From 45955b16f26ebdbcc9f2b1397706800664b9417b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 12 Jan 2002 03:23:32 +0000 Subject: [PATCH] printf arg checking. unfortunatly, due to a bug in gcc, no checking on the function pointers, but all the other printf style functions are checked. Also, use gcc_attr.h from qf so quake2 will compile with lame compilers --- client/cl_main.c | 4 ++-- client/cl_parse.c | 2 +- client/cl_view.c | 4 ++-- client/ref.h | 3 +++ client/snd_dma.c | 2 +- ctf/g_save.c | 4 ++-- ctf/game.h | 9 +++++++++ ctf/q_shared.h | 9 +++++---- game/g_save.c | 4 ++-- game/game.h | 9 +++++++++ game/q_shared.h | 9 +++++---- linux/rw_x11.c | 2 +- qcommon/qcommon.h | 13 +++++++------ qcommon/quakeio.h | 1 + server/server.h | 9 +++++---- server/sv_main.c | 2 +- 16 files changed, 56 insertions(+), 30 deletions(-) diff --git a/client/cl_main.c b/client/cl_main.c index 3cef00d..369cc77 100644 --- a/client/cl_main.c +++ b/client/cl_main.c @@ -332,7 +332,7 @@ void CL_Setenv_f( void ) } else { - Com_Printf( "%s undefined\n", Cmd_Argv(1), env ); + Com_Printf( "%s undefined\n", Cmd_Argv(1)); } } } @@ -504,7 +504,7 @@ void CL_Connect_f (void) if (Com_ServerState ()) { // if running a local server, kill it and reissue - SV_Shutdown (va("Server quit\n", msg), false); + SV_Shutdown ("Server quit\n", false); } else { diff --git a/client/cl_parse.c b/client/cl_parse.c index f6f5552..2662474 100644 --- a/client/cl_parse.c +++ b/client/cl_parse.c @@ -458,7 +458,7 @@ void CL_LoadClientinfo (clientinfo_t *ci, char *s) // it, so default to grunt if (!ci->skin) { // see if the skin exists for the male model - Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/grunt.pcx", model_name, skin_name); + Com_sprintf (skin_filename, sizeof(skin_filename), "players/%s/grunt.pcx", model_name); ci->skin = re.RegisterSkin (skin_filename); } diff --git a/client/cl_view.c b/client/cl_view.c index 4b75809..381ba8d 100644 --- a/client/cl_view.c +++ b/client/cl_view.c @@ -310,7 +310,7 @@ void CL_PrepRefresh (void) Com_Printf (" \r"); } - Com_Printf ("images\r", i); + Com_Printf ("images\r"); SCR_UpdateScreen (); for (i=1 ; ivalue; diff --git a/ctf/game.h b/ctf/game.h index d447198..6e77547 100644 --- a/ctf/game.h +++ b/ctf/game.h @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/gcc_attr.h" // game.h -- game dll information visible to server @@ -109,10 +110,17 @@ struct edict_s typedef struct { // special messages +#if 0 + void (*bprintf) (int printlevel, char *fmt, ...) __attribute__((format(printf,2,3))); + void (*dprintf) (char *fmt, ...) __attribute__((format(printf,1,2))); + void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...) __attribute__((format(printf,3,4))); + void (*centerprintf) (edict_t *ent, char *fmt, ...) __attribute__((format(printf,2,3))); +#else void (*bprintf) (int printlevel, char *fmt, ...); void (*dprintf) (char *fmt, ...); void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...); void (*centerprintf) (edict_t *ent, char *fmt, ...); +#endif void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs); void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs); @@ -122,6 +130,7 @@ typedef struct // they connect, and changes are sent to all connected clients. void (*configstring) (int num, char *string); + //void (*error) (char *fmt, ...) __attribute__((noreturn, format(printf,1,2))); void (*error) (char *fmt, ...) __attribute__((noreturn)); // the *index functions create configstrings and some internal server state diff --git a/ctf/q_shared.h b/ctf/q_shared.h index a833dbc..3b435cf 100644 --- a/ctf/q_shared.h +++ b/ctf/q_shared.h @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/gcc_attr.h" // q_shared.h -- included first by ALL program modules @@ -218,7 +219,7 @@ void COM_DefaultExtension (char *path, char *extension); char *COM_Parse (char **data_p); // data is an in/out parm, returns a parsed out token -void Com_sprintf (char *dest, int size, char *fmt, ...); +void Com_sprintf (char *dest, int size, char *fmt, ...) __attribute__((format(printf,3,4))); void Com_PageInMemory (byte *buffer, int size); @@ -239,7 +240,7 @@ float BigFloat (float l); float LittleFloat (float l); void Swap_Init (void); -char *va(char *format, ...); +char *va(char *format, ...) __attribute__((format(printf,1,2))); //============================================= @@ -290,8 +291,8 @@ void Sys_FindClose (void); // this is only here so the functions in q_shared.c and q_shwin.c can link -void Sys_Error (char *error, ...) __attribute__((noreturn)); -void Com_Printf (char *msg, ...); +void Sys_Error (char *error, ...) __attribute__((noreturn, format(printf,1,2))); +void Com_Printf (char *msg, ...) __attribute__((format(printf,1,2))); /* diff --git a/game/g_save.c b/game/g_save.c index 2dc553a..c07ccdb 100644 --- a/game/g_save.c +++ b/game/g_save.c @@ -206,9 +206,9 @@ void InitGame (void) // items InitItems (); - Com_sprintf (game.helpmessage1, sizeof(game.helpmessage1), ""); + game.helpmessage1[0] = 0; - Com_sprintf (game.helpmessage2, sizeof(game.helpmessage2), ""); + game.helpmessage2[0] = 0; // initialize all entities for this game game.maxentities = maxentities->value; diff --git a/game/game.h b/game/game.h index 90a305e..7abd44e 100644 --- a/game/game.h +++ b/game/game.h @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/gcc_attr.h" // game.h -- game dll information visible to server @@ -102,10 +103,17 @@ struct edict_s typedef struct { // special messages +#if 0 + void (*bprintf) (int printlevel, char *fmt, ...) __attribute__((format(printf,2,3))); + void (*dprintf) (char *fmt, ...) __attribute__((format(printf,1,2))); + void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...) __attribute__((format(printf,3,4))); + void (*centerprintf) (edict_t *ent, char *fmt, ...) __attribute__((format(printf,2,3))); +#else void (*bprintf) (int printlevel, char *fmt, ...); void (*dprintf) (char *fmt, ...); void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...); void (*centerprintf) (edict_t *ent, char *fmt, ...); +#endif void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs); void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs); @@ -115,6 +123,7 @@ typedef struct // they connect, and changes are sent to all connected clients. void (*configstring) (int num, char *string); + //void (*error) (char *fmt, ...) __attribute__((noreturn, format(printf,1,2))); void (*error) (char *fmt, ...) __attribute__((noreturn)); // the *index functions create configstrings and some internal server state diff --git a/game/q_shared.h b/game/q_shared.h index a833dbc..3b435cf 100644 --- a/game/q_shared.h +++ b/game/q_shared.h @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/gcc_attr.h" // q_shared.h -- included first by ALL program modules @@ -218,7 +219,7 @@ void COM_DefaultExtension (char *path, char *extension); char *COM_Parse (char **data_p); // data is an in/out parm, returns a parsed out token -void Com_sprintf (char *dest, int size, char *fmt, ...); +void Com_sprintf (char *dest, int size, char *fmt, ...) __attribute__((format(printf,3,4))); void Com_PageInMemory (byte *buffer, int size); @@ -239,7 +240,7 @@ float BigFloat (float l); float LittleFloat (float l); void Swap_Init (void); -char *va(char *format, ...); +char *va(char *format, ...) __attribute__((format(printf,1,2))); //============================================= @@ -290,8 +291,8 @@ void Sys_FindClose (void); // this is only here so the functions in q_shared.c and q_shwin.c can link -void Sys_Error (char *error, ...) __attribute__((noreturn)); -void Com_Printf (char *msg, ...); +void Sys_Error (char *error, ...) __attribute__((noreturn, format(printf,1,2))); +void Com_Printf (char *msg, ...) __attribute__((format(printf,1,2))); /* diff --git a/linux/rw_x11.c b/linux/rw_x11.c index fe32710..3689ece 100644 --- a/linux/rw_x11.c +++ b/linux/rw_x11.c @@ -1028,7 +1028,7 @@ static qboolean SWimp_InitGraphics( qboolean fullscreen ) else if (num_visuals == 0) { if (template_mask == VisualIDMask) - Sys_Error("VID: Bad visual id %d\n", template.visualid); + Sys_Error("VID: Bad visual id %ld\n", template.visualid); else Sys_Error("VID: No visuals at depth %d\n", template.depth); } diff --git a/qcommon/qcommon.h b/qcommon/qcommon.h index 6c5a31a..54a9e16 100644 --- a/qcommon/qcommon.h +++ b/qcommon/qcommon.h @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/gcc_attr.h" // qcommon.h -- definitions common between client and server, but not game.dll @@ -607,7 +608,7 @@ void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport); qboolean Netchan_NeedReliable (netchan_t *chan); void Netchan_Transmit (netchan_t *chan, int length, byte *data); void Netchan_OutOfBand (int net_socket, netadr_t adr, int length, byte *data); -void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...); +void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...) __attribute__((format(printf,3,4))); qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg); qboolean Netchan_CanReliable (netchan_t *chan); @@ -736,10 +737,10 @@ MISC void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush)); void Com_EndRedirect (void); -void Com_Printf (char *fmt, ...); -void Com_DPrintf (char *fmt, ...); -void Com_MDPrintf (char *fmt, ...); -void Com_Error (int code, char *fmt, ...) __attribute__((noreturn)); +void Com_Printf (char *fmt, ...) __attribute__((format(printf,1,2))); +void Com_DPrintf (char *fmt, ...) __attribute__((format(printf,1,2))); +void Com_MDPrintf (char *fmt, ...) __attribute__((format(printf,1,2))); +void Com_Error (int code, char *fmt, ...) __attribute__((noreturn, format(printf,2,3))); void Com_Quit (void); int Com_ServerState (void); // this should have just been a cvar... @@ -800,7 +801,7 @@ void *Sys_GetGameAPI (void *parms); char *Sys_ConsoleInput (void); void Sys_ConsoleOutput (char *string); void Sys_SendKeyEvents (void); -void Sys_Error (char *error, ...) __attribute__((noreturn)); +void Sys_Error (char *error, ...) __attribute__((noreturn, format(printf,1,2))); void Sys_Quit (void); char *Sys_GetClipboardData( void ); void Sys_CopyProtect (void); diff --git a/qcommon/quakeio.h b/qcommon/quakeio.h index 0d1a56d..508526b 100644 --- a/qcommon/quakeio.h +++ b/qcommon/quakeio.h @@ -31,6 +31,7 @@ #define __quakeio_h #include +#include "../qcommon/gcc_attr.h" typedef struct QFile_s QFile; diff --git a/server/server.h b/server/server.h index a8d30ca..d31e91b 100644 --- a/server/server.h +++ b/server/server.h @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //define PARANOID // speed sapping error checking +#include "../qcommon/gcc_attr.h" #include "../qcommon/qcommon.h" #include "../game/game.h" @@ -253,9 +254,9 @@ void SV_Multicast (vec3_t origin, multicast_t to); void SV_StartSound (vec3_t origin, edict_t *entity, int channel, int soundindex, float volume, float attenuation, float timeofs); -void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...); -void SV_BroadcastPrintf (int level, char *fmt, ...); -void SV_BroadcastCommand (char *fmt, ...); +void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...) __attribute__((format(printf,3,4))); +void SV_BroadcastPrintf (int level, char *fmt, ...) __attribute__((format(printf,2,3))); +void SV_BroadcastCommand (char *fmt, ...) __attribute__((format(printf,1,2))); // // sv_user.c @@ -277,7 +278,7 @@ void SV_RecordDemoMessage (void); void SV_BuildClientFrame (client_t *client); -void SV_Error (char *error, ...); +void SV_Error (char *error, ...) __attribute__((format(printf,1,2))); // // sv_game.c diff --git a/server/sv_main.c b/server/sv_main.c index 590aa67..1dd3e6f 100644 --- a/server/sv_main.c +++ b/server/sv_main.c @@ -185,7 +185,7 @@ void SVC_Info (void) version = atoi (Cmd_Argv(1)); if (version != PROTOCOL_VERSION) - Com_sprintf (string, sizeof(string), "%s: wrong version\n", hostname->string, sizeof(string)); + Com_sprintf (string, sizeof(string), "%s: wrong version\n", hostname->string); else { count = 0;