Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Work around a false positive compiler warning in pcm_switch_sink()

CC firmware/pcm.c
firmware/pcm.c: In function ‘pcm_switch_sink’:
firmware/pcm.c:311:38: warning: array subscript 1 is above array bounds of ‘struct pcm_sink *[1]’ [-Warray-bounds]
311 | struct pcm_sink* old_sink = sinks[cur_sink];
| ~~~~~^~~~~~~~~~
firmware/pcm.c:79:25: note: while referencing ‘sinks’
79 | static struct pcm_sink* sinks[PCM_SINK_NUM] = {
|

PCM_SINK_NUM is 1, and cur_sink is initialized to 0. It can never be set
above 0. cur_sink can never be >= PCM_SINK_NUM, ie 0, but for some reason
the compiler thinks otherwise.... sometimes.

This only shows up on native ARM builds with GCC9.5.0

Change-Id: I1aa731a4ee21c46a264c8b70833e3b43e777e8a7

+20 -4
+1
firmware/export/pcm_sink.h
··· 52 52 53 53 enum pcm_sink_ids { 54 54 PCM_SINK_BUILTIN = 0, 55 + PCM_SINK_NUM 55 56 }; 56 57 57 58 /* defined in each platform pcm source */
+19 -4
firmware/pcm.c
··· 21 21 #include <stdlib.h> 22 22 #include "system.h" 23 23 #include "kernel.h" 24 + #include "panic.h" 24 25 25 26 /* Define LOGF_ENABLE to enable logf output in this file */ 26 27 //#define LOGF_ENABLE ··· 76 77 * 77 78 */ 78 79 79 - static struct pcm_sink* sinks[1] = { 80 + static struct pcm_sink* sinks[PCM_SINK_NUM] = { 80 81 [PCM_SINK_BUILTIN] = &builtin_pcm_sink, 81 82 }; 82 83 static enum pcm_sink_ids cur_sink = PCM_SINK_BUILTIN; ··· 247 248 { 248 249 logf("pcm_init"); 249 250 250 - for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) { 251 + for(size_t i = 0; i < PCM_SINK_NUM; i += 1) { 251 252 struct pcm_sink* sink = sinks[i]; 252 253 sink->pending_freq = sink->caps.default_freq; 253 254 sink->configured_freq = -1U; ··· 261 262 { 262 263 logf("pcm_postinit"); 263 264 264 - for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) { 265 + for(size_t i = 0; i < PCM_SINK_NUM; i += 1) { 265 266 struct pcm_sink* sink = sinks[i]; 266 267 sink->ops.postinit(); 267 268 sink->pcm_is_ready = true; ··· 294 295 bool pcm_switch_sink(enum pcm_sink_ids sink) 295 296 { 296 297 logf("pcm_switch_sink %d to %d", cur_sink, sink); 297 - if(sink >= ARRAYLEN(sinks)) { 298 + if(sink >= PCM_SINK_NUM) { 298 299 return false; 299 300 } 300 301 301 302 if(cur_sink == sink) { 302 303 return true; 303 304 } 305 + 306 + /* This should not be possible but it silences 307 + a false warning that only occurs with with GCC9.5 on bare metal ARM. 308 + */ 309 + #if __GNUC__ == 9 && defined(CPU_ARM) 310 + #pragma GCC diagnostic push 311 + #pragma GCC diagnostic ignored "-Warray-bounds" 312 + #endif 313 + 304 314 /* save current sink before switching */ 305 315 struct pcm_sink* old_sink = sinks[cur_sink]; 316 + 317 + #if __GNUC__ == 9 318 + #pragma GCC diagnostic pop 319 + #endif 320 + 306 321 /* update sink index */ 307 322 cur_sink = sink; 308 323 /* synchronize frequency */