using [xa]sprintf for string concatenation is neat and saves
authorDenis Vlasenko <vda.linux@googlemail.com>
Sat, 9 Sep 2006 12:24:19 +0000 (12:24 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sat, 9 Sep 2006 12:24:19 +0000 (12:24 -0000)
~100 bytes according to bloatcheck. Also this fixes bug in rpm

archival/gzip.c
archival/rpm.c
coreutils/tr.c
e2fsprogs/ext2fs/mkjournal.c
procps/sysctl.c
sysklogd/logger.c

index 37fefbf6a3ddf50dc22ecd7cb80ae8009300c9cc..ad2c24df1eab2e09bb99ee41afae534846ac8ef2 100644 (file)
@@ -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
index d399e0ea2da8ac85b800b4da04e8b29365ae9afb..a459839d91e1cb7fa348669462e5e229965e7dba 100644 (file)
@@ -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);
index 6eb86750d0417afb091d0fd89f96b20595908b9d..f2c9065d1ea0caa922836421935f43264354df89 100644 (file)
@@ -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;
                                }
index c23ed90218f9df73d1b3a2429ab97361fa3118f2..5bdd346820c0faef5da4baabd3106de48f67c409 100644 (file)
@@ -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) {
index 03a03889e142f961f9b494f1528d24311b1cd34a..297a12a851d8196897c172349b1a545e070a3dc7 100644 (file)
@@ -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);
index ea093ed5204994aae1de692b11256d07de0d0da6..762e70ff7370c345799e08be6e1a31b7a23d89b2 100644 (file)
@@ -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);