diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-09 12:24:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-09 12:24:19 +0000 |
commit | 9cac521f07550764e94c469d70b22ad5c194855a (patch) | |
tree | 98f3e605a5b17bffc9e1f087907bf15049d6e717 | |
parent | 3526a1320a7e70be0def06a31b65ffff3430510b (diff) | |
download | busybox-9cac521f07550764e94c469d70b22ad5c194855a.tar.gz |
using [xa]sprintf for string concatenation is neat and saves
~100 bytes according to bloatcheck. Also this fixes bug in rpm
-rw-r--r-- | archival/gzip.c | 4 | ||||
-rw-r--r-- | archival/rpm.c | 3 | ||||
-rw-r--r-- | coreutils/tr.c | 2 | ||||
-rw-r--r-- | e2fsprogs/ext2fs/mkjournal.c | 5 | ||||
-rw-r--r-- | procps/sysctl.c | 7 | ||||
-rw-r--r-- | sysklogd/logger.c | 2 |
6 files changed, 10 insertions, 13 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 37fefbf6a..ad2c24df1 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -1212,9 +1212,7 @@ int gzip_main(int argc, char **argv) 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 diff --git a/archival/rpm.c b/archival/rpm.c index d399e0ea2..a459839d9 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -290,8 +290,7 @@ static void fileaction_dobackup(char *filename, int fileref) 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); diff --git a/coreutils/tr.c b/coreutils/tr.c index 6eb86750d..f2c9065d1 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -128,7 +128,7 @@ static unsigned int expand(const char *arg, char *buffer) 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; } diff --git a/e2fsprogs/ext2fs/mkjournal.c b/e2fsprogs/ext2fs/mkjournal.c index c23ed9021..5bdd34682 100644 --- a/e2fsprogs/ext2fs/mkjournal.c +++ b/e2fsprogs/ext2fs/mkjournal.c @@ -322,8 +322,9 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) 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) { diff --git a/procps/sysctl.c b/procps/sysctl.c index 03a03889e..297a12a85 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c @@ -129,7 +129,7 @@ int sysctl_preload_file(const char *filename, int output) } 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 @@ int sysctl_preload_file(const char *filename, int output) 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); diff --git a/sysklogd/logger.c b/sysklogd/logger.c index ea093ed52..762e70ff7 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -138,7 +138,7 @@ int logger_main(int argc, char **argv) len += strlen(*argv); message = xrealloc(message, len); if(!i) - message[0] = 0; + message[0] = '\0'; else strcat(message, " "); strcat(message, *argv); |