From ab589592d5b461bc09f968d950eccf2397df85c0 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:54:51 +0100 Subject: [PATCH] fix compiler warnings for glibc 2.43 and newer this version changed so that many standard functions now propagate the constness of its input pointers to not cause warnings for everyone on older versions this is now a really dumb macro lol --- src/d_main.c | 2 +- src/doomtype.h | 9 +++++++++ src/g_game.c | 3 +++ src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/m_misc.c | 6 +++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c33c13da8..34209e32a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2137,7 +2137,7 @@ void D_SRB2Main(void) if (M_CheckProtoParam("replay")) { const char *replayurl = M_GetProtoParam(); - char *replayname = strrchr(replayurl, '/'); + gconst char *replayname = strrchr(replayurl, '/'); if (!replayname || !replayurl) I_Error("REPLAY: Invalid URL."); diff --git a/src/doomtype.h b/src/doomtype.h index 27571f981..3294bcdad 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,6 +68,15 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif +// glibc 2.43 made alot of standard lib functions propagate the constness of its input pointers +// to not cause warnings or compile issues on older glibc versions we do this silly thing +// to not have a gazillion glibc version checks +#if __GLIBC_PREREQ(2, 43) + #define gconst const +#else + #define gconst +#endif + #ifndef _GNU_SOURCE char *nongnu_strcasestr(const char *in, const char *what); #define strcasestr nongnu_strcasestr diff --git a/src/g_game.c b/src/g_game.c index fd247a026..90334aa7b 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4162,6 +4162,7 @@ static void measurekeywords(mapsearchfreq_t *fr, { char *qp; char *sp; + if (wanttable) (*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim), PU_STATIC, NULL); @@ -4176,10 +4177,12 @@ static void measurekeywords(mapsearchfreq_t *fr, (*dimp)[(*cuntp)].pos = sp - s; (*dimp)[(*cuntp)].siz = strlen(qp); } + (*cuntp)++; fr->total++; } } + if (wanttable) (*dimp) = Z_Realloc((*dimp), (*cuntp) * sizeof (struct searchdim), PU_STATIC, NULL); diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index a1c275b8e..533a34bad 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -112,7 +112,7 @@ boolean HWR_InitShaders(void) // returns INT32_MAX if not found static INT32 strstr_int(const char *str1, const char *str2) { - char *location = strstr(str1, str2); + gconst char *location = strstr(str1, str2); if (location) return location - str1; else diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 3571c607d..383647d89 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1387,19 +1387,19 @@ void GL_Flush(void) // -----------------+ INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { - GLubyte *where, *terminator; + gconst GLubyte *where, *terminator; if (!extension || !start) return 0; - where = (GLubyte *) strchr(extension, ' '); + where = (gconst GLubyte *)strchr(extension, ' '); if (where || *extension == '\0') return 0; for (;;) { - where = (GLubyte *) strstr((const char *) start, extension); + where = (gconst GLubyte *)strstr((const char *)start, extension); if (!where) break; diff --git a/src/m_misc.c b/src/m_misc.c index 24d61c531..dca00950d 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1454,9 +1454,9 @@ INT32 axtoi(const char *hexStg) void CopyCaretColors(char *p, const char *s, int n) { - char *t; - int m; - int c; + gconst char *t; + int m; + int c; if (!n) return;