提交 9f66e09b 编写于 作者: J John Ferlan

util: Change return argument for virBitmapParseUnlimited

Rather than returning an int and a *bitmap pointer, just return and
check a NULL bitmap pointer
上级 0543db3a
...@@ -545,7 +545,6 @@ virBitmapParse(const char *str, ...@@ -545,7 +545,6 @@ virBitmapParse(const char *str,
/** /**
* virBitmapParseUnlimited: * virBitmapParseUnlimited:
* @str: points to a string representing a human-readable bitmap * @str: points to a string representing a human-readable bitmap
* @bitmap: a bitmap created from @str
* *
* This function is the counterpart of virBitmapFormat. This function creates * This function is the counterpart of virBitmapFormat. This function creates
* a bitmap, in which bits are set according to the content of @str. * a bitmap, in which bits are set according to the content of @str.
...@@ -556,20 +555,20 @@ virBitmapParse(const char *str, ...@@ -556,20 +555,20 @@ virBitmapParse(const char *str,
* to set, and ^N, which means to unset the bit, and N-M for ranges of bits * to set, and ^N, which means to unset the bit, and N-M for ranges of bits
* to set. * to set.
* *
* Returns 0 on success, or -1 in case of error. * Returns @bitmap on success, or NULL in case of error
*/ */
int virBitmapPtr
virBitmapParseUnlimited(const char *str, virBitmapParseUnlimited(const char *str)
virBitmapPtr *bitmap)
{ {
virBitmapPtr bitmap;
bool neg = false; bool neg = false;
const char *cur = str; const char *cur = str;
char *tmp; char *tmp;
size_t i; size_t i;
int start, last; int start, last;
if (!(*bitmap = virBitmapNewEmpty())) if (!(bitmap = virBitmapNewEmpty()))
return -1; return NULL;
if (!str) if (!str)
goto error; goto error;
...@@ -605,10 +604,10 @@ virBitmapParseUnlimited(const char *str, ...@@ -605,10 +604,10 @@ virBitmapParseUnlimited(const char *str,
if (*cur == ',' || *cur == 0) { if (*cur == ',' || *cur == 0) {
if (neg) { if (neg) {
if (virBitmapClearBitExpand(*bitmap, start) < 0) if (virBitmapClearBitExpand(bitmap, start) < 0)
goto error; goto error;
} else { } else {
if (virBitmapSetBitExpand(*bitmap, start) < 0) if (virBitmapSetBitExpand(bitmap, start) < 0)
goto error; goto error;
} }
} else if (*cur == '-') { } else if (*cur == '-') {
...@@ -626,7 +625,7 @@ virBitmapParseUnlimited(const char *str, ...@@ -626,7 +625,7 @@ virBitmapParseUnlimited(const char *str,
cur = tmp; cur = tmp;
for (i = start; i <= last; i++) { for (i = start; i <= last; i++) {
if (virBitmapSetBitExpand(*bitmap, i) < 0) if (virBitmapSetBitExpand(bitmap, i) < 0)
goto error; goto error;
} }
...@@ -644,14 +643,13 @@ virBitmapParseUnlimited(const char *str, ...@@ -644,14 +643,13 @@ virBitmapParseUnlimited(const char *str,
} }
} }
return 0; return bitmap;
error: error:
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("Failed to parse bitmap '%s'"), str); _("Failed to parse bitmap '%s'"), str);
virBitmapFree(*bitmap); virBitmapFree(bitmap);
*bitmap = NULL; return NULL;
return -1;
} }
/** /**
......
...@@ -94,10 +94,9 @@ virBitmapParseSeparator(const char *str, ...@@ -94,10 +94,9 @@ virBitmapParseSeparator(const char *str,
char terminator, char terminator,
virBitmapPtr *bitmap, virBitmapPtr *bitmap,
size_t bitmapSize); size_t bitmapSize);
int virBitmapPtr
virBitmapParseUnlimited(const char *str, virBitmapParseUnlimited(const char *str)
virBitmapPtr *bitmap) ATTRIBUTE_NONNULL(1);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ATTRIBUTE_NONNULL(1); virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ATTRIBUTE_NONNULL(1);
......
...@@ -926,7 +926,7 @@ int virTestMain(int argc, ...@@ -926,7 +926,7 @@ int virTestMain(int argc,
} }
if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) { if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) {
if (virBitmapParseUnlimited(testRange, &testBitmap) < 0) { if (!(testBitmap = virBitmapParseUnlimited(testRange))) {
fprintf(stderr, "Cannot parse range %s\n", testRange); fprintf(stderr, "Cannot parse range %s\n", testRange);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
...@@ -650,7 +650,7 @@ test12(const void *opaque ATTRIBUTE_UNUSED) ...@@ -650,7 +650,7 @@ test12(const void *opaque ATTRIBUTE_UNUSED)
TEST_MAP(151, "128"); TEST_MAP(151, "128");
virBitmapFree(map); virBitmapFree(map);
if (virBitmapParseUnlimited("34,1023", &map) < 0) if (!(map = virBitmapParseUnlimited("34,1023")))
goto cleanup; goto cleanup;
TEST_MAP(1024, "34,1023"); TEST_MAP(1024, "34,1023");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册