From 33dea28e23b4f9f9d374de6b3fd293275c2f27db Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 8 Feb 2012 12:50:10 +0000 Subject: [PATCH] Use dm_snprintf and improve error handling Add standard error reporting with error logging. Use plain alloc instead of zalloc for string buffer. Use dm_snprintf with valid test for <0. --- WHATS_NEW | 1 + lib/format_text/archiver.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 3bae8ac96..8cb8871cd 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.91 - =================================== + Fix error path handling in _build_desc() Add range test for device number in _scan_proc_dev(). Use signed long for sysconf() call in cmirrord. Do not write in front of log buffer in print_log(). diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c index d249b96e6..0efdcb840 100644 --- a/lib/format_text/archiver.c +++ b/lib/format_text/archiver.c @@ -83,13 +83,16 @@ static char *_build_desc(struct dm_pool *mem, const char *line, int before) size_t len = strlen(line) + 32; char *buffer; - if (!(buffer = dm_pool_zalloc(mem, strlen(line) + 32))) - return_NULL; + if (!(buffer = dm_pool_alloc(mem, len))) { + log_error("Failed to allocate desc."); + return NULL; + } - if (snprintf(buffer, len, - "Created %s executing '%s'", - before ? "*before*" : "*after*", line) < 0) - return_NULL; + if (dm_snprintf(buffer, len, "Created %s executing '%s'", + before ? "*before*" : "*after*", line) < 0) { + log_error("Failed to build desc."); + return NULL; + } return buffer; }