Re-arrange the code so that the returned bitmap is always initialized to NULL even on early failures and return an error message as some callers are already expecting it. --- src/util/virbitmap.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 47c678e..5d0655c 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -298,23 +298,21 @@ virBitmapParse(const char *str, size_t bitmapSize) { bool neg = false; - const char *cur; + const char *cur = str; char *tmp; size_t i; int start, last; - if (!str) + if (!(*bitmap = virBitmapNew(bitmapSize))) return -1; - cur = str; - virSkipSpaces(&cur); + if (!str) + goto error; - if (*cur == 0) - return -1; + virSkipSpaces(&cur); - *bitmap = virBitmapNew(bitmapSize); - if (!*bitmap) - return -1; + if (*cur == '\0') + goto error; while (*cur != 0 && *cur != terminator) { /* @@ -384,6 +382,8 @@ virBitmapParse(const char *str, return virBitmapCountBits(*bitmap); error: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse bitmap '%s'", str)); virBitmapFree(*bitmap); *bitmap = NULL; return -1; -- 1.8.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list