[LEDE-DEV] [PATCH] mountd: Fix fgets check.

Rosen Penev rosenp at gmail.com
Sat Dec 17 16:09:24 PST 2016


fgets returns NULL on failure and a pointer otherwise. While comparing
it normally does not cause problems, comparing a pointer like this
is still undefined behavior.

Signed-off by: Rosen Penev <rosenp at gmail.com>
---
 mount.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mount.c b/mount.c
index da62ae9..a7f1862 100644
--- a/mount.c
+++ b/mount.c
@@ -177,7 +177,7 @@ static int mount_check_disc(char *disc)
 		fclose(fp);
 		return avail;
 	}
-	while((fgets(tmp, 256, fp) > 0) && (avail == -1))
+	while((fgets(tmp, 256, fp) != NULL) && (avail == -1))
 	{
 		char *t;
 		char tmp2[32];
@@ -389,7 +389,7 @@ static char* mount_get_serial(char *dev)
 						fp = fopen(tmp2, "r");
 						if(fp)
 						{
-							while(fgets(tmp2, 64, fp) > 0)
+							while(fgets(tmp2, 64, fp) != NULL)
 							{
 								serial = strstr(tmp2, "Serial Number:");
 								if(serial)
@@ -619,7 +619,7 @@ static void mount_check_mount_list(void)
 		return;
 	}
 	mounted_count = 0;
-	while(fgets(tmp, 256, fp) > 0)
+	while(fgets(tmp, 256, fp) != NULL)
 	{
 		char *t, *t2;
 		t = strstr(tmp, " ");
-- 
2.9.3




More information about the Lede-dev mailing list