dircache: use alloca to avoid VLA in struct extension

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 0b52c2893378a4c6ae893f31994708a6e72832b4
Author: Aidan MacDonald <[email protected]>
Date:   Fri Aug 14 13:35:21 2026 +0100

    dircache: use alloca to avoid VLA in struct extension
    
    Clang does not support VLA-in-struct so use alloca to
    do the same thing by hand.
    
    Change-Id: Ib135d1a90b00aac3098e4c64f9f5f5e397fe771c

diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 4b584fca56..1464ffab79 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -1395,15 +1395,12 @@ static void sab_process_dir(struct file_base_info *infop, bool issab)
        should also filled in beforehand */
 
     /* allocate the stack right now to the max demand */
-    struct dirsab
-    {
-        struct sab           sab;
-        struct sab_component stack[issab ? DIRCACHE_MAX_DEPTH : 1];
-    } dirsab;
-    struct sab *sabp = &dirsab.sab;
+    size_t stackdepth = (issab ? DIRCACHE_MAX_DEPTH : 1);
+    struct sab *sabp = alloca(sizeof(*sabp) +
+                              sizeof(sabp->stack[0]) * stackdepth);
 
     sabp->quit     = false;
-    sabp->stackend = &sabp->stack[ARRAYLEN(dirsab.stack)];
+    sabp->stackend = &sabp->stack[stackdepth];
     sabp->top      = sabp->stackend;
     sabp->info     = *infop;
 
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.