Be careful to not look at **argv unless there are more arguments.
authorCraig Leres <leres@ucbvax.Berkeley.EDU>
Fri, 13 Sep 1991 10:57:00 +0000 (02:57 -0800)
committerCraig Leres <leres@ucbvax.Berkeley.EDU>
Fri, 13 Sep 1991 10:57:00 +0000 (02:57 -0800)
SCCS-vsn: usr.bin/uniq/uniq.c 5.3

usr/src/usr.bin/uniq/uniq.c

index b354c99..4bdd131 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)uniq.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)uniq.c     5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <stdio.h>
 #endif /* not lint */
 
 #include <stdio.h>
@@ -75,7 +75,7 @@ done: argc -= optind;
                dflag = uflag = 1;
 
        /* because of the +, getopt is messed up */
                dflag = uflag = 1;
 
        /* because of the +, getopt is messed up */
-       for (; **argv == '+' || **argv == '-'; ++argv, --argc)
+       for (; argc > 0 && (**argv == '+' || **argv == '-'); ++argv, --argc)
                switch (**argv) {
                case '+':
                        if ((numchars = atoi(*argv + 1)) < 0)
                switch (**argv) {
                case '+':
                        if ((numchars = atoi(*argv + 1)) < 0)