]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use xalloc stuff
authorKarel Zak <kzak@redhat.com>
Thu, 26 Sep 2013 08:58:03 +0000 (10:58 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Sep 2013 08:58:03 +0000 (10:58 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c

index 61a522c3645d34def966af1c28d4080f6d9ddc1c..f8216bba9ace8b6f586fca36fd8f6080c5e04af7 100644 (file)
@@ -45,8 +45,6 @@
 # include <linux/blkpg.h>
 #endif
 
-#include "fdisk.h"
-
 static void __attribute__ ((__noreturn__)) usage(FILE *out)
 {
        fputs(USAGE_HEADER, out);
@@ -273,20 +271,20 @@ static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
 static void dump_blkdev(struct fdisk_context *cxt, const char *name,
                        off_t offset, size_t size, int all)
 {
-       unsigned char *buf = NULL;
-
        fdisk_colon(cxt, _("\n%s: offset = %ju, size = %zu bytes."),
                        name, offset, size);
 
        if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1)
                fdisk_warn(cxt, _("cannot seek"));
-       else if (!(buf = malloc(size)))
-               fdisk_warn(cxt, _("cannot allocate"));
-       else if (read_all(cxt->dev_fd, (char *) buf, size) != (ssize_t) size)
-               fdisk_warn(cxt, _("cannot read"));
-       else
-               dump_buffer(offset, buf, size, all);
-       free(buf);
+       else {
+               unsigned char *buf = xmalloc(size);
+
+               if (read_all(cxt->dev_fd, (char *) buf, size) != (ssize_t) size)
+                       fdisk_warn(cxt, _("cannot read"));
+               else
+                       dump_buffer(offset, buf, size, all);
+               free(buf);
+       }
 }
 
 void dump_firstsector(struct fdisk_context *cxt)