From: Dave Reisner Date: Tue, 20 Mar 2012 08:44:40 +0000 (+0100) Subject: checkxalloc: nudge regex, fix newfound instances X-Git-Tag: v2.22-rc1~646 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99d618c0eb5fc7dc0d4bb39df3ce5d680ab5b8e2;p=thirdparty%2Futil-linux.git checkxalloc: nudge regex, fix newfound instances 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 Signed-off-by: Karel Zak --- diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index f549c64134..a090772a86 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -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); diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 2df79a4cbb..f800381441 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -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; } diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index f17fad65b5..02e4a26d12 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -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, ",")) { diff --git a/tools/checkxalloc.sh b/tools/checkxalloc.sh index c507777dbc..3c342545f7 100755 --- a/tools/checkxalloc.sh +++ b/tools/checkxalloc.sh @@ -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=$?