From bc4a6dda94adf7c2a8f4274dd5b38a13e5c2c18b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 17 Dec 2016 16:09:24 -0800 Subject: [PATCH] mountd: Fix fgets check. 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 --- mount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mount.c b/mount.c index 8330abe..9a291d7 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.25.1