[PATCH] Avoid side effects in putc(), which may be implemented as a macro

Dan Fandrich dan at coneharvesters.com
Wed Sep 8 06:40:00 UTC 2010


Signed-off-by: Dan Fandrich <dan at coneharvesters.com>
---
 coreutils/ls.c  |    4 ++--
 coreutils/tee.c |    8 ++++----
 shell/ash.c     |    6 ++++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/coreutils/ls.c b/coreutils/ls.c
index cbfcfc7..db84e9d 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -568,12 +568,12 @@ static unsigned print_name(const char *name)
 
 	len = 2 + uni_stat.unicode_width;
 	putchar('"');
-	while (*name) {
+	for (; *name; ++name) {
 		if (*name == '"' || *name == '\\') {
 			putchar('\\');
 			len++;
 		}
-		putchar(*name++);
+		putchar(*name);
 	}
 	putchar('"');
 	return len;
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 8db9042..2e1e367 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -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
 
diff --git a/shell/ash.c b/shell/ash.c
index 70425b3..6084c3a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -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);
@@ -963,7 +964,8 @@ sharg(union node *arg, FILE *fp)
 				putc('#', fp);
 
 			while (*p != '=')
-				putc(*p++, fp);
+				putc(*p, fp);
+				++p;
 
 			if (subtype & VSNUL)
 				putc(':', fp);
-- 
1.5.3.2



More information about the busybox mailing list