mountd: Fix fgets check.
authorRosen Penev <rosenp@gmail.com>
Sun, 18 Dec 2016 00:09:24 +0000 (16:09 -0800)
committerJohn Crispin <john@phrozen.org>
Mon, 19 Dec 2016 07:31:49 +0000 (08:31 +0100)
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@gmail.com>

mount.c

diff --git a/mount.c b/mount.c
index 8330abe..9a291d7 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -177,7 +177,7 @@ static int mount_check_disc(char *disc)
                fclose(fp);
                return avail;
        }
                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];
        {
                char *t;
                char tmp2[32];
@@ -389,7 +389,7 @@ static char* mount_get_serial(char *dev)
                                                fp = fopen(tmp2, "r");
                                                if(fp)
                                                {
                                                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)
                                                        {
                                                                serial = strstr(tmp2, "Serial Number:");
                                                                if(serial)
@@ -619,7 +619,7 @@ static void mount_check_mount_list(void)
                return;
        }
        mounted_count = 0;
                return;
        }
        mounted_count = 0;
-       while(fgets(tmp, 256, fp) > 0)
+       while(fgets(tmp, 256, fp) != NULL)
        {
                char *t, *t2;
                t = strstr(tmp, " ");
        {
                char *t, *t2;
                t = strstr(tmp, " ");