Skip to contentSkip to conversation

tools/helpers: fix snprintf argument in init-dom0less.c

PATCH In review Luca Fancellu 3 participants 3 messages Jun 29, 2022 – Jul 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/helpers: fix snprintf argument in init-dom0less.c

Fix snprintf argument in init-dom0less.c because two instances of the function are using libxl_dominfo struct members that are uint64_t types, so change "%lu" to "%"PRIu64 to handle it properly when building on arm32 and arm64.

---
 tools/helpers/init-dom0less.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/helpers/init-dom0less.c +3 -2
index 4c90dd6a0c8f..fee93459c4b9 100644
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/time.h>
+#include <inttypes.h>
 #include <xenstore.h>
 #include <xenctrl.h>
 #include <xenguest.h>
@@ -138,10 +139,10 @@ static int create_xenstore(struct xs_handle *xsh,
                   "vm/" LIBXL_UUID_FMT, LIBXL_UUID_BYTES(uuid));
     if (rc < 0 || rc >= STR_MAX_LENGTH)
         return rc;
-    rc = snprintf(max_memkb_str, STR_MAX_LENGTH, "%lu", info->max_memkb);
+    rc = snprintf(max_memkb_str, STR_MAX_LENGTH, "%"PRIu64, info->max_memkb);
     if (rc < 0 || rc >= STR_MAX_LENGTH)
         return rc;
-    rc = snprintf(target_memkb_str, STR_MAX_LENGTH, "%lu", info->current_memkb);
+    rc = snprintf(target_memkb_str, STR_MAX_LENGTH, "%"PRIu64, info->current_memkb);
     if (rc < 0 || rc >= STR_MAX_LENGTH)
         return rc;
     rc = snprintf(ring_ref_str, STR_MAX_LENGTH, "%lld",
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Luca,

Quoted 8 lines · Luca Fancellu

Fix snprintf argument in init-dom0less.c because two instances of the function are using libxl_dominfo struct members that are uint64_t types, so change "%lu" to "%"PRIu64 to handle it properly when building on arm32 and arm64.

Cheers
Bertrand

Quoted 32 lines

---
tools/helpers/init-dom0less.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
tools/helpers/init-dom0less.c +3 -2
index 4c90dd6a0c8f..fee93459c4b9 100644
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/time.h>
+#include <inttypes.h>
 #include <xenstore.h>
 #include <xenctrl.h>
 #include <xenguest.h>
@@ -138,10 +139,10 @@ static int create_xenstore(struct xs_handle *xsh,
                  "vm/" LIBXL_UUID_FMT, LIBXL_UUID_BYTES(uuid));
    if (rc < 0 || rc >= STR_MAX_LENGTH)
        return rc;
-    rc = snprintf(max_memkb_str, STR_MAX_LENGTH, "%lu", info->max_memkb);
+    rc = snprintf(max_memkb_str, STR_MAX_LENGTH, "%"PRIu64, info->max_memkb);
    if (rc < 0 || rc >= STR_MAX_LENGTH)
        return rc;
-    rc = snprintf(target_memkb_str, STR_MAX_LENGTH, "%lu", info->current_memkb);
+    rc = snprintf(target_memkb_str, STR_MAX_LENGTH, "%"PRIu64, info->current_memkb);
    if (rc < 0 || rc >= STR_MAX_LENGTH)
        return rc;
    rc = snprintf(ring_ref_str, STR_MAX_LENGTH, "%lld",
Signature · 1 line
2.17.1
#2 lore raw
Quoted 11 lines · Bertrand Marquis

Hi Luca,

Quoted 8 lines · Luca Fancellu

Fix snprintf argument in init-dom0less.c because two instances of the function are using libxl_dominfo struct members that are uint64_t types, so change "%lu" to "%"PRIu64 to handle it properly when building on arm32 and arm64.

Thanks,

Signature · 1 line
Anthony PERARD