From d707e133d3d4b33fa2657eac3a1f1babb40418f7 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 8 Feb 2012 12:59:19 +0000 Subject: [PATCH] Use dm_asprintf to simplify code --- WHATS_NEW_DM | 1 + libdm/ioctl/libdm-iface.c | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index f98432bab..dbb62e24f 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.70 - =================================== + Simplify dm_task_set_geometry() and use dm_asprintf(). Set all parameters to 0 for dm_get_next_target() for NULL return. Fix fd resource leak in error path for _udev_notify_sem_create(). Leave space for '\0' for readline() call in _sysfs_get_kernel_name(). diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index fa38c4380..dfe9e012f 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -769,16 +769,11 @@ int dm_task_set_sector(struct dm_task *dmt, uint64_t sector) return 1; } -int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start) +int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, + const char *sectors, const char *start) { - size_t len = strlen(cylinders) + 1 + strlen(heads) + 1 + strlen(sectors) + 1 + strlen(start) + 1; - - if (!(dmt->geometry = dm_malloc(len))) { - log_error("dm_task_set_geometry: dm_malloc failed"); - return 0; - } - - if (sprintf(dmt->geometry, "%s %s %s %s", cylinders, heads, sectors, start) < 0) { + if (dm_asprintf(&(dmt->geometry), "%s %s %s %s", + cylinders, heads, sectors, start) < 0) { log_error("dm_task_set_geometry: sprintf failed"); return 0; }