NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/45842: Incorrect comparison fgets.



>Number:         45842
>Category:       bin
>Synopsis:       Incorrect comparison fgets.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 16 08:35:00 +0000 2012
>Originator:     Henning Petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Incorrect comparison fgets with integer 0, should be NULL.
>How-To-Repeat:

>Fix:
diff -u -p -r1.13 getcom.c
--- games/battlestar/getcom.c   1 Jul 2005 06:04:54 -0000       1.13
+++ games/battlestar/getcom.c   13 Jan 2012 11:00:30 -0000
@@ -45,7 +45,7 @@ getcom(char *buf, int size, const char *
 {
        for (;;) {
                fputs(prompt, stdout);
-               if (fgets(buf, size, stdin) == 0) {
+               if (fgets(buf, size, stdin) == NULL) {
                        if (feof(stdin))
                                die();
                        clearerr(stdin);
 
===================================================================
RCS file: /cvsroot/src/sbin/routed/parms.c,v
retrieving revision 1.25
diff -u -p -r1.25 parms.c
--- sbin/routed/parms.c 24 May 2011 12:03:04 -0000      1.25
+++ sbin/routed/parms.c 13 Jan 2012 11:00:37 -0000
@@ -192,7 +192,7 @@ gwkludge(void)
        }
 
        for (lnum = 1; ; lnum++) {
-               if (0 == fgets(lbuf, sizeof(lbuf), fp))
+               if (fgets(lbuf, sizeof(lbuf), fp) == NULL)
                        break;
                lptr = lbuf;
                while (*lptr == ' ')
===================================================================
diff -u -p -r1.25 edit.c
--- usr.bin/mail/edit.c 10 Apr 2009 13:08:24 -0000      1.25
+++ usr.bin/mail/edit.c 13 Jan 2012 11:00:39 -0000
@@ -172,7 +172,7 @@ edit1(int *msgvec, int editortype)
                        char *p;
 
                        (void)printf("Edit message %d [ynq]? ", msgvec[i]);
-                       if (fgets(buf, (int)sizeof(buf), stdin) == 0)
+                       if (fgets(buf, (int)sizeof(buf), stdin) == NULL)
                                break;
                        p = skip_WSP(buf);
                        if (*p == 'q')
===================================================================
diff -u -p -r1.29 main.c
--- usr.bin/tftp/main.c 17 Sep 2011 15:15:46 -0000      1.29
+++ usr.bin/tftp/main.c 13 Jan 2012 11:00:44 -0000
@@ -662,7 +662,7 @@ command(void)
 
        for (;;) {
                (void)printf("%s> ", prompt);
-               if (fgets(line, LBUFLEN, stdin) == 0) {
+               if (fgets(line, LBUFLEN, stdin) == NULL) {
                        if (feof(stdin)) {
                                exit(0);
                        } else {
===================================================================
diff -u -p -r1.21 timedc.c
--- usr.sbin/timed/timedc/timedc.c      21 Jul 2008 13:37:00 -0000      1.21
+++ usr.sbin/timed/timedc/timedc.c      13 Jan 2012 11:00:52 -0000
@@ -105,7 +105,7 @@ main(int argc, char *argv[])
                        printf("timedc> ");
                        (void) fflush(stdout);
                }
-               if (fgets(cmdline, sizeof(cmdline), stdin) == 0)
+               if (fgets(cmdline, sizeof(cmdline), stdin) == NULL)
                        quit(0, NULL);




Home | Main Index | Thread Index | Old Index