[PATCH 4/4] virCapabilitiesHostNUMAFormat: Bring variables into loops

Michal Privoznik posted 4 patches 4 years, 8 months ago
[PATCH 4/4] virCapabilitiesHostNUMAFormat: Bring variables into loops
Posted by Michal Privoznik 4 years, 8 months ago
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/capabilities.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 1dae6d38cc..915cd3149e 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -807,8 +807,6 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
                               virCapsHostNUMA *caps)
 {
     size_t i;
-    size_t j;
-    char *siblings;
 
     if (!caps)
         return 0;
@@ -819,6 +817,8 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
     virBufferAdjustIndent(buf, 2);
     for (i = 0; i < caps->cells->len; i++) {
         virCapsHostNUMACell *cell = g_ptr_array_index(caps->cells, i);
+        size_t j;
+
         virBufferAsprintf(buf, "<cell id='%d'>\n", cell->num);
         virBufferAdjustIndent(buf, 2);
 
@@ -847,10 +847,12 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
 
         virBufferAsprintf(buf, "<cpus num='%d'>\n", cell->ncpus);
         virBufferAdjustIndent(buf, 2);
-        for (j = 0; j < cell->ncpus; j++) {
+        for (j = 0; j < cell->ncpus; ++j) {
             virBufferAsprintf(buf, "<cpu id='%d'", cell->cpus[j].id);
 
             if (cell->cpus[j].siblings) {
+                g_autofree char * siblings = NULL;
+
                 if (!(siblings = virBitmapFormat(cell->cpus[j].siblings)))
                     return -1;
 
@@ -860,7 +862,6 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
                                   cell->cpus[j].die_id,
                                   cell->cpus[j].core_id,
                                   siblings);
-                VIR_FREE(siblings);
             }
             virBufferAddLit(buf, "/>\n");
         }
-- 
2.26.3

Re: [PATCH 4/4] virCapabilitiesHostNUMAFormat: Bring variables into loops
Posted by Ján Tomko 4 years, 8 months ago
On a Monday in 2021, Michal Privoznik wrote:
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/conf/capabilities.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
>diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
>index 1dae6d38cc..915cd3149e 100644
>--- a/src/conf/capabilities.c
>+++ b/src/conf/capabilities.c
>@@ -807,8 +807,6 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>                               virCapsHostNUMA *caps)
> {
>     size_t i;
>-    size_t j;
>-    char *siblings;
>
>     if (!caps)
>         return 0;
>@@ -819,6 +817,8 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>     virBufferAdjustIndent(buf, 2);
>     for (i = 0; i < caps->cells->len; i++) {
>         virCapsHostNUMACell *cell = g_ptr_array_index(caps->cells, i);
>+        size_t j;
>+
>         virBufferAsprintf(buf, "<cell id='%d'>\n", cell->num);
>         virBufferAdjustIndent(buf, 2);
>
>@@ -847,10 +847,12 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>
>         virBufferAsprintf(buf, "<cpus num='%d'>\n", cell->ncpus);
>         virBufferAdjustIndent(buf, 2);
>-        for (j = 0; j < cell->ncpus; j++) {
>+        for (j = 0; j < cell->ncpus; ++j) {

No need to change the post-increment to pre-increment.

Jano

>             virBufferAsprintf(buf, "<cpu id='%d'", cell->cpus[j].id);
>
>             if (cell->cpus[j].siblings) {
>+                g_autofree char * siblings = NULL;
>+
>                 if (!(siblings = virBitmapFormat(cell->cpus[j].siblings)))
>                     return -1;
>
Re: [PATCH 4/4] virCapabilitiesHostNUMAFormat: Bring variables into loops
Posted by Michal Prívozník 4 years, 8 months ago
On 5/17/21 3:46 PM, Ján Tomko wrote:
> On a Monday in 2021, Michal Privoznik wrote:
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>> src/conf/capabilities.c | 9 +++++----
>> 1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
>> index 1dae6d38cc..915cd3149e 100644
>> --- a/src/conf/capabilities.c
>> +++ b/src/conf/capabilities.c
>> @@ -807,8 +807,6 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>>                               virCapsHostNUMA *caps)
>> {
>>     size_t i;
>> -    size_t j;
>> -    char *siblings;
>>
>>     if (!caps)
>>         return 0;
>> @@ -819,6 +817,8 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>>     virBufferAdjustIndent(buf, 2);
>>     for (i = 0; i < caps->cells->len; i++) {
>>         virCapsHostNUMACell *cell = g_ptr_array_index(caps->cells, i);
>> +        size_t j;
>> +
>>         virBufferAsprintf(buf, "<cell id='%d'>\n", cell->num);
>>         virBufferAdjustIndent(buf, 2);
>>
>> @@ -847,10 +847,12 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf,
>>
>>         virBufferAsprintf(buf, "<cpus num='%d'>\n", cell->ncpus);
>>         virBufferAdjustIndent(buf, 2);
>> -        for (j = 0; j < cell->ncpus; j++) {
>> +        for (j = 0; j < cell->ncpus; ++j) {
> 
> No need to change the post-increment to pre-increment.

Huh, I have no idea how that slipped in there :-)

Michal