From 0e936f973c3dcb7f74691912db3ad85e8805ccf1 Mon Sep 17 00:00:00 2001 From: molivier Date: Thu, 3 Feb 2005 12:17:10 +0000 Subject: [PATCH] Replaced snprintf and vnsprintf calls by dpsnprintf and dpvsnprintf calls, to ensure coherence among the various platforms (the Win32 versions of those functions aren't C99 compatible). dp(v)snprintf functions return -1 when the buffer is too small to contain all the data, and insure null termination. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4991 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 2 +- common.c | 43 ++++++++++++++++++++++++++++++++++++++++++- common.h | 14 ++++++++++++-- console.c | 8 ++++---- fs.c | 37 +++++++++++++++++++++---------------- host.c | 8 ++++---- host_cmd.c | 4 ++-- keys.c | 4 ++-- model_brush.c | 2 +- netconn.c | 14 +++++++------- pr_edict.c | 46 +++++++++++++++++++++++----------------------- prvm_edict.c | 12 ++++++------ r_shadow.c | 2 +- r_sky.c | 8 ++++---- sbar.c | 2 +- snd_mem.c | 8 ++++---- sv_main.c | 6 +++--- sys_linux.c | 2 +- sys_sdl.c | 2 +- sys_shared.c | 2 +- sys_win.c | 2 +- 21 files changed, 142 insertions(+), 86 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index a0af3961..271d29af 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -1410,7 +1410,7 @@ void CL_ParseServerMessage(void) i &= 31; while(count > 0) { - snprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]); + dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]); strlcat (description, temp, sizeof (description)); count--; i++; diff --git a/common.c b/common.c index 63d6a2d9..09acf582 100644 --- a/common.c +++ b/common.c @@ -1067,13 +1067,54 @@ char *va(const char *format, ...) s = string[stringindex]; stringindex = (stringindex + 1) & 7; va_start (argptr, format); - vsnprintf (s, sizeof (string[0]), format,argptr); + dpvsnprintf (s, sizeof (string[0]), format,argptr); va_end (argptr); return s; } +//====================================== + +// snprintf and vsnprintf are NOT portable. Use their DP counterparts instead + +#undef snprintf +#undef vsnprintf + +#ifdef WIN32 +# define snprintf _snprintf +# define vsnprintf _vsnprintf +#endif + + +int dpsnprintf (char *buffer, size_t buffersize, const char *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = dpvsnprintf (buffer, buffersize, format, args); + va_end (args); + + return result; +} + + +int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list args) +{ + int result; + + result = vsnprintf (buffer, buffersize, format, args); + if (result < 0 || (size_t)result >= buffersize) + { + buffer[buffersize - 1] = '\0'; + return -1; + } + + return result; +} + + //====================================== void COM_ToLowerString (const char *in, char *out, size_t size_out) diff --git a/common.h b/common.h index 6ce65f46..891f6783 100644 --- a/common.h +++ b/common.h @@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // MSVC has a different name for several standard functions #ifdef WIN32 -# define snprintf _snprintf -# define vsnprintf _vsnprintf # define strcasecmp stricmp # define strncasecmp strnicmp #endif @@ -182,6 +180,18 @@ char *va(const char *format, ...); // does a varargs printf into a temp buffer +// snprintf and vsnprintf are NOT portable. Use their DP counterparts instead +#define snprintf DO_NOT_USE_SNPRINTF__USE_DPSNPRINTF +#define vsnprintf DO_NOT_USE_VSNPRINTF__USE_DPVSNPRINTF + +// dpsnprintf and dpvsnprintf +// return the number of printed characters, excluding the final '\0' +// or return -1 if the buffer isn't big enough to contain the entire string. +// buffer is ALWAYS null-terminated +extern int dpsnprintf (char *buffer, size_t buffersize, const char *format, ...); +extern int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list args); + + //============================================================================ extern struct cvar_s registered; diff --git a/console.c b/console.c index 018f4908..043dbeb8 100644 --- a/console.c +++ b/console.c @@ -99,9 +99,9 @@ const char* Log_Timestamp (const char *desc) strftime (timestring, sizeof (timestring), "%a %b %d %H:%M:%S %Y", crt_tm); if (desc != NULL) - snprintf (timestamp, sizeof (timestamp), "====== %s (%s) ======\n", desc, timestring); + dpsnprintf (timestamp, sizeof (timestamp), "====== %s (%s) ======\n", desc, timestring); else - snprintf (timestamp, sizeof (timestamp), "====== %s ======\n", timestring); + dpsnprintf (timestamp, sizeof (timestamp), "====== %s ======\n", timestring); return timestamp; } @@ -637,7 +637,7 @@ void Con_Printf(const char *fmt, ...) char msg[MAXPRINTMSG]; va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); Con_Print(msg); @@ -673,7 +673,7 @@ void Con_DPrintf(const char *fmt, ...) return; // don't confuse non-developers with techie stuff... va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); Con_Print(msg); diff --git a/fs.c b/fs.c index c6742d39..9ad57055 100644 --- a/fs.c +++ b/fs.c @@ -803,7 +803,7 @@ void FS_AddGameDirectory (const char *dir) { if (matchpattern(current->text, "*.pak", true)) { - snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); + dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); pak = FS_LoadPackPAK (pakfile); if (pak) { @@ -822,7 +822,7 @@ void FS_AddGameDirectory (const char *dir) { if (matchpattern(current->text, "*.pk3", true)) { - snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); + dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); pak = FS_LoadPackPK3 (pakfile); if (pak) { @@ -1260,7 +1260,7 @@ static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet) else { char netpath[MAX_OSPATH]; - snprintf(netpath, sizeof(netpath), "%s/%s", search->filename, name); + dpsnprintf(netpath, sizeof(netpath), "%s/%s", search->filename, name); if (FS_SysFileExists (netpath)) { if (!quiet) @@ -1309,7 +1309,7 @@ qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet) if (pack_ind < 0) { char path [MAX_OSPATH]; - snprintf (path, sizeof (path), "%s/%s", search->filename, filename); + dpsnprintf (path, sizeof (path), "%s/%s", search->filename, filename); return FS_SysOpen (path, "rb"); } @@ -1349,7 +1349,7 @@ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet) char real_path [MAX_OSPATH]; // Open the file on disk directly - snprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); + dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); // Create directories up to the file FS_CreatePath (real_path); @@ -1604,19 +1604,24 @@ Print a string into a file int FS_VPrintf (qfile_t* file, const char* format, va_list ap) { int len; - char tempstring [1024]; + size_t buff_size; + char *tempbuff = NULL; - len = vsnprintf (tempstring, sizeof(tempstring), format, ap); - if (len >= sizeof (tempstring)) + buff_size = 1024; + tempbuff = Mem_Alloc (tempmempool, buff_size); + len = dpvsnprintf (tempbuff, buff_size, format, ap); + while (len < 0) { - char *temp = Mem_Alloc (tempmempool, len + 1); - len = vsnprintf (temp, len + 1, format, ap); - len = write (file->handle, temp, len); - Mem_Free (temp); - return len; + Mem_Free (tempbuff); + buff_size *= 2; + tempbuff = Mem_Alloc (tempmempool, buff_size); + len = dpvsnprintf (tempbuff, buff_size, format, ap); } - return write (file->handle, tempstring, len); + len = write (file->handle, tempbuff, len); + Mem_Free (tempbuff); + + return len; } @@ -2019,12 +2024,12 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) else { // get a directory listing and look at each name - snprintf(netpath, sizeof (netpath), "%s/%s", searchpath->filename, basepath); + dpsnprintf(netpath, sizeof (netpath), "%s/%s", searchpath->filename, basepath); if ((dir = listdirectory(netpath))) { for (dirfile = dir;dirfile;dirfile = dirfile->next) { - snprintf(temp, sizeof(temp), "%s/%s", basepath, dirfile->text); + dpsnprintf(temp, sizeof(temp), "%s/%s", basepath, dirfile->text); if (matchpattern(temp, (char *)pattern, true)) { for (listtemp = liststart;listtemp;listtemp = listtemp->next) diff --git a/host.c b/host.c index f04472d4..833fce9e 100644 --- a/host.c +++ b/host.c @@ -112,7 +112,7 @@ void Host_Error (const char *error, ...) va_list argptr; va_start (argptr,error); - vsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr); + dpvsnprintf (hosterrorstring1,sizeof(hosterrorstring1),error,argptr); va_end (argptr); Con_Printf("Host_Error: %s\n", hosterrorstring1); @@ -323,7 +323,7 @@ void SV_ClientPrintf(const char *fmt, ...) char msg[4096]; va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); SV_ClientPrint(msg); @@ -367,7 +367,7 @@ void SV_BroadcastPrintf(const char *fmt, ...) char msg[4096]; va_start(argptr,fmt); - vsnprintf(msg,sizeof(msg),fmt,argptr); + dpvsnprintf(msg,sizeof(msg),fmt,argptr); va_end(argptr); SV_BroadcastPrint(msg); @@ -386,7 +386,7 @@ void Host_ClientCommands(const char *fmt, ...) char string[1024]; va_start(argptr,fmt); - vsnprintf(string, sizeof(string), fmt, argptr); + dpvsnprintf(string, sizeof(string), fmt, argptr); va_end(argptr); MSG_WriteByte(&host_client->message, svc_stufftext); diff --git a/host_cmd.c b/host_cmd.c index 995e61bc..2efcdd05 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -919,9 +919,9 @@ void Host_Say(qboolean teamonly) p1++; } if (!fromServer) - snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1); + dpsnprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1); else - snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1); + dpsnprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1); p2 = text + strlen(text); while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted))) { diff --git a/keys.c b/keys.c index 37f33aff..c3c1b9cd 100644 --- a/keys.c +++ b/keys.c @@ -947,7 +947,7 @@ Key_Event (int key, char ascii, qboolean down) kb = keybindings[key_bmap2][key]; if (kb && kb[0] == '+') { - snprintf (cmd, sizeof(cmd), "-%s %i\n", kb + 1, key); + dpsnprintf (cmd, sizeof(cmd), "-%s %i\n", kb + 1, key); Cbuf_AddText (cmd); } return; @@ -972,7 +972,7 @@ Key_Event (int key, char ascii, qboolean down) kb = keybindings[key_bmap2][key]; if (kb) { if (kb[0] == '+') { // button commands add keynum as a parm - snprintf (cmd, sizeof(cmd), "%s %i\n", kb, key); + dpsnprintf (cmd, sizeof(cmd), "%s %i\n", kb, key); Cbuf_AddText (cmd); } else { Cbuf_AddText (kb); diff --git a/model_brush.c b/model_brush.c index 9be6bb45..3eab23d0 100644 --- a/model_brush.c +++ b/model_brush.c @@ -3978,7 +3978,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l) if ((flags & Q3SURFACEPARM_SKY) && sky[0]) { // quake3 seems to append a _ to the skybox name, so this must do so as well - snprintf(loadmodel->brush.skybox, sizeof(loadmodel->brush.skybox), "%s_", sky); + dpsnprintf(loadmodel->brush.skybox, sizeof(loadmodel->brush.skybox), "%s_", sky); } } } diff --git a/netconn.c b/netconn.c index 4d696769..53446bac 100755 --- a/netconn.c +++ b/netconn.c @@ -299,7 +299,7 @@ static void _HostCache_Test(void) for( i = 0 ; i < 1024 ; i++ ) { memset( &hostcache_cache[hostcache_cachecount], 0, sizeof( hostcache_t ) ); hostcache_cache[hostcache_cachecount].info.ping = rand() % 450 + 250; - snprintf( hostcache_cache[hostcache_cachecount].info.name, 128, "Black's HostCache Test %i", i ); + dpsnprintf( hostcache_cache[hostcache_cachecount].info.name, 128, "Black's HostCache Test %i", i ); hostcache_cache[hostcache_cachecount].finished = true; sprintf( hostcache_cache[hostcache_cachecount].line1, "%i %s", hostcache_cache[hostcache_cachecount].info.ping, hostcache_cache[hostcache_cachecount].info.name ); _HostCache_Insert( &hostcache_cache[hostcache_cachecount] ); @@ -942,8 +942,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, // legacy/old stuff move it to the menu ASAP // build description strings for the things users care about - snprintf(hostcache_cache[n].line1, sizeof(hostcache_cache[n].line1), "%5d%c%3u/%3u %-65.65s", (int)pingtime, info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name); - snprintf(hostcache_cache[n].line2, sizeof(hostcache_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map); + dpsnprintf(hostcache_cache[n].line1, sizeof(hostcache_cache[n].line1), "%5d%c%3u/%3u %-65.65s", (int)pingtime, info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name); + dpsnprintf(hostcache_cache[n].line2, sizeof(hostcache_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map); // if ping is especially high, display it as such if (pingtime >= 300) { @@ -982,7 +982,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, { serverquerycount++; - snprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]); + dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]); if (developer.integer) Con_Printf("Requesting info from server %s\n", ipstring); // ignore the rest of the message if the hostcache is full @@ -1318,13 +1318,13 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, for (i = 0, n = 0;i < svs.maxclients;i++) if (svs.clients[i].active) n++; - responselength = snprintf(response, sizeof(response), "\377\377\377\377infoResponse\x0A" + responselength = dpsnprintf(response, sizeof(response), "\377\377\377\377infoResponse\x0A" "\\gamename\\%s\\modname\\%s\\sv_maxclients\\%d" "\\clients\\%d\\mapname\\%s\\hostname\\%s\\protocol\\%d%s%s", gamename, com_modname, svs.maxclients, n, sv.name, hostname.string, NET_PROTOCOL_VERSION, challenge ? "\\challenge\\" : "", challenge ? challenge : ""); // does it fit in the buffer? - if (responselength < (int)sizeof(response)) + if (responselength >= 0) { if (developer.integer) Con_Printf("Sending reply to master %s - %s\n", addressstring2, response); @@ -1613,7 +1613,7 @@ void NetConn_QueryMasters(void) #endif // build the getservers - snprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); + dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); // search internet for (masternum = 0;sv_masters[masternum].name;masternum++) diff --git a/pr_edict.c b/pr_edict.c index 96e73fbe..5e3f6a4f 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -439,34 +439,34 @@ char *PR_ValueString (etype_t type, eval_t *val) //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); n = val->edict; if (n < 0 || n >= MAX_EDICTS) - snprintf (line, sizeof (line), "entity %i (invalid!)", n); + dpsnprintf (line, sizeof (line), "entity %i (invalid!)", n); else - snprintf (line, sizeof (line), "entity %i", n); + dpsnprintf (line, sizeof (line), "entity %i", n); break; case ev_function: f = pr_functions + val->function; - snprintf (line, sizeof (line), "%s()", PR_GetString(f->s_name)); + dpsnprintf (line, sizeof (line), "%s()", PR_GetString(f->s_name)); break; case ev_field: def = ED_FieldAtOfs ( val->_int ); - snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - snprintf (line, sizeof (line), "void"); + dpsnprintf (line, sizeof (line), "void"); break; case ev_float: // LordHavoc: changed from %5.1f to %10.4f - snprintf (line, sizeof (line), "%10.4f", val->_float); + dpsnprintf (line, sizeof (line), "%10.4f", val->_float); break; case ev_vector: // LordHavoc: changed from %5.1f to %10.4f - snprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); + dpsnprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); break; case ev_pointer: - snprintf (line, sizeof (line), "pointer"); + dpsnprintf (line, sizeof (line), "pointer"); break; default: - snprintf (line, sizeof (line), "bad type %i", type); + dpsnprintf (line, sizeof (line), "bad type %i", type); break; } @@ -517,7 +517,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) line[i] = '\0'; break; case ev_entity: - snprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); + dpsnprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); break; case ev_function: f = pr_functions + val->function; @@ -525,19 +525,19 @@ char *PR_UglyValueString (etype_t type, eval_t *val) break; case ev_field: def = ED_FieldAtOfs ( val->_int ); - snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - snprintf (line, sizeof (line), "void"); + dpsnprintf (line, sizeof (line), "void"); break; case ev_float: - snprintf (line, sizeof (line), "%f", val->_float); + dpsnprintf (line, sizeof (line), "%f", val->_float); break; case ev_vector: - snprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); + dpsnprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); break; default: - snprintf (line, sizeof (line), "bad type %i", type); + dpsnprintf (line, sizeof (line), "bad type %i", type); break; } @@ -563,11 +563,11 @@ char *PR_GlobalString (int ofs) val = (void *)&pr_globals[ofs]; def = ED_GlobalAtOfs(ofs); if (!def) - snprintf (line, sizeof (line), "%i(?)", ofs); + dpsnprintf (line, sizeof (line), "%i(?)", ofs); else { s = PR_ValueString (def->type, val); - snprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s); + dpsnprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s); } i = strlen(line); @@ -586,9 +586,9 @@ char *PR_GlobalStringNoContents (int ofs) def = ED_GlobalAtOfs(ofs); if (!def) - snprintf (line, sizeof (line), "%i(?)", ofs); + dpsnprintf (line, sizeof (line), "%i(?)", ofs); else - snprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name)); i = strlen(line); for ( ; i<20 ; i++) @@ -625,7 +625,7 @@ void ED_Print(edict_t *ed) } tempstring[0] = 0; - snprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); + dpsnprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); for (i=1 ; inumfielddefs ; i++) { d = &pr_fielddefs[i]; @@ -1108,7 +1108,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) { char temp[32]; strlcpy (temp, com_token, sizeof (temp)); - snprintf (com_token, sizeof (com_token), "0 %s 0", temp); + dpsnprintf (com_token, sizeof (com_token), "0 %s 0", temp); } if (!ED_ParseEpair(ent, key, com_token)) @@ -1579,7 +1579,7 @@ void PR_Fields_f (void) strlcat (tempstring, "pointer ", sizeof (tempstring)); break; default: - snprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL); + dpsnprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL); strlcat (tempstring, tempstring2, sizeof (tempstring)); break; } @@ -1593,7 +1593,7 @@ void PR_Fields_f (void) strcat (tempstring, name); for (j = strlen(name);j < 25;j++) strcat(tempstring, " "); - snprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); + dpsnprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); strlcat (tempstring, tempstring2, sizeof (tempstring)); strlcat (tempstring, "\n", sizeof (tempstring)); if (strlen(tempstring) >= 4096) diff --git a/prvm_edict.c b/prvm_edict.c index 76b364ee..0dceb690 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -467,7 +467,7 @@ char *PRVM_UglyValueString (etype_t type, prvm_eval_t *val) line[i] = '\0'; break; case ev_entity: - snprintf (line, sizeof (line), "%i", PRVM_NUM_FOR_EDICT(PRVM_PROG_TO_EDICT(val->edict))); + dpsnprintf (line, sizeof (line), "%i", PRVM_NUM_FOR_EDICT(PRVM_PROG_TO_EDICT(val->edict))); break; case ev_function: f = pr_functions + val->function; @@ -475,19 +475,19 @@ char *PRVM_UglyValueString (etype_t type, prvm_eval_t *val) break; case ev_field: def = PRVM_ED_FieldAtOfs ( val->_int ); - snprintf (line, sizeof (line), ".%s", PRVM_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), ".%s", PRVM_GetString(def->s_name)); break; case ev_void: - snprintf (line, sizeof (line), "void"); + dpsnprintf (line, sizeof (line), "void"); break; case ev_float: - snprintf (line, sizeof (line), "%f", val->_float); + dpsnprintf (line, sizeof (line), "%f", val->_float); break; case ev_vector: - snprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); + dpsnprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); break; default: - snprintf (line, sizeof (line), "bad type %i", type); + dpsnprintf (line, sizeof (line), "bad type %i", type); break; } diff --git a/r_shadow.c b/r_shadow.c index d12b3c9c..258c3e33 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2951,7 +2951,7 @@ rtexture_t *R_Shadow_LoadCubemap(const char *basename) for (i = 0;i < 6;i++) { // generate an image name based on the base and and suffix - snprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix); + dpsnprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix); // load it if ((image_rgba = loadimagepixels(name, false, cubemapsize, cubemapsize))) { diff --git a/r_sky.c b/r_sky.c index b58ada98..135d2dab 100644 --- a/r_sky.c +++ b/r_sky.c @@ -102,13 +102,13 @@ void R_LoadSkyBox(void) success = 0; for (i=0; i<6; i++) { - if (snprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - if (snprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - if (snprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - if (snprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0))) continue; } } diff --git a/sbar.c b/sbar.c index 24f96340..7512d953 100644 --- a/sbar.c +++ b/sbar.c @@ -847,7 +847,7 @@ void Sbar_ShowFPS(void) framecount++; calc = framerate; } - snprintf(fpsstring, sizeof(fpsstring), "%4i fps", calc); + dpsnprintf(fpsstring, sizeof(fpsstring), "%4i fps", calc); } if (showtime.integer) strlcpy(timestring, Sys_TimeString(showtime_format.string), sizeof(timestring)); diff --git a/snd_mem.c b/snd_mem.c index 7422a01b..07c32eb1 100644 --- a/snd_mem.c +++ b/snd_mem.c @@ -174,8 +174,8 @@ qboolean S_LoadSound (sfx_t *s, qboolean complain) // LordHavoc: if the sound filename does not begin with sound/, try adding it if (strncasecmp(s->name, "sound/", 6)) { - len = snprintf (namebuffer, sizeof(namebuffer), "sound/%s", s->name); - if (len >= sizeof (namebuffer)) + len = dpsnprintf (namebuffer, sizeof(namebuffer), "sound/%s", s->name); + if (len < 0) { // name too long Con_Printf("S_LoadSound: name \"%s\" is too long\n", s->name); @@ -190,8 +190,8 @@ qboolean S_LoadSound (sfx_t *s, qboolean complain) } // LordHavoc: then try without the added sound/ as wav and ogg - len = snprintf (namebuffer, sizeof(namebuffer), "%s", s->name); - if (len >= sizeof (namebuffer)) + len = dpsnprintf (namebuffer, sizeof(namebuffer), "%s", s->name); + if (len < 0) { // name too long Con_Printf("S_LoadSound: name \"%s\" is too long\n", s->name); diff --git a/sv_main.c b/sv_main.c index 75cf3703..d85aba28 100644 --- a/sv_main.c +++ b/sv_main.c @@ -314,7 +314,7 @@ void SV_SendServerinfo (client_t *client) client->entitydatabase5 = EntityFrame5_AllocDatabase(sv_clients_mempool); MSG_WriteByte (&client->message, svc_print); - snprintf (message, sizeof (message), "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc); + dpsnprintf (message, sizeof (message), "\002\nServer: %s build %s (progs %i crc)", gamename, buildstring, pr_crc); MSG_WriteString (&client->message,message); MSG_WriteByte (&client->message, svc_serverinfo); @@ -1610,7 +1610,7 @@ void SV_SpawnServer (const char *server) if (cls.state != ca_dedicated) SCR_BeginLoadingPlaque(); - snprintf (modelname, sizeof(modelname), "maps/%s.bsp", server); + dpsnprintf (modelname, sizeof(modelname), "maps/%s.bsp", server); worldmodel = Mod_ForName(modelname, false, true, true); if (!worldmodel || !worldmodel->TraceBox) { @@ -1750,7 +1750,7 @@ void SV_SpawnServer (const char *server) strlcpy(sv.model_precache[1], sv.modelname, sizeof(sv.model_precache[1])); for (i = 1;i < sv.worldmodel->brush.numsubmodels;i++) { - snprintf(sv.model_precache[i+1], sizeof(sv.model_precache[i+1]), "*%i", i); + dpsnprintf(sv.model_precache[i+1], sizeof(sv.model_precache[i+1]), "*%i", i); sv.models[i+1] = Mod_ForName (sv.model_precache[i+1], false, false, false); } diff --git a/sys_linux.c b/sys_linux.c index ea91828f..1666a7f5 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -40,7 +40,7 @@ void Sys_Error (const char *error, ...) #endif va_start (argptr,error); - vsnprintf (string, sizeof (string), error, argptr); + dpvsnprintf (string, sizeof (string), error, argptr); va_end (argptr); fprintf(stderr, "Error: %s\n", string); diff --git a/sys_sdl.c b/sys_sdl.c index 11d4894d..6f165317 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -42,7 +42,7 @@ void Sys_Error (const char *error, ...) #endif va_start (argptr,error); - vsnprintf (string, sizeof (string), error, argptr); + dpvsnprintf (string, sizeof (string), error, argptr); va_end (argptr); fprintf(stderr, "Error: %s\n", string); diff --git a/sys_shared.c b/sys_shared.c index e876daf1..9b4aea62 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -53,7 +53,7 @@ void Sys_Shared_EarlyInit(void) #else os = "Unknown"; #endif - snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); + dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from if (COM_CheckParm("-nostdout")) diff --git a/sys_win.c b/sys_win.c index 36ab6e59..4fa62ee0 100644 --- a/sys_win.c +++ b/sys_win.c @@ -57,7 +57,7 @@ void Sys_Error (const char *error, ...) static int in_sys_error3 = 0; va_start (argptr, error); - vsnprintf (text, sizeof (text), error, argptr); + dpvsnprintf (text, sizeof (text), error, argptr); va_end (argptr); Con_Printf ("Quake Error: %s\n", text); -- 2.39.2