]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setarch: do not use -1 as array index [cppcheck]
authorSami Kerola <kerolasa@iki.fi>
Sat, 9 Jun 2012 20:45:27 +0000 (22:45 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 9 Jun 2012 20:51:10 +0000 (22:51 +0200)
Negative array index does technically work, but looks awkward and
can confuse static analyser such as cppcheck.

[sys-utils/setarch.c:267]: (error) Array index -1 is out of bounds

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/setarch.c

index 97269f45aef7c0bfb81f4793578c17ba2f3731ca..a0c6ea81fbb1f7d72d5fe8357ab3dd56f2415fdb 100644 (file)
@@ -259,12 +259,12 @@ int main(int argc, char *argv[])
 
   p = program_invocation_short_name;
   if (!strcmp(p, "setarch")) {
-    argv++;
     argc--;
     if (argc < 1)
       show_usage(_("Not enough arguments"));
-    p = argv[0];
-    argv[0] = argv[-1];      /* for getopt_long() to get the program name */
+    p = argv[1];
+    argv[1] = argv[0];         /* for getopt_long() to get the program name */
+    argv++;
     if (!strcmp(p, "-h") || !strcmp(p, "--help"))
       show_help();
     else if (!strcmp(p, "-V") || !strcmp(p, "--version"))