truncate buffer before reading empty files

If readfile() reads an empty file, fgets() won't truncate the buffer
and it'll still contain the contents of the previously read file.

[lh: fixed similar issue in ui-repolist.c]

Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
This commit is contained in:
Simon Arlott 2009-03-07 00:06:24 +00:00 committed by Lars Hjemli
parent 6421dc38db
commit 011f2e9bdd
2 changed files with 2 additions and 0 deletions

View File

@ -42,6 +42,7 @@ char *readfile(const char *path)
if (!(f = fopen(path, "r"))) if (!(f = fopen(path, "r")))
return NULL; return NULL;
buf[0] = 0;
fgets(buf, MAX_PATH, f); fgets(buf, MAX_PATH, f);
fclose(f); fclose(f);
return buf; return buf;

View File

@ -23,6 +23,7 @@ time_t read_agefile(char *path)
if (!(f = fopen(path, "r"))) if (!(f = fopen(path, "r")))
return -1; return -1;
buf[0] = 0;
if (fgets(buf, sizeof(buf), f) == NULL) if (fgets(buf, sizeof(buf), f) == NULL)
return -1; return -1;
fclose(f); fclose(f);