提交 3ceb6951 编写于 作者: P Peter Krempa

virBitmapNewEmpty: Use g_new0 to allocate and remove error checking

virBitmapNewEmpty can't fail now so we can make it obvious and fix all
callers.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 29979632
...@@ -110,17 +110,12 @@ virBitmapNew(size_t size) ...@@ -110,17 +110,12 @@ virBitmapNew(size_t size)
* *
* Allocate an empty bitmap. It can be used with self-expanding APIs. * Allocate an empty bitmap. It can be used with self-expanding APIs.
* *
* Returns a pointer to the allocated bitmap or NULL if memory cannot be * Returns a pointer to the allocated bitmap.
* allocated. Reports libvirt errors.
*/ */
virBitmapPtr virBitmapPtr
virBitmapNewEmpty(void) virBitmapNewEmpty(void)
{ {
virBitmapPtr ret; return g_new0(virBitmap, 1);
ignore_value(VIR_ALLOC(ret));
return ret;
} }
...@@ -610,16 +605,13 @@ virBitmapParse(const char *str, ...@@ -610,16 +605,13 @@ virBitmapParse(const char *str,
virBitmapPtr virBitmapPtr
virBitmapParseUnlimited(const char *str) virBitmapParseUnlimited(const char *str)
{ {
virBitmapPtr bitmap; virBitmapPtr bitmap = virBitmapNewEmpty();
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()))
return NULL;
if (!str) if (!str)
goto error; goto error;
......
...@@ -336,8 +336,7 @@ virHostCPUParseNode(const char *node, ...@@ -336,8 +336,7 @@ virHostCPUParseNode(const char *node,
goto cleanup; goto cleanup;
/* enumerate sockets in the node */ /* enumerate sockets in the node */
if (!(sockets_map = virBitmapNewEmpty())) sockets_map = virBitmapNewEmpty();
goto cleanup;
while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) { while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1) if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
...@@ -373,8 +372,7 @@ virHostCPUParseNode(const char *node, ...@@ -373,8 +372,7 @@ virHostCPUParseNode(const char *node,
goto cleanup; goto cleanup;
for (i = 0; i < sock_max; i++) for (i = 0; i < sock_max; i++)
if (!(cores_maps[i] = virBitmapNewEmpty())) cores_maps[i] = virBitmapNewEmpty();
goto cleanup;
/* Iterate over all CPUs in the node, in ascending order */ /* Iterate over all CPUs in the node, in ascending order */
for (cpu = 0; cpu < npresent_cpus; cpu++) { for (cpu = 0; cpu < npresent_cpus; cpu++) {
......
...@@ -183,8 +183,7 @@ virTPMExecGetCaps(virCommandPtr cmd, ...@@ -183,8 +183,7 @@ virTPMExecGetCaps(virCommandPtr cmd,
if (virCommandRun(cmd, &exitstatus) < 0) if (virCommandRun(cmd, &exitstatus) < 0)
return NULL; return NULL;
if (!(bitmap = virBitmapNewEmpty())) bitmap = virBitmapNewEmpty();
return NULL;
/* older version does not support --print-capabilties -- that's fine */ /* older version does not support --print-capabilties -- that's fine */
if (exitstatus != 0) { if (exitstatus != 0) {
......
...@@ -193,8 +193,7 @@ test4(const void *data G_GNUC_UNUSED) ...@@ -193,8 +193,7 @@ test4(const void *data G_GNUC_UNUSED)
/* 0. empty set */ /* 0. empty set */
if (!(bitmap = virBitmapNewEmpty())) bitmap = virBitmapNewEmpty();
goto error;
if (virBitmapNextSetBit(bitmap, -1) != -1) if (virBitmapNextSetBit(bitmap, -1) != -1)
goto error; goto error;
...@@ -632,12 +631,9 @@ test11(const void *opaque) ...@@ -632,12 +631,9 @@ test11(const void *opaque)
static int static int
test12(const void *opaque G_GNUC_UNUSED) test12(const void *opaque G_GNUC_UNUSED)
{ {
virBitmapPtr map = NULL; virBitmapPtr map = virBitmapNewEmpty();
int ret = -1; int ret = -1;
if (!(map = virBitmapNewEmpty()))
return -1;
TEST_MAP(0, ""); TEST_MAP(0, "");
if (virBitmapSetBitExpand(map, 128) < 0) if (virBitmapSetBitExpand(map, 128) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册