mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-07-10 13:29:52 -04:00
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
This commit is contained in:
parent
39abe4f698
commit
9dce0c3258
2 changed files with 20 additions and 4 deletions
|
|
@ -52,6 +52,7 @@ struct pcm_sink {
|
||||||
|
|
||||||
enum pcm_sink_ids {
|
enum pcm_sink_ids {
|
||||||
PCM_SINK_BUILTIN = 0,
|
PCM_SINK_BUILTIN = 0,
|
||||||
|
PCM_SINK_NUM
|
||||||
};
|
};
|
||||||
|
|
||||||
/* defined in each platform pcm source */
|
/* defined in each platform pcm source */
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
#include "panic.h"
|
||||||
|
|
||||||
/* Define LOGF_ENABLE to enable logf output in this file */
|
/* Define LOGF_ENABLE to enable logf output in this file */
|
||||||
//#define LOGF_ENABLE
|
//#define LOGF_ENABLE
|
||||||
|
|
@ -76,7 +77,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct pcm_sink* sinks[1] = {
|
static struct pcm_sink* sinks[PCM_SINK_NUM] = {
|
||||||
[PCM_SINK_BUILTIN] = &builtin_pcm_sink,
|
[PCM_SINK_BUILTIN] = &builtin_pcm_sink,
|
||||||
};
|
};
|
||||||
static enum pcm_sink_ids cur_sink = PCM_SINK_BUILTIN;
|
static enum pcm_sink_ids cur_sink = PCM_SINK_BUILTIN;
|
||||||
|
|
@ -247,7 +248,7 @@ void pcm_init(void)
|
||||||
{
|
{
|
||||||
logf("pcm_init");
|
logf("pcm_init");
|
||||||
|
|
||||||
for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) {
|
for(size_t i = 0; i < PCM_SINK_NUM; i += 1) {
|
||||||
struct pcm_sink* sink = sinks[i];
|
struct pcm_sink* sink = sinks[i];
|
||||||
sink->pending_freq = sink->caps.default_freq;
|
sink->pending_freq = sink->caps.default_freq;
|
||||||
sink->configured_freq = -1U;
|
sink->configured_freq = -1U;
|
||||||
|
|
@ -261,7 +262,7 @@ void pcm_postinit(void)
|
||||||
{
|
{
|
||||||
logf("pcm_postinit");
|
logf("pcm_postinit");
|
||||||
|
|
||||||
for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) {
|
for(size_t i = 0; i < PCM_SINK_NUM; i += 1) {
|
||||||
struct pcm_sink* sink = sinks[i];
|
struct pcm_sink* sink = sinks[i];
|
||||||
sink->ops.postinit();
|
sink->ops.postinit();
|
||||||
sink->pcm_is_ready = true;
|
sink->pcm_is_ready = true;
|
||||||
|
|
@ -294,15 +295,29 @@ const struct pcm_sink_caps* pcm_current_sink_caps(void)
|
||||||
bool pcm_switch_sink(enum pcm_sink_ids sink)
|
bool pcm_switch_sink(enum pcm_sink_ids sink)
|
||||||
{
|
{
|
||||||
logf("pcm_switch_sink %d to %d", cur_sink, sink);
|
logf("pcm_switch_sink %d to %d", cur_sink, sink);
|
||||||
if(sink >= ARRAYLEN(sinks)) {
|
if(sink >= PCM_SINK_NUM) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cur_sink == sink) {
|
if(cur_sink == sink) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This should not be possible but it silences
|
||||||
|
a false warning that only occurs with with GCC9.5 on bare metal ARM.
|
||||||
|
*/
|
||||||
|
#if __GNUC__ == 9 && defined(CPU_ARM)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* save current sink before switching */
|
/* save current sink before switching */
|
||||||
struct pcm_sink* old_sink = sinks[cur_sink];
|
struct pcm_sink* old_sink = sinks[cur_sink];
|
||||||
|
|
||||||
|
#if __GNUC__ == 9
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
/* update sink index */
|
/* update sink index */
|
||||||
cur_sink = sink;
|
cur_sink = sink;
|
||||||
/* synchronize frequency */
|
/* synchronize frequency */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue