shithub: choc

Download patch

ref: 6904023bfd41b6ee6cd7cc2903e0a142644d9594
parent: 6a6d49eaf885c63039d708249a9be8afe7ee27db
parent: a857a1416367b80da4c2f447efbb63d8e53eb120
author: Simon Howard <fraggle+github@gmail.com>
date: Mon Dec 17 04:46:51 EST 2018

Merge pull request #1121 from turol/const

Const correctness

--- a/src/hexen/ct_chat.c
+++ b/src/hexen/ct_chat.c
@@ -73,7 +73,7 @@
 
 static int FontABaseLump;
 
-char *CT_FromPlrText[MAXPLAYERS] = {
+const char *CT_FromPlrText[MAXPLAYERS] = {
     "BLUE:  ",
     "RED:  ",
     "YELLOW:  ",
--- a/src/hexen/f_finale.c
+++ b/src/hexen/f_finale.c
@@ -366,10 +366,10 @@
 
 static char *GetFinaleText(int sequence)
 {
-    char *msgLumpName;
+    const char *msgLumpName;
     int msgSize;
     int msgLump;
-    static char *winMsgLumpNames[] = {
+    static const char *winMsgLumpNames[] = {
         "win1msg",
         "win2msg",
         "win3msg"
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -93,7 +93,7 @@
 // PUBLIC DATA DEFINITIONS -------------------------------------------------
 
 GameMode_t gamemode;
-char *gamedescription;
+static const char *gamedescription;
 char *iwadfile;
 static char demolumpname[9];    // Demo lump to start playing.
 boolean nomonsters;             // checkparm of -nomonsters
@@ -119,7 +119,7 @@
 static int WarpMap;
 static int demosequence;
 static int pagetic;
-static char *pagename;
+static const char *pagename;
 static char *SavePathConfig;
 
 // CODE --------------------------------------------------------------------
--- a/src/hexen/in_lude.c
+++ b/src/hexen/in_lude.c
@@ -153,7 +153,7 @@
 //      Initializes the stats for single player mode
 //========================================================================
 
-static char *ClusMsgLumpNames[] = {
+static const char *ClusMsgLumpNames[] = {
     "clus1msg",
     "clus2msg",
     "clus3msg",
@@ -170,7 +170,7 @@
     int posnum;
     int slaughtercount;
     int playercount;
-    char *msgLumpName;
+    const char *msgLumpName;
     int msgSize;
     int msgLump;
 
--- a/src/hexen/info.c
+++ b/src/hexen/info.c
@@ -17,7 +17,7 @@
 #include "i_swap.h"
 // generated by stateco
 
-char *sprnames[] = {
+const char *sprnames[] = {
     "MAN1","ACLO","TLGL","FBL1","XPL1","ARRW","DART","RIPP","CFCF","BLAD",
     "SHRD","FFSM","FFLG","PTN1","PTN2","SOAR","INVU","SUMN","TSPK","TELO",
     "TRNG","ROCK","FOGS","FOGM","FOGL","SGSA","SGSB","PORK","EGGM","FHFX",
--- a/src/hexen/info.h
+++ b/src/hexen/info.h
@@ -3182,7 +3182,7 @@
 } state_t;
 
 extern state_t states[NUMSTATES];
-extern char *sprnames[];
+extern const char *sprnames[];
 
 
 
--- a/src/hexen/p_inter.c
+++ b/src/hexen/p_inter.c
@@ -34,7 +34,7 @@
 int AutoArmorSave[NUMCLASSES] =
     { 15 * FRACUNIT, 10 * FRACUNIT, 5 * FRACUNIT, 0 };
 
-char *TextKeyMessages[] = {
+const char *TextKeyMessages[] = {
     TXT_KEY_STEEL,
     TXT_KEY_CAVE,
     TXT_KEY_AXE,
@@ -412,12 +412,12 @@
     boolean checkAssembled;
     boolean gaveWeapon;
     int gaveMana;
-    static char *fourthWeaponText[] = {
+    static const char *fourthWeaponText[] = {
         TXT_WEAPON_F4,
         TXT_WEAPON_C4,
         TXT_WEAPON_M4
     };
-    static char *weaponPieceText[] = {
+    static const char *weaponPieceText[] = {
         TXT_QUIETUS_PIECE,
         TXT_WRAITHVERGE_PIECE,
         TXT_BLOODSCOURGE_PIECE
@@ -711,7 +711,7 @@
 static void TryPickupArtifact(player_t * player, artitype_t artifactType,
                               mobj_t * artifact)
 {
-    static char *artifactMessages[NUMARTIFACTS] = {
+    static const char *artifactMessages[NUMARTIFACTS] = {
         NULL,
         TXT_ARTIINVULNERABILITY,
         TXT_ARTIHEALTH,
--- a/src/hexen/r_local.h
+++ b/src/hexen/r_local.h
@@ -493,7 +493,7 @@
 void R_AddSprites(sector_t * sec);
 void R_AddPSprites(void);
 void R_DrawSprites(void);
-void R_InitSprites(char **namelist);
+void R_InitSprites(const char **namelist);
 void R_ClearSprites(void);
 void R_DrawMasked(void);
 void R_ClipVisSprite(vissprite_t * vis, int xl, int xh);
--- a/src/hexen/r_things.c
+++ b/src/hexen/r_things.c
@@ -65,7 +65,7 @@
 
 spriteframe_t sprtemp[30];
 int maxframe;
-char *spritename;
+static const char *spritename;
 
 
 
@@ -144,9 +144,9 @@
 =================
 */
 
-void R_InitSpriteDefs(char **namelist)
+void R_InitSpriteDefs(const char **namelist)
 {
-    char **check;
+    const char **check;
     int i, l, frame, rotation;
     int start, end;
 
@@ -258,7 +258,7 @@
 ===================
 */
 
-void R_InitSprites(char **namelist)
+void R_InitSprites(const char **namelist)
 {
     int i;
 
--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -800,7 +800,7 @@
 // Parse a line from substitute music configuration file; returns error
 // message or NULL for no error.
 
-static char *ParseSubstituteLine(char *musicdir, char *line)
+static const char *ParseSubstituteLine(char *musicdir, char *line)
 {
     const char *hash_prefix;
     char *filename;
@@ -887,7 +887,7 @@
 
     while (line != NULL)
     {
-        char *error;
+        const char *error;
         char *next;
 
         // find end of line
--- a/src/net_dedicated.c
+++ b/src/net_dedicated.c
@@ -36,7 +36,7 @@
 // specified to a dedicated server.
 //
 
-static char *not_dedicated_options[] = 
+static const char *not_dedicated_options[] =
 {
     "-deh", "-iwad", "-cdrom", "-gameversion", "-nomonsters", "-respawn",
     "-fast", "-altdeath", "-deathmatch", "-turbo", "-merge", "-af", "-as",
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -87,7 +87,7 @@
 
     // Try to resolve a name to an address
 
-    net_addr_t *(*ResolveAddress)(char *addr);
+    net_addr_t *(*ResolveAddress)(const char *addr);
 };
 
 // net_addr_t
@@ -242,13 +242,13 @@
 
 typedef struct
 {
-    char *version;
+    const char *version;
     int server_state;
     int num_players;
     int max_players;
     int gamemode;
     int gamemission;
-    char *description;
+    const char *description;
     net_protocol_t protocol;
 } net_querydata_t;
 
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -235,7 +235,7 @@
     }
 }
 
-static void PrintSHA1Digest(char *s, byte *digest)
+static void PrintSHA1Digest(const char *s, const byte *digest)
 {
     unsigned int i;
 
--- a/src/net_io.c
+++ b/src/net_io.c
@@ -54,7 +54,7 @@
     ++context->num_modules;
 }
 
-net_addr_t *NET_ResolveAddress(net_context_t *context, char *addr)
+net_addr_t *NET_ResolveAddress(net_context_t *context, const char *addr)
 {
     int i;
     net_addr_t *result;
--- a/src/net_io.h
+++ b/src/net_io.h
@@ -30,7 +30,7 @@
                        net_packet_t **packet);
 char *NET_AddrToString(net_addr_t *addr);
 void NET_FreeAddress(net_addr_t *addr);
-net_addr_t *NET_ResolveAddress(net_context_t *context, char *address);
+net_addr_t *NET_ResolveAddress(net_context_t *context, const char *address);
 
 #endif  /* #ifndef NET_IO_H */
 
--- a/src/net_loop.c
+++ b/src/net_loop.c
@@ -128,7 +128,7 @@
 {
 }
 
-static net_addr_t *NET_CL_ResolveAddress(char *address)
+static net_addr_t *NET_CL_ResolveAddress(const char *address)
 {
     if (address == NULL)
     {
@@ -204,7 +204,7 @@
 {
 }
 
-static net_addr_t *NET_SV_ResolveAddress(char *address)
+static net_addr_t *NET_SV_ResolveAddress(const char *address)
 {
     if (address == NULL)
     {
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -642,8 +642,8 @@
 
 // -----------------------------------------------------------------------
 
-static void formatted_printf(int wide, char *s, ...) PRINTF_ATTR(2, 3);
-static void formatted_printf(int wide, char *s, ...)
+static void formatted_printf(int wide, const char *s, ...) PRINTF_ATTR(2, 3);
+static void formatted_printf(int wide, const char *s, ...)
 {
     va_list args;
     int i;
@@ -659,7 +659,7 @@
     }
 }
 
-static char *GameDescription(GameMode_t mode, GameMission_t mission)
+static const char *GameDescription(GameMode_t mode, GameMission_t mission)
 {
     switch (mission)
     {
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -325,7 +325,7 @@
     }
 }
 
-net_addr_t *NET_SDL_ResolveAddress(char *address)
+net_addr_t *NET_SDL_ResolveAddress(const char *address)
 {
     IPaddress ip;
     char *addr_hostname;
@@ -335,25 +335,21 @@
 
     colon = strchr(address, ':');
 
+    addr_hostname = M_StringDuplicate(address);
     if (colon != NULL)
     {
-	addr_hostname = M_StringDuplicate(address);
 	addr_hostname[colon - address] = '\0';
 	addr_port = atoi(colon + 1);
     }
     else
     {
-	addr_hostname = address;
 	addr_port = port;
     }
     
     result = SDLNet_ResolveHost(&ip, addr_hostname, addr_port);
 
-    if (addr_hostname != address)
-    {
-	free(addr_hostname);
-    }
-    
+    free(addr_hostname);
+
     if (result)
     {
         // unable to resolve
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -186,7 +186,8 @@
 
 // Send a message to be displayed on a client's console
 
-static void NET_SV_SendConsoleMessage(net_client_t *client, char *s, ...)
+static void NET_SV_SendConsoleMessage(net_client_t *client, const char *s, ...) PRINTF_ATTR(2, 3);
+static void NET_SV_SendConsoleMessage(net_client_t *client, const char *s, ...)
 {
     char buf[1024];
     va_list args;
@@ -204,7 +205,8 @@
 
 // Send a message to all clients
 
-static void NET_SV_BroadcastMessage(char *s, ...)
+static void NET_SV_BroadcastMessage(const char *s, ...) PRINTF_ATTR(1, 2);
+static void NET_SV_BroadcastMessage(const char *s, ...)
 {
     char buf[1024];
     va_list args;
@@ -218,7 +220,7 @@
     {
         if (ClientConnected(&clients[i]))
         {
-            NET_SV_SendConsoleMessage(&clients[i], buf);
+            NET_SV_SendConsoleMessage(&clients[i], "%s", buf);
         }
     }
 
@@ -544,7 +546,7 @@
 
 // send a rejection packet to a client
 
-static void NET_SV_SendReject(net_addr_t *addr, char *msg)
+static void NET_SV_SendReject(net_addr_t *addr, const char *msg)
 {
     net_packet_t *packet;