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
2016-02-05 22:50:08 +01:00
parent d58c58d972
commit caff08f58d
+10 -4
View File
@@ -9,22 +9,28 @@
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;
old = cond_get_path(path);
switch (new) {
case COND_ON:
strlcpy(dir, path, sizeof(dir));
makepath(dirname(dir));
strlcpy(buf, path, sizeof(buf));
dir = dirname(buf);
if (!dir) {
_e("Invalid path '%s' for condition", path);
return 0;
}
makepath(dir);
touch(path);
utime(path, NULL);
break;
case COND_OFF:
unlink(path);
break;
default:
_e("Invalid condition state");
return 0;