[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.19] tools/libxl: remove usage of VLA arrays



commit 1406f07aa13edcbcc8094c266faab117275962c6
Author:     Roger Pau Monné <roger.pau@xxxxxxxxxx>
AuthorDate: Tue Nov 12 13:42:56 2024 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Nov 12 13:42:56 2024 +0100

    tools/libxl: remove usage of VLA arrays
    
    Clang 19 complains with the following error when building libxl:
    
    libxl_utils.c:48:15: error: variable length array folded to constant array 
as an extension [-Werror,-Wgnu-folding-constant]
       48 |     char path[strlen("/local/domain") + 12];
          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Replace the usage of strlen() with sizeof, which allows the literal
    string length to be known at build time.  Note sizeof accounts for the
    NUL terminator while strlen() didn't, hence subtract 1 from the total
    size calculation.
    
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Reviewed-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
    master commit: a7c7c3f6424504c4004bbb3437be319aa41ad580
    master date: 2024-11-05 19:59:50 +0000
---
 tools/libs/light/libxl_utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
index 10398a6c86..506c5b5631 100644
--- a/tools/libs/light/libxl_utils.c
+++ b/tools/libs/light/libxl_utils.c
@@ -45,7 +45,7 @@ unsigned long libxl_get_required_shadow_memory(unsigned long 
maxmem_kb, unsigned
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid)
 {
     unsigned int len;
-    char path[strlen("/local/domain") + 12];
+    char path[sizeof("/local/domain") + 11];
     char *s;
 
     snprintf(path, sizeof(path), "/local/domain/%d/name", domid);
@@ -141,7 +141,7 @@ int libxl_cpupool_qualifier_to_cpupoolid(libxl_ctx *ctx, 
const char *p,
 char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
 {
     unsigned int len;
-    char path[strlen("/local/pool") + 12];
+    char path[sizeof("/local/pool") + 11];
     char *s;
 
     snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.19



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.