svn commit: trunk/busybox: archival coreutils e2fsprogs/ext2fs proc etc...

vda at busybox.net vda at busybox.net
Sat Sep 9 12:24:20 UTC 2006


Author: vda
Date: 2006-09-09 05:24:19 -0700 (Sat, 09 Sep 2006)
New Revision: 16081

Log:
using [xa]sprintf for string concatenation is neat and saves
~100 bytes according to bloatcheck. Also this fixes bug in rpm



Modified:
   trunk/busybox/archival/gzip.c
   trunk/busybox/archival/rpm.c
   trunk/busybox/coreutils/tr.c
   trunk/busybox/e2fsprogs/ext2fs/mkjournal.c
   trunk/busybox/procps/sysctl.c
   trunk/busybox/sysklogd/logger.c


Changeset:
Modified: trunk/busybox/archival/gzip.c
===================================================================
--- trunk/busybox/archival/gzip.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/archival/gzip.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -1212,9 +1212,7 @@
 				time_stamp = statBuf.st_ctime;
 
 				if (!tostdout) {
-					path = xmalloc(strlen(argv[i]) + 4);
-					strcpy(path, argv[i]);
-					strcat(path, ".gz");
+					path = xasprintf("%s.gz", argv[i]);
 
 					/* Open output file */
 #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) && defined O_NOFOLLOW

Modified: trunk/busybox/archival/rpm.c
===================================================================
--- trunk/busybox/archival/rpm.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/archival/rpm.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -290,8 +290,7 @@
 	if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
 		stat_res = lstat (filename, &oldfile);
 		if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists  - really should check MD5's etc to see if different */
-			newname = xstrdup(filename);
-			newname = strcat(newname, ".rpmorig");
+			newname = xasprintf("%s.rpmorig", filename);
 			copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
 			remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
 			free(newname);

Modified: trunk/busybox/coreutils/tr.c
===================================================================
--- trunk/busybox/coreutils/tr.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/coreutils/tr.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -128,7 +128,7 @@
 					for (i = 'A'; i <= 'Z'; i++)
 						*buffer++ = i;
 				else if (strncmp(arg, "space", 5) == 0) {
-				    const char s[] = "\t\n\v\f\r ";
+					const char s[] = "\t\n\v\f\r ";
 					strcat((char*)buffer, s);
 					buffer += sizeof(s) - 1;
 				}

Modified: trunk/busybox/e2fsprogs/ext2fs/mkjournal.c
===================================================================
--- trunk/busybox/e2fsprogs/ext2fs/mkjournal.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/e2fsprogs/ext2fs/mkjournal.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -322,8 +322,9 @@
 	char			jfile[1024];
 	int			fd, mount_flags, f;
 
-	if ((retval = ext2fs_check_mount_point(fs->device_name, &mount_flags,
-					       jfile, sizeof(jfile)-10)))
+	retval = ext2fs_check_mount_point(fs->device_name, &mount_flags,
+					       jfile, sizeof(jfile)-10);
+	if (retval)
 		return retval;
 
 	if (mount_flags & EXT2_MF_MOUNTED) {

Modified: trunk/busybox/procps/sysctl.c
===================================================================
--- trunk/busybox/procps/sysctl.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/procps/sysctl.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -129,7 +129,7 @@
 	}
 
 	while (fgets(oneline, sizeof(oneline) - 1, fp)) {
-		oneline[sizeof(oneline) - 1] = 0;
+		oneline[sizeof(oneline) - 1] = '\0';
 		lineno++;
 		trim(oneline);
 		ptr = (char *) oneline;
@@ -156,9 +156,8 @@
 
 		while ((*value == ' ' || *value == '\t') && *value != 0)
 			value++;
-		strcpy(buffer, name);
-		strcat(buffer, "=");
-		strcat(buffer, value);
+		/* safe because sizeof(oneline) == sizeof(buffer) */
+		sprintf(buffer, "%s=%s", name, value);
 		sysctl_write_setting(buffer, output);
 	}
 	fclose(fp);

Modified: trunk/busybox/sysklogd/logger.c
===================================================================
--- trunk/busybox/sysklogd/logger.c	2006-09-09 12:20:57 UTC (rev 16080)
+++ trunk/busybox/sysklogd/logger.c	2006-09-09 12:24:19 UTC (rev 16081)
@@ -138,7 +138,7 @@
 			len += strlen(*argv);
 			message = xrealloc(message, len);
 			if(!i)
-				message[0] = 0;
+				message[0] = '\0';
 			else
 				strcat(message, " ");
 			strcat(message, *argv);




More information about the busybox-cvs mailing list