From: Karel Zak Date: Thu, 26 Sep 2013 08:58:03 +0000 (+0200) Subject: fdisk: use xalloc stuff X-Git-Tag: v2.24-rc1~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5afed1872e763b3171aad79c9f08dfa111ef76a1;p=thirdparty%2Futil-linux.git fdisk: use xalloc stuff Signed-off-by: Karel Zak --- diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index 61a522c364..f8216bba9a 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -45,8 +45,6 @@ # include #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)