Avoid side effects in putc(), which may be implemented as a macro
authorDan Fandrich <dan@coneharvesters.com>
Wed, 8 Sep 2010 06:38:28 +0000 (23:38 -0700)
committerDenys Vlasenko <dvlasenk@redhat.com>
Thu, 9 Sep 2010 09:48:02 +0000 (11:48 +0200)
Signed-off-by: Dan Fandrich <dan@coneharvesters.com>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
coreutils/ls.c
coreutils/tee.c
shell/ash.c

index cbfcfc7a1d4cc77754bf8ca19c693d61f3298395..e69f1afd962652c0705042a85564b71814560197 100644 (file)
@@ -573,7 +573,8 @@ static unsigned print_name(const char *name)
                        putchar('\\');
                        len++;
                }
-               putchar(*name++);
+               putchar(*name);
+               name++;
        }
        putchar('"');
        return len;
index 8db9042aadbe8f67366da9ead185a282260b69e3..2e1e367f2ac1045aad025831b4e4dc31105d2710 100644 (file)
@@ -70,8 +70,8 @@ int tee_main(int argc, char **argv)
        while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
                fp = files;
                do
-                       fwrite(buf, 1, c, *fp++);
-               while (*fp);
+                       fwrite(buf, 1, c, *fp);
+               while (*++fp);
        }
        if (c < 0) {            /* Make sure read errors are signaled. */
                retval = EXIT_FAILURE;
@@ -81,8 +81,8 @@ int tee_main(int argc, char **argv)
        while ((c = getchar()) != EOF) {
                fp = files;
                do
-                       putc(c, *fp++);
-               while (*fp);
+                       putc(c, *fp);
+               while (*++fp);
        }
 #endif
 
index 70425b324f1747937d4b4185558ad05361082c3f..f262872ea455f49e737825f171d6932f63c1d771 100644 (file)
@@ -953,7 +953,8 @@ sharg(union node *arg, FILE *fp)
        for (p = arg->narg.text; *p; p++) {
                switch ((unsigned char)*p) {
                case CTLESC:
-                       putc(*++p, fp);
+                       p++;
+                       putc(*p, fp);
                        break;
                case CTLVAR:
                        putc('$', fp);
@@ -962,8 +963,10 @@ sharg(union node *arg, FILE *fp)
                        if (subtype == VSLENGTH)
                                putc('#', fp);
 
-                       while (*p != '=')
-                               putc(*p++, fp);
+                       while (*p != '=') {
+                               putc(*p, fp);
+                               p++;
+                       }
 
                        if (subtype & VSNUL)
                                putc(':', fp);