[git commit] dd: do not reuse local variables for unrelated values.

Denys Vlasenko vda.linux at googlemail.com
Mon Aug 19 07:00:08 UTC 2013


commit: http://git.busybox.net/busybox/commit/?id=4b1896cd2ccdb3e09070035f86a48d42b678d8ff
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/dd.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/coreutils/dd.c b/coreutils/dd.c
index 96602eb..9cb96bb 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -201,7 +201,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 	};
 	int exitcode = EXIT_FAILURE;
 	size_t ibs = 512, obs = 512;
-	ssize_t n, w;
+	int i;
 	char *ibuf, *obuf;
 	/* And these are all zeroed at once! */
 	struct {
@@ -223,10 +223,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 	INIT_G();
 	//fflush_all(); - is this needed because of NOEXEC?
 
-	for (n = 1; argv[n]; n++) {
+	for (i = 1; argv[i]; i++) {
 		int what;
 		char *val;
-		char *arg = argv[n];
+		char *arg = argv[i];
 
 #if ENABLE_DESKTOP
 		/* "dd --". NB: coreutils 6.9 will complain if they see
@@ -300,7 +300,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 			outfile = val;
 			/*continue;*/
 		}
-	} /* end of "for (argv[n])" */
+	} /* end of "for (argv[i])" */
 
 //XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
 	ibuf = obuf = xmalloc(ibs);
@@ -347,7 +347,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 	if (skip) {
 		if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
 			while (skip-- > 0) {
-				n = safe_read(ifd, ibuf, ibs);
+				ssize_t n = safe_read(ifd, ibuf, ibs);
 				if (n < 0)
 					goto die_infile;
 				if (n == 0)
@@ -361,6 +361,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 	}
 
 	while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
+		ssize_t n;
+
 		n = safe_read(ifd, ibuf, ibs);
 		if (n == 0)
 			break;
@@ -411,7 +413,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 	}
 
 	if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
-		w = full_write_or_warn(obuf, oc, outfile);
+		ssize_t w = full_write_or_warn(obuf, oc, outfile);
 		if (w < 0) goto out_status;
 		if (w > 0) G.out_part++;
 	}


More information about the busybox-cvs mailing list