]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
checkxalloc: nudge regex, fix newfound instances
authorDave Reisner <dreisner@archlinux.org>
Tue, 20 Mar 2012 08:44:40 +0000 (09:44 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2012 08:44:40 +0000 (09:44 +0100)
Using the -w flag with grep actually fought against us here, and hid
some instances where xalloc functions weren't used. Discard it in
favor of an explicit word boundary as a prefix to the function name,
and extend our requirements on the trailing side of the pattern.

This also fixes the few new instances that were overlooked because of
the regex's deficiency.

[kzak@redhat.com: - fix also newfound in findmnt
                  - remove unnecessary checks after xallocs]

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisk/sfdisk.c
misc-utils/findmnt.c
sys-utils/swapon.c
tools/checkxalloc.sh

index f549c64134a2a67d898427e5fefa575acb373f20..a090772a86614c5b1ec7133aab99f97301489bde 100644 (file)
@@ -305,10 +305,8 @@ restore_sectors(char *dev) {
        error(_("partition restore file has wrong size - not restoring\n"));
        goto err;
     }
-    if (!(ss0 = (char *)malloc(statbuf.st_size))) {
-       error(_("out of memory?\n"));
-       goto err;
-    }
+
+    ss0 = xmalloc(statbuf.st_size);
     ss = ss0;
 
     fdin = open(restore_sector_file, O_RDONLY);
index 2df79a4cbbf91c2764b49f81a2bf873b5ff752a1..f800381441f00faae0c789c9b008c8a5d3cf4a15 100644 (file)
@@ -497,13 +497,7 @@ static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
 
 static char **append_tabfile(char **files, int *nfiles, char *filename)
 {
-       void *tmp = realloc(files, sizeof(char *) * (*nfiles + 1));
-
-       if (!tmp) {
-               free(files);
-               return NULL;
-       }
-       files = tmp;
+       files = xrealloc(files, sizeof(char *) * (*nfiles + 1));
        files[(*nfiles)++] = filename;
        return files;
 }
index f17fad65b5e15f41674d54ee57103960460049c1..02e4a26d12622e0bca1ebcb30f7b5af230d137ad 100644 (file)
@@ -197,9 +197,7 @@ read_proc_swaps(void) {
                               *p = '\0';
                }
 
-               q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
-               if (q == NULL)
-                       break;
+               q = xrealloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
                swapFiles = q;
 
                if ((p = unmangle(line, NULL)) == NULL)
@@ -640,7 +638,7 @@ swapon_all(void) {
                if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
                        continue;
 
-               opts = strdup(fstab->mnt_opts);
+               opts = xstrdup(fstab->mnt_opts);
 
                for (opt = strtok(opts, ","); opt != NULL;
                     opt = strtok(NULL, ",")) {
index c507777dbc8dc215cb1455b69d9078b0cfb3f07c..3c342545f715e1636cc2dfe19a1ad3d77efdd89e 100755 (executable)
@@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)" || {
 }
 
 git grep -zl '#include "xalloc.h"' |
-  xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup|asprintf)\('
+  xargs -0 grep -nE '\b(([cm]|re)alloc|strdup|asprintf)[[:space:]]*\([^)]'
 
 result=$?