summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2013-04-10 17:30:34 +0200
committerKarel Zak2013-04-10 17:30:34 +0200
commit5d00280cdb5fae3ac54f1f1f8c7b7dd94749c1af (patch)
tree0c33fc0c6bdc8171739f5a53af641cccd21c75bb /misc-utils
parenttests: make line(1) optional (diff)
downloadkernel-qcow2-util-linux-5d00280cdb5fae3ac54f1f1f8c7b7dd94749c1af.tar.gz
kernel-qcow2-util-linux-5d00280cdb5fae3ac54f1f1f8c7b7dd94749c1af.tar.xz
kernel-qcow2-util-linux-5d00280cdb5fae3ac54f1f1f8c7b7dd94749c1af.zip
blkid: use xalloc everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/blkid.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index f67ee4490..ce712ac53 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -369,14 +369,7 @@ static int append_str(char **res, size_t *sz, const char *a, const char *b)
if (!len)
return -1;
- str = realloc(str, len + 1);
- if (!str) {
- free(*res);
- *res = NULL;
- return -1;
- }
-
- *res = str;
+ *res = str = xrealloc(str, len + 1);
str += *sz;
if (a) {
@@ -623,25 +616,19 @@ static char **list_to_types(const char *list, int *flag)
}
for (i = 1; p && (p = strchr(p, ',')); i++, p++);
- res = calloc(i + 1, sizeof(char *));
- if (!res)
- goto err_mem;
+ res = xcalloc(i + 1, sizeof(char *));
p = *flag & BLKID_FLTR_NOTIN ? list + 2 : list;
i = 0;
while(p) {
const char *word = p;
p = strchr(p, ',');
- res[i] = p ? strndup(word, p - word) : strdup(word);
- if (!res[i++])
- goto err_mem;
+ res[i++] = p ? xstrndup(word, p - word) : xstrdup(word);
if (p)
p++;
}
res[i] = NULL;
return res;
-err_mem:
- fprintf(stderr, "out of memory\n");
err:
*flag = 0;
free(res);
@@ -804,12 +791,7 @@ int main(int argc, char **argv)
/* The rest of the args are device names */
if (optind < argc) {
- devices = calloc(argc - optind, sizeof(char *));
- if (!devices) {
- fprintf(stderr, "Failed to allocate device name array\n");
- goto exit;
- }
-
+ devices = xcalloc(argc - optind, sizeof(char *));
while (optind < argc)
devices[numdev++] = argv[optind++];
}