summaryrefslogtreecommitdiff
path: root/lib/modechange.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-09-24 07:00:59 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-09-24 07:00:59 +0000
commitd7caebfe16375066910e6eb9818dd62a9ee169d5 (patch)
treece15f91c1b5aef9b260ad822ea5b3b6b7d5b5737 /lib/modechange.c
parented37158ead918ea006d88f92856e8bc858014d46 (diff)
downloadcoreutils-d7caebfe16375066910e6eb9818dd62a9ee169d5.tar.xz
(mode_compile): Don't decrement a pointer that
points to the start of a string, as the C Standard says the resulting behavior is undefined.
Diffstat (limited to 'lib/modechange.c')
-rw-r--r--lib/modechange.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/modechange.c b/lib/modechange.c
index b4df3388c..991235b09 100644
--- a/lib/modechange.c
+++ b/lib/modechange.c
@@ -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: