SDL_power.c: Adjust SDL_POWER_DISABLED ifdefs to avoid zero-size array

Otherwise if SDL_POWER_DISABLED is disabled (eg with --disable-power):

... with clang -pedantic:
src/power/SDL_power.c:48:50: warning: use of GNU empty initializer extension [-Wgnu-empty-initializer]
static SDL_GetPowerInfo_Impl implementations[] = {
                                                 ^
src/power/SDL_power.c:48:50: warning: zero size arrays are an extension [-Wzero-length-array]
2 warnings generated.

... with gcc -pedantic:
src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic]
src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic]
 static SDL_GetPowerInfo_Impl implementations[] = {
                                                  ^
src/power/SDL_power.c:48:30: error: zero or negative size array ?implementations?
 static SDL_GetPowerInfo_Impl implementations[] = {
                              ^~~~~~~~~~~~~~~

... with Watcom:
./src/power/SDL_power.c(85): Error! E1112: Initializer list cannot be empty
This commit is contained in:
Ozkan Sezer
2018-10-15 11:01:00 +03:00
parent dae4a01361
commit 7be4fca62c
3 changed files with 12 additions and 15 deletions

View File

@@ -42,11 +42,8 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
return SDL_TRUE;
}
#endif
#endif
static SDL_GetPowerInfo_Impl implementations[] = {
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
SDL_GetPowerInfo_Linux_org_freedesktop_upower,
SDL_GetPowerInfo_Linux_sys_class_power_supply,
@@ -81,31 +78,34 @@ static SDL_GetPowerInfo_Impl implementations[] = {
#ifdef SDL_POWER_HARDWIRED
SDL_GetPowerInfo_Hardwired,
#endif
#endif
};
#endif
SDL_PowerState
SDL_GetPowerInfo(int *seconds, int *percent)
{
#ifndef SDL_POWER_DISABLED
const int total = sizeof(implementations) / sizeof(implementations[0]);
int _seconds, _percent;
SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
int i;
#endif
int _seconds, _percent;
/* Make these never NULL for platform-specific implementations. */
if (seconds == NULL) {
seconds = &_seconds;
}
if (percent == NULL) {
percent = &_percent;
}
#ifndef SDL_POWER_DISABLED
for (i = 0; i < total; i++) {
if (implementations[i](&retval, seconds, percent)) {
return retval;
}
}
#endif
/* nothing was definitive. */
*seconds = -1;