mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-04-11 12:40:45 +00:00
Fix (potential) problematic use cases of qboolean.
Until853f832
qboolean was always defined as an enum. Starting with853f832
it may be defined as bool when building in C23 mode or any newer standard. There are subtle behavioral differences between enum and bool, fix these: * The enum has int as underlying type, floats are cut down to the nearest int. Thus 0.5f becomes false. With bool everything which is not 0 becomes true. Gone through the code and made sure that there are no float to qboolean type conversions. * Always use true and false, not something else like 1 and 0 or (when building under Windows) TRUE and FALSE. * Fix some corner cases where integers >1 where missused as true. These should be noops. * Fix `R_GreyscaledLight()` misusing qboolean for returning int. Partly based upon yquake2/yquake2remaster@e3c8d26 Closes #1191
This commit is contained in:
parent
989c30e31d
commit
d2efa1c9af
8 changed files with 20 additions and 21 deletions
|
@ -397,7 +397,7 @@ NET_StringToSockaddr(const char *s, struct sockaddr_storage *sadr)
|
|||
if (!*space)
|
||||
{
|
||||
Com_Printf("NET_StringToSockaddr: invalid IPv6 address %s\n", s);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
*space++ = '\0';
|
||||
|
@ -417,7 +417,7 @@ NET_StringToSockaddr(const char *s, struct sockaddr_storage *sadr)
|
|||
/* Error */
|
||||
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s,
|
||||
gai_strerror(err));
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (resultp->ai_family)
|
||||
|
@ -432,7 +432,7 @@ NET_StringToSockaddr(const char *s, struct sockaddr_storage *sadr)
|
|||
default:
|
||||
Com_Printf("NET_StringToSockaddr: string %s:\nprotocol family %d not supported\n",
|
||||
s, resultp->ai_family);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
freeaddrinfo(resultp);
|
||||
|
|
|
@ -79,7 +79,7 @@ Hunk_Begin(int maxsize)
|
|||
prot |= PROT_MAX(prot);
|
||||
#endif
|
||||
|
||||
membase = mmap(0, maxhunksize, prot,
|
||||
membase = (byte *)mmap(0, maxhunksize, prot,
|
||||
flags, -1, 0);
|
||||
|
||||
if ((membase == NULL) || (membase == (byte *)-1))
|
||||
|
|
|
@ -193,7 +193,7 @@ NET_CompareAdr(netadr_t a, netadr_t b)
|
|||
|
||||
if (a.type == NA_LOOPBACK)
|
||||
{
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (a.type == NA_IP)
|
||||
|
@ -240,7 +240,7 @@ NET_CompareBaseAdr(netadr_t a, netadr_t b)
|
|||
|
||||
if (a.type == NA_LOOPBACK)
|
||||
{
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (a.type == NA_IP)
|
||||
|
@ -411,7 +411,7 @@ NET_StringToSockaddr(const char *s, struct sockaddr_storage *sadr)
|
|||
if (!*space)
|
||||
{
|
||||
Com_Printf("NET_StringToSockaddr: invalid IPv6 address %s\n", s);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
*space++ = '\0';
|
||||
|
@ -431,7 +431,7 @@ NET_StringToSockaddr(const char *s, struct sockaddr_storage *sadr)
|
|||
/* Error */
|
||||
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s,
|
||||
gai_strerror(err));
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (resultp->ai_family)
|
||||
|
|
|
@ -1179,7 +1179,7 @@ qboolean CL_PendingHTTPDownloads(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
return pendingCount + handleCount;
|
||||
return ((pendingCount + handleCount) > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -39,7 +39,7 @@ surfcache_t *sc_base;
|
|||
/*
|
||||
* Color light apply is not required
|
||||
*/
|
||||
static qboolean
|
||||
static int
|
||||
R_GreyscaledLight(const light3_t light)
|
||||
{
|
||||
light3_t light_masked;
|
||||
|
|
|
@ -1344,7 +1344,7 @@ SDL_BackendInit(void)
|
|||
but this is Quake 2 ... */
|
||||
if (snd_inited)
|
||||
{
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int sndbits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value;
|
||||
|
@ -1369,7 +1369,7 @@ SDL_BackendInit(void)
|
|||
#endif
|
||||
{
|
||||
Com_Printf ("Couldn't init SDL audio: %s.\n", SDL_GetError ());
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const char* drivername = SDL_GetCurrentAudioDriver();
|
||||
|
@ -1432,7 +1432,7 @@ SDL_BackendInit(void)
|
|||
{
|
||||
Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This points to the frontend */
|
||||
|
@ -1473,7 +1473,7 @@ SDL_BackendInit(void)
|
|||
soundtime = 0;
|
||||
snd_inited = 1;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1508,7 +1508,7 @@ SDL_BackendInit(void)
|
|||
but this is Quake 2 ... */
|
||||
if (snd_inited)
|
||||
{
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int sndbits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value;
|
||||
|
@ -1529,7 +1529,7 @@ SDL_BackendInit(void)
|
|||
if (SDL_Init(SDL_INIT_AUDIO) == -1)
|
||||
{
|
||||
Com_Printf ("Couldn't init SDL audio: %s.\n", SDL_GetError ());
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const char* drivername = SDL_GetCurrentAudioDriver();
|
||||
|
@ -1592,7 +1592,7 @@ SDL_BackendInit(void)
|
|||
{
|
||||
Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError());
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This points to the frontend */
|
||||
|
@ -1633,7 +1633,7 @@ SDL_BackendInit(void)
|
|||
soundtime = 0;
|
||||
snd_inited = 1;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -54,7 +54,6 @@ int alias_count; /* for detecting runaway loops */
|
|||
cmdalias_t *cmd_alias;
|
||||
int cmd_wait;
|
||||
static int cmd_argc;
|
||||
static int cmd_argc;
|
||||
static char *cmd_argv[MAX_STRING_TOKENS];
|
||||
static char *cmd_null_string = "";
|
||||
static char cmd_args[MAX_STRING_CHARS];
|
||||
|
|
|
@ -176,11 +176,11 @@ SV_FilterPacket(char *from)
|
|||
{
|
||||
if ((in & ipfilters[i].mask) == ipfilters[i].compare)
|
||||
{
|
||||
return (int)filterban->value;
|
||||
return (filterban->value != 0);
|
||||
}
|
||||
}
|
||||
|
||||
return (int)!filterban->value;
|
||||
return (filterban->value == 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue