`top -b -- 3 foo bar' works but should not.

OK?


Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.101
diff -u -p -r1.101 top.c
--- top.c       8 Oct 2019 20:51:03 -0000       1.101
+++ top.c       12 Oct 2019 10:43:58 -0000
@@ -304,6 +304,13 @@ parseargs(int ac, char **av)
                        exit(1);
                }
        }
+       ac -= optind;
+       av += optind;
+
+       if (ac > 1) {
+               usage();
+               exit(1);
+       }
 
        i = getncpuonline();
        if (i == -1)
@@ -313,8 +320,8 @@ parseargs(int ac, char **av)
                combine_cpus = 1;
 
        /* get count of top processes to display (if any) */
-       if (optind < ac) {
-               if ((topn = atoiwi(av[optind])) == Invalid) {
+       if (ac) {
+               if ((topn = atoiwi(av[ac - 1])) == Invalid) {
                        new_message(MT_delayed,
                            "warning: process count should "
                            "be a non-negative number -- using default");

Reply via email to