Constify various char* vars, parameters, etc. for more -Wwrite-strings cleanness

-Wwrite-strings is useful to detect code where string literals and e.g. alloc'd
strings are used side-by-side, potentially creating dangerous situations, or to
find uses of old, non-constified APIs.  However, enabling it would still flood
the log with too many warnings.  Also, GCC wrongly warns for initializations of
char arrays.

git-svn-id: https://svn.eduke32.com/eduke32@2796 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-07-01 22:11:33 +00:00
parent 8a89c07261
commit bdedbc6f76
25 changed files with 95 additions and 86 deletions

View file

@ -803,8 +803,8 @@ int32_t md_loadmodel(const char *fn);
int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags);
// int32_t md_tilehasmodel(int32_t tilenume, int32_t pal);
extern char *G_DefaultDefFile(void);
extern char *G_DefFile(void);
extern const char *G_DefaultDefFile(void);
extern const char *G_DefFile(void);
extern char *g_defNamePtr;
extern char **g_defModules;

View file

@ -108,7 +108,7 @@ int32_t OSD_GetRowsCur(void);
void OSD_Init(void);
// sets the file to echo output to
void OSD_SetLogFile(char *fn);
void OSD_SetLogFile(const char *fn);
// sets the functions the OSD will call to interrogate the environment
void OSD_SetFunctions(

View file

@ -174,10 +174,10 @@ typedef struct s_prrograminfo {
typedef struct s_prprogrambit {
int32_t bit;
char* vert_def;
char* vert_prog;
char* frag_def;
char* frag_prog;
const char* vert_def;
const char* vert_prog;
const char* frag_def;
const char* frag_prog;
} _prprogrambit;
#include "prlights.h"

View file

@ -774,7 +774,7 @@ void OSD_Init(void)
//
// OSD_SetLogFile() -- Sets the text file where printed text should be echoed
//
void OSD_SetLogFile(char *fn)
void OSD_SetLogFile(const char *fn)
{
if (osdlog)
{

View file

@ -4949,7 +4949,7 @@ static void polymer_compileprogram(int32_t programbits)
{
int32_t i, enabledbits;
GLhandleARB vert, frag, program;
GLcharARB* source[PR_BIT_COUNT * 2];
const GLcharARB* source[PR_BIT_COUNT * 2];
GLcharARB infobuffer[PR_INFO_LOG_BUFFER_SIZE];
GLint linkstatus;
@ -4971,7 +4971,7 @@ static void polymer_compileprogram(int32_t programbits)
i++;
}
bglShaderSourceARB(vert, enabledbits, (const GLcharARB**)source, NULL);
bglShaderSourceARB(vert, enabledbits, source, NULL);
bglCompileShaderARB(vert);

View file

@ -217,7 +217,7 @@ const char oldkeydefaults[NUMGAMEFUNCTIONS*3][MAXGAMEFUNCLEN] =
"Dpad_Aiming", "", "",
};
static char * mousedefaults[] =
static const char * mousedefaults[] =
{
"Fire",
"MedKit",
@ -232,7 +232,7 @@ static char * mousedefaults[] =
};
static char * mouseclickeddefaults[] =
static const char * mouseclickeddefaults[] =
{
"",
"",
@ -247,14 +247,14 @@ static char * mouseclickeddefaults[] =
};
static char * mouseanalogdefaults[] =
static const char * mouseanalogdefaults[] =
{
"analog_turning",
"analog_moving",
};
static char * mousedigitaldefaults[] =
static const char * mousedigitaldefaults[] =
{
"",
"",
@ -263,7 +263,7 @@ static char * mousedigitaldefaults[] =
};
#if defined(GEKKO)
static char * joystickdefaults[] =
static const char * joystickdefaults[] =
{
"Open", // A
"Fire", // B
@ -304,7 +304,7 @@ static char * joystickdefaults[] =
};
static char * joystickclickeddefaults[] =
static const char * joystickclickeddefaults[] =
{
"",
"",
@ -345,7 +345,7 @@ static char * joystickclickeddefaults[] =
};
static char * joystickanalogdefaults[] =
static const char * joystickanalogdefaults[] =
{
"analog_strafing",
"analog_moving",
@ -366,7 +366,7 @@ static char * joystickanalogdefaults[] =
};
static char * joystickdigitaldefaults[] =
static const char * joystickdigitaldefaults[] =
{
"",
"",
@ -386,7 +386,7 @@ static char * joystickdigitaldefaults[] =
"",
};
#else
static char * joystickdefaults[] =
static const char * joystickdefaults[] =
{
"Fire",
"Strafe",
@ -427,7 +427,7 @@ static char * joystickdefaults[] =
};
static char * joystickclickeddefaults[] =
static const char * joystickclickeddefaults[] =
{
"",
"Inventory",
@ -468,7 +468,7 @@ static char * joystickclickeddefaults[] =
};
static char * joystickanalogdefaults[] =
static const char * joystickanalogdefaults[] =
{
"analog_turning",
"analog_moving",
@ -481,7 +481,7 @@ static char * joystickanalogdefaults[] =
};
static char * joystickdigitaldefaults[] =
static const char * joystickdigitaldefaults[] =
{
"",
"",

View file

@ -9617,9 +9617,9 @@ enum
T_INCLUDEDEFAULT,
};
int32_t parsegroupfiles(scriptfile *script);
static int32_t parsegroupfiles(scriptfile *script);
void parsegroupfiles_include(const char *fn, scriptfile *script, char *cmdtokptr)
static void parsegroupfiles_include(const char *fn, scriptfile *script, const char *cmdtokptr)
{
scriptfile *included;
@ -9639,7 +9639,7 @@ void parsegroupfiles_include(const char *fn, scriptfile *script, char *cmdtokptr
}
}
int32_t parsegroupfiles(scriptfile *script)
static int32_t parsegroupfiles(scriptfile *script)
{
int32_t tokn;
char *cmdtokptr;
@ -10074,7 +10074,7 @@ static int32_t loadtilegroups(const char *fn)
/// vvv Parse CON files partially to get sound definitions
static int32_t parseconsounds(scriptfile *script);
static void parseconsounds_include(const char *fn, scriptfile *script, char *cmdtokptr)
static void parseconsounds_include(const char *fn, scriptfile *script, const char *cmdtokptr)
{
scriptfile *included;

View file

@ -16,10 +16,10 @@ int32_t g_gameType = GAMEFLAG_DUKE;
// grp/con/def handling
char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" };
char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" };
char *defaultconfilename = "GAME.CON";
char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPALM.CON", "WW2GI.CON" };
const char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" };
const char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" };
const char *defaultconfilename = "GAME.CON";
const char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPALM.CON", "WW2GI.CON" };
// g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char *g_grpNamePtr = NULL;
@ -49,7 +49,7 @@ void clearScriptNamePtr(void)
// g_scriptNamePtr assumed to be assigned to right after
}
char *G_DefaultGrpFile(void)
const char *G_DefaultGrpFile(void)
{
if (DUKE)
return defaultgamegrp[GAME_DUKE];
@ -63,7 +63,7 @@ char *G_DefaultGrpFile(void)
return defaultgamegrp[0];
}
char *G_DefaultDefFile(void)
const char *G_DefaultDefFile(void)
{
if (DUKE)
return defaultdeffilename[GAME_DUKE];
@ -86,7 +86,7 @@ char *G_DefaultDefFile(void)
return defaultdeffilename[0];
}
char *G_DefaultConFile(void)
const char *G_DefaultConFile(void)
{
if (DUKE && testkopen(defaultgameconfilename[GAME_DUKE],0))
return defaultgameconfilename[GAME_DUKE];
@ -116,21 +116,21 @@ char *G_DefaultConFile(void)
return defaultconfilename;
}
char *G_GrpFile(void)
const char *G_GrpFile(void)
{
if (g_grpNamePtr == NULL)
return G_DefaultGrpFile();
else
return g_grpNamePtr;
}
char *G_DefFile(void)
const char *G_DefFile(void)
{
if (g_defNamePtr == NULL)
return G_DefaultDefFile();
else
return g_defNamePtr;
}
char *G_ConFile(void)
const char *G_ConFile(void)
{
if (g_scriptNamePtr == NULL)
return G_DefaultConFile();

View file

@ -27,19 +27,19 @@ enum Games_t {
GAMECOUNT
};
extern char *defaultgamegrp[GAMECOUNT];
extern char *defaultdeffilename[GAMECOUNT];
extern char *defaultconfilename;
extern char *defaultgameconfilename[GAMECOUNT];
extern const char *defaultgamegrp[GAMECOUNT];
extern const char *defaultdeffilename[GAMECOUNT];
extern const char *defaultconfilename;
extern const char *defaultgameconfilename[GAMECOUNT];
extern char *g_grpNamePtr;
extern char *g_scriptNamePtr;
extern char *G_DefaultGrpFile(void);
extern char *G_GrpFile(void);
extern const char *G_DefaultGrpFile(void);
extern const char *G_GrpFile(void);
extern char *G_DefaultConFile(void);
extern char *G_ConFile(void);
extern const char *G_DefaultConFile(void);
extern const char *G_ConFile(void);
extern void clearGrpNamePtr(void);
extern void clearDefNamePtr(void);

View file

@ -53,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
hashtable_t h_gamefuncs = { NUMGAMEFUNCTIONS<<1, NULL };
int32_t CONFIG_FunctionNameToNum(char *func)
int32_t CONFIG_FunctionNameToNum(const char *func)
{
int32_t i;
@ -95,7 +95,7 @@ char *CONFIG_FunctionNumToName(int32_t func)
*/
int32_t CONFIG_AnalogNameToNum(char *func)
int32_t CONFIG_AnalogNameToNum(const char *func)
{
if (!Bstrcasecmp(func,"analog_turning"))
@ -119,7 +119,7 @@ int32_t CONFIG_AnalogNameToNum(char *func)
}
char *CONFIG_AnalogNumToName(int32_t func)
const char *CONFIG_AnalogNumToName(int32_t func)
{
switch (func)
{

View file

@ -37,10 +37,10 @@ int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm);
void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2);
int32_t CONFIG_FunctionNameToNum(char *func);
int32_t CONFIG_FunctionNameToNum(const char *func);
char *CONFIG_FunctionNumToName(int32_t func);
int32_t CONFIG_AnalogNameToNum(char *func);
char *CONFIG_AnalogNumToName(int32_t func);
int32_t CONFIG_AnalogNameToNum(const char *func);
const char *CONFIG_AnalogNumToName(int32_t func);
void CONFIG_SetDefaults(void);
void CONFIG_ReadKeys(void);

View file

@ -7358,7 +7358,7 @@ FOUNDCHEAT:
case CHEAT_MONSTERS:
{
char *s[] = { "On", "Off" };
const char *s[] = { "On", "Off" };
if (++g_noEnemies == 3)
g_noEnemies = 0;
@ -8046,7 +8046,7 @@ FAKE_F3:
static void G_ShowParameterHelp(void)
{
char *s = "Usage: eduke32 [files] [options]\n"
const char *s = "Usage: eduke32 [files] [options]\n"
"Example: eduke32 -q4 -a -m -tx -map nukeland.map\n\n"
"Files can be *.grp/zip/con/def/rts\n"
"\n"
@ -8096,7 +8096,7 @@ static void G_ShowParameterHelp(void)
static void G_ShowDebugHelp(void)
{
char *s = "Usage: eduke32 [files] [options]\n"
const char *s = "Usage: eduke32 [files] [options]\n"
"\n"
"-a\t\tUse fake player AI (fake multiplayer only)\n"
"-cachesize #\tSets cache size, in Kb\n"
@ -8200,7 +8200,7 @@ static int32_t S_DefineMusic(char *ID,char *name)
static int32_t parsedefinitions_game(scriptfile *script, int32_t preload);
static void parsedefinitions_game_include(const char *fn, scriptfile *script, char *cmdtokptr, const int32_t preload)
static void parsedefinitions_game_include(const char *fn, scriptfile *script, const char *cmdtokptr, const int32_t preload)
{
scriptfile *included = scriptfile_fromfile(fn);
@ -10314,7 +10314,7 @@ CLEAN_DIRECTORY:
if (quitevent) return 4;
{
char *defsfile = G_DefFile();
const char *defsfile = G_DefFile();
if (!loaddefinitionsfile(defsfile))
{
initprintf("Definitions file \"%s\" loaded.\n",defsfile);

View file

@ -81,7 +81,7 @@ extern intptr_t *g_scriptPtr;
typedef struct
{
char *name;
const char *name;
int32_t lId;
int32_t flags;
int32_t maxParm2;

View file

@ -62,7 +62,7 @@ typedef struct
#define MUSIC_LoopSong ( 1 == 1 )
#define MUSIC_PlayOnce ( !MUSIC_LoopSong )
char *MUSIC_ErrorString( int32_t ErrorNumber );
const char *MUSIC_ErrorString( int32_t ErrorNumber );
int32_t MUSIC_Init( int32_t SoundCard, int32_t Address );
int32_t MUSIC_Shutdown( void );
void MUSIC_SetVolume( int32_t volume );

View file

@ -202,7 +202,7 @@ void CONTROL_PrintAxes( void );
#define MAXBOUNDKEYS 256
typedef struct binding {
char *key;
const char *key;
char cmd[MAXBINDSTRINGLENGTH];
char repeat;
char laststate;

View file

@ -45,7 +45,7 @@ static int32_t numpad = 0;
// translation table for taking key names to scancodes and back again
static struct
{
char *key;
const char *key;
kb_scancode sc;
} sctokeylut[] =
{
@ -233,7 +233,7 @@ void KB_ClearKeysDown(void)
//bflushchars();
}
char *KB_ScanCodeToString(kb_scancode scancode)
const char *KB_ScanCodeToString(kb_scancode scancode)
{
uint32_t s;

View file

@ -92,7 +92,7 @@ int32_t KB_KeyWaiting( void ); // Checks if a character is waiting in th
char KB_Getch( void ); // Gets the next keypress
void KB_FlushKeyboardQueue( void ); // Empties the keyboard queue of all waiting characters.
void KB_ClearKeysDown( void ); // Clears all keys down flags.
char * KB_ScanCodeToString( kb_scancode scancode ); // convert scancode into a string
const char * KB_ScanCodeToString( kb_scancode scancode ); // convert scancode into a string
kb_scancode KB_StringToScanCode( char * string ); // convert a string into a scancode
void KB_TurnKeypadOn( void ); // turn the keypad on
void KB_TurnKeypadOff( void ); // turn the keypad off

View file

@ -814,10 +814,11 @@ void SCRIPT_PutString
int32_t scripthandle,
char * sectionname,
char * entryname,
char * string
const char * string
)
{
char *raw,*q,*p;
const char *q;
char *raw,*p;
int32_t len = 3;
if (!string) string = "";

View file

@ -218,7 +218,7 @@ void SCRIPT_PutString
int32_t scripthandle,
char * sectionname,
char * entryname,
char * string
const char * string
);
/*

View file

@ -80,7 +80,10 @@ static int32_t soundbits, soundvoices, soundrate;
#define NUMDOUBLEMBTNS 3 // # of mouse buttons that can be double-clicked (mouse1 - mouse3)
#define NUMSINGLEMBTNS 4 // # of mouse buttons that can only be single-clicked (the rest)
#define NUMMOUSEFUNCTIONS (NUMDOUBLEMBTNS*2+NUMSINGLEMBTNS)
static char *mousebuttonnames[] = { "Mouse1", "Mouse2", "Mouse3", "Mouse4", "Wheel Up", "Wheel Down", "Mouse5", "Mouse6", "Mouse7", "Mouse8"};
static const char *mousebuttonnames[] =
{ "Mouse1", "Mouse2", "Mouse3", "Mouse4", "Wheel Up",
"Wheel Down", "Mouse5", "Mouse6", "Mouse7", "Mouse8"
};
extern int32_t voting;
@ -688,7 +691,7 @@ void M_DisplayMenus(void)
CACHE1D_FIND_REC *dir;
int32_t c,x,i;
int32_t l,m;
char *p = NULL;
const char *p = NULL;
Net_GetPackets();
@ -839,7 +842,7 @@ void M_DisplayMenus(void)
c = (320>>1)-120;
{
int32_t io, ii, yy = 37, d=c+140, enabled;
char *opts[] =
const char *opts[] =
{
"Name",
"-",
@ -1043,23 +1046,24 @@ void M_DisplayMenus(void)
case 1:
{
char *s[] = { "Auto","","","","","","","","","Blue","Red","Green","Gray","Dark gray","Dark green","Brown",
"Dark blue","","","","","Bright red","","Yellow","",""
};
const char *s[] =
{ "Auto","","","","","","","","","Blue","Red","Green","Gray","Dark gray","Dark green","Brown",
"Dark blue","","","","","Bright red","","Yellow","",""
};
mgametext(d-50,yy,s[ud.color],MENUHIGHLIGHT(io),2+8+16);
}
break;
case 2:
{
char *s[] = { "Blue", "Red", "Green", "Gray" };
const char *s[] = { "Blue", "Red", "Green", "Gray" };
mgametext(d-50,yy,s[ud.team],MENUHIGHLIGHT(io),2+8+16);
}
break;
case 3:
{
char *s[] = { "Off", "All weapons", "Bullets only" };
const char *s[] = { "Off", "All weapons", "Bullets only" };
mgametext(d-50,yy,s[ud.config.AutoAim],MENUHIGHLIGHT(io),2+8+16);
}
break;
@ -2686,7 +2690,7 @@ cheat_for_port_credits:
break;
case 7:
{
char *s[] = { "Off", "On", "Compress" };
const char *s[] = { "Off", "On", "Compress" };
enabled = (glusetexcompr && usehightile);
if (enabled && x==io)
{
@ -2818,7 +2822,7 @@ cheat_for_port_credits:
{
int32_t io, ii, yy, d=c+160+40, enabled;
char *opts[] =
const char *opts[] =
{
"Show setup window at start",
"Show crosshair",
@ -2991,7 +2995,7 @@ cheat_for_port_credits:
{
int32_t io, ii, yy, d=c+160+40, enabled;
char *opts[] =
const char *opts[] =
{
"Parental lock",
"-",
@ -3071,7 +3075,7 @@ cheat_for_port_credits:
}
modval(0,2,(int32_t *)&ud.drawweapon,1,probey==io);
{
char *s[] = { "Off", "On", "Icon only" };
const char *s[] = { "Off", "On", "Icon only" };
mgametextpal(d,yy, s[ud.drawweapon], MENUHIGHLIGHT(io), 0);
break;
}
@ -3092,7 +3096,7 @@ cheat_for_port_credits:
}
modval(0,2,(int32_t *)&ud.autovote,1,probey==io);
{
char *s[] = { "Off", "Vote No", "Vote Yes" };
const char *s[] = { "Off", "Vote No", "Vote Yes" };
mgametextpal(d,yy, s[ud.autovote], MENUHIGHLIGHT(io), 0);
break;
}
@ -3965,7 +3969,7 @@ cheat_for_port_credits:
}
else if (function == 2)
{
static char *directions[] =
static const char *directions[] =
{
"Up", "Right", "Down", "Left"
};
@ -4217,7 +4221,7 @@ cheat_for_port_credits:
}
else
{
static char *directions[] =
static const char *directions[] =
{
"Up", "Right", "Down", "Left"
};
@ -4510,7 +4514,7 @@ cheat_for_port_credits:
{
int32_t io, ii, yy, d=c+160+40, enabled, j;
char *opts[] =
const char *opts[] =
{
"Sound",
"Sound volume",

View file

@ -38,7 +38,7 @@ int16_t DynamicTileMap[MAXTILES];
struct dynitem
{
char *str;
const char *str;
int32_t *dynvalptr;
const int16_t staticval;
};

View file

@ -854,7 +854,11 @@ keydef_t ConsoleKeys[]=
{0,0}
};
char *ConsoleButtons[] = { "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup", "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8" };
const char *ConsoleButtons[] =
{
"mouse1", "mouse2", "mouse3", "mouse4", "mwheelup",
"mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8"
};
static int32_t osdcmd_bind(const osdfuncparm_t *parm)
{

View file

@ -38,12 +38,12 @@ extern float r_ambientlight,r_ambientlightrecip;
#pragma pack(push,1)
// key bindings stuff
typedef struct {
char *name;
const char *name;
int32_t id;
} keydef_t;
extern keydef_t ConsoleKeys[];
extern char *ConsoleButtons[];
extern const char *ConsoleButtons[];
#pragma pack(pop)
#endif // __osdcmds_h__

View file

@ -338,7 +338,7 @@ static void G_PrecacheSounds(void)
}
}
static void G_DoLoadScreen(char *statustext, int32_t percent)
static void G_DoLoadScreen(const char *statustext, int32_t percent)
{
int32_t i=0,j;

View file

@ -75,7 +75,7 @@ static void setErrorMessage(const char *msg)
// The music functions...
char *MUSIC_ErrorString(int32_t ErrorNumber)
const char *MUSIC_ErrorString(int32_t ErrorNumber)
{
switch (ErrorNumber)
{