]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: snd_pcm_slave_conf - fix C99 variable-length array allocation
authorJaroslav Kysela <perex@perex.cz>
Mon, 25 May 2026 10:34:37 +0000 (12:34 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 25 May 2026 10:34:37 +0000 (12:34 +0200)
The C standard (C99 ยง6.7.5.2p1) requires VLA bounds to be greater than zero;
a bound of 0 is undefined behavior. Reported by UBSan.

Fixes: https://github.com/alsa-project/alsa-lib/issues/505
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm.c

index 11b15100cd796612e2c482aa3d897e24f49c66ee..f2831ed773bd45ea363c56d0915bdc8667ee3090 100644 (file)
@@ -7824,7 +7824,7 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
                int flags;
                void *ptr;
                int present;
-       } fields[count];
+       } fields[count > 0 ? count : 1];
        unsigned int k;
        snd_config_t *pcm_conf = NULL;
        int err;