(mode_compile): Don't decrement a pointer that
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Oct 2004 04:24:47 +0000 (04:24 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Oct 2004 04:24:47 +0000 (04:24 +0000)
points to the start of a string, as the C Standard says the
resulting behavior is undefined.

lib/modechange.c

index b4df3388ceba2b38eec2fdf8b4ed5eb2b8000609..991235b09cc1809cf15cea779d86e001cd3fb047 100644 (file)
@@ -211,10 +211,9 @@ mode_compile (const char *mode_string, unsigned int masked_ops)
 
   umask_value = umask (0);
   umask (umask_value);         /* Restore the old value. */
-  --mode_string;
 
   /* One loop iteration for each "ugoa...=+-rwxXstugo...[=+-rwxXstugo...]". */
-  do
+  for (;; mode_string++)
     {
       /* Which bits in the mode are operated on. */
       mode_t affected_bits = 0;
@@ -226,7 +225,7 @@ mode_compile (const char *mode_string, unsigned int masked_ops)
       bool who_specified_p;
 
       /* Turn on all the bits in `affected_bits' for each group given. */
-      for (++mode_string;; ++mode_string)
+      for (;; mode_string++)
        switch (*mode_string)
          {
          case 'u':
@@ -349,7 +348,11 @@ mode_compile (const char *mode_string, unsigned int masked_ops)
              }
        no_more_values:;
        }
-  } while (*mode_string == ',');
+
+      if (*mode_string != ',')
+       break;
+    }
+
   if (*mode_string == 0)
     return head;
 invalid: