summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner2012-03-20 09:44:40 +0100
committerKarel Zak2012-03-20 09:44:40 +0100
commit99d618c0eb5fc7dc0d4bb39df3ce5d680ab5b8e2 (patch)
tree3b0303acde572267b7ef28eddf8d0357de007585
parentfindmnt: add -P, --pairs to the man page (diff)
downloadkernel-qcow2-util-linux-99d618c0eb5fc7dc0d4bb39df3ce5d680ab5b8e2.tar.gz
kernel-qcow2-util-linux-99d618c0eb5fc7dc0d4bb39df3ce5d680ab5b8e2.tar.xz
kernel-qcow2-util-linux-99d618c0eb5fc7dc0d4bb39df3ce5d680ab5b8e2.zip
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 <dreisner@archlinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--fdisk/sfdisk.c6
-rw-r--r--misc-utils/findmnt.c8
-rw-r--r--sys-utils/swapon.c6
-rwxr-xr-xtools/checkxalloc.sh2
4 files changed, 6 insertions, 16 deletions
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index f549c6413..a090772a8 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 2df79a4cb..f80038144 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 f17fad65b..02e4a26d1 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 c507777db..3c342545f 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=$?