Fix Coverity warning for unchecked return value from dirname()

- Check return value from dirname()
- Remove static from local compose buffer

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-02-05 22:50:08 +01:00
1 parent d58c58d972
commit caff08f58d
1 file changed
+10 -4
+10 -4
View File
@@ -9,22 +9,28 @@
int cond_set_path(const char *path, enum cond_state new) int cond_set_path(const char *path, enum cond_state new)
{ {
static char dir[MAX_ARG_LEN]; char buf[MAX_ARG_LEN], *dir;
enum cond_state old; enum cond_state old;
old = cond_get_path(path); old = cond_get_path(path);
switch (new) { switch (new) {
case COND_ON: case COND_ON:
strlcpy(dir, path, sizeof(dir)); strlcpy(buf, path, sizeof(buf));
makepath(dirname(dir)); dir = dirname(buf);
if (!dir) {
_e("Invalid path '%s' for condition", path);
return 0;
}
makepath(dir);
touch(path); touch(path);
utime(path, NULL); utime(path, NULL);
break; break;
case COND_OFF: case COND_OFF:
unlink(path); unlink(path);
break; break;
default: default:
_e("Invalid condition state"); _e("Invalid condition state");
return 0; return 0;