cgit

commit 011f2e9bdddcbfe65da397629bca87d167313a28

Author: Simon Arlott <simon@fire.lp0.eu>

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>

 scan-tree.c | 1 +
 ui-repolist.c | 1 +


diff --git a/scan-tree.c b/scan-tree.c
index cdafb02df6b51a9ea7bc82a94a59d18cf4389054..47f3988b3723673b0ed06b104f41822711db46cf 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -42,6 +42,7 @@ 	static char buf[MAX_PATH];
 
 	if (!(f = fopen(path, "r")))
 		return NULL;
+	buf[0] = 0;
 	fgets(buf, MAX_PATH, f);
 	fclose(f);
 	return buf;




diff --git a/ui-repolist.c b/ui-repolist.c
index 2c13d5041b2a4931358b241b6316db3d96a9a6b5..3aedde5456f761fe58926bfef7e28f389975aa41 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -23,6 +23,7 @@ 	static char buf[64], buf2[64];
 
 	if (!(f = fopen(path, "r")))
 		return -1;
+	buf[0] = 0;
 	if (fgets(buf, sizeof(buf), f) == NULL)
 		return -1;
 	fclose(f);