Replace various occurences of "Bstrncpy(buf, src, sz); buf[sz-1]=0;" with Bstrncpyz

git-svn-id: https://svn.eduke32.com/eduke32@2559 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-03-28 19:43:21 +00:00
parent 0ea9feee2d
commit 0e3adea64e
12 changed files with 38 additions and 63 deletions

View file

@ -538,10 +538,7 @@ int32_t app_main(int32_t argc, const char **argv)
}
if (!boardfilename[0])
{
Bstrncpy(boardfilename, argv[i], BMAX_PATH);
boardfilename[BMAX_PATH-1] = 0;
}
Bstrncpyz(boardfilename, argv[i], BMAX_PATH);
}
if (boardfilename[0] == 0)
{
@ -8532,8 +8529,7 @@ int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char
// need to have 4+11+2==17 chars room at the end
// ("^011", max. string length of an int32, "_ ")
Bstrncpy(ournamestart, namestart, sizeof(ournamestart));
ournamestart[sizeof(ournamestart)-1] = 0;
Bstrncpyz(ournamestart, namestart, sizeof(ournamestart));
bflushchars();
while (keystatus[0x1] == 0)
@ -8604,8 +8600,7 @@ int32_t _getnumber256(const char *namestart, int32_t num, int32_t maxnumber, cha
// need to have 11+2==13 chars room at the end
// (max. string length of an int32, "_ ")
Bstrncpy(ournamestart, namestart, sizeof(ournamestart));
ournamestart[sizeof(ournamestart)-1] = 0;
Bstrncpyz(ournamestart, namestart, sizeof(ournamestart));
bflushchars();
while (keystatus[0x1] == 0)
@ -8795,8 +8790,8 @@ const char *getstring_simple(const char *querystr, const char *defaultstr, int32
if (numcompl<3)
{
Bstrncpy(completions[numcompl], cmpstr+len, sizeof(completions[0]));
completions[numcompl][sizeof(completions[0])-1] = 0;
Bstrncpyz(completions[numcompl], cmpstr+len, sizeof(completions[0]));
for (k=0; completions[numcompl][k]; k++)
completions[numcompl][k] = Btolower(completions[numcompl][k]);
numcompl++;
@ -9411,8 +9406,7 @@ int32_t loadnames(const char *namesfile, int8_t root)
int8_t quotes=0, anglebrackets=0;
BFILE *fp;
Bstrncpy(buffer, namesfile, sizeof(buffer));
buffer[sizeof(buffer)-1] = 0;
Bstrncpyz(buffer, namesfile, sizeof(buffer));
fp = fopenfrompath(buffer,"r");
if (!fp)
@ -9516,8 +9510,7 @@ int32_t loadnames(const char *namesfile, int8_t root)
if (Bstrlen(name) > 24)
initprintf("Warning: Name \"%s\" longer than 24 characters (line %d). Truncating.\n", name, line-1);
Bstrncpy(names[num], name, 24);
names[num][24] = 0;
Bstrncpyz(names[num], name, 25);
syms++;

View file

@ -325,8 +325,8 @@ int32_t loadsetup(const char *fn)
// copy script history into OSD history
for (i=0; i<min(scripthistend, OSD_HISTORYDEPTH); i++)
{
Bstrncpy(osdhistorybuf[i], scripthist[scripthistend-1-i], OSD_EDITLENGTH+1);
osdhistorybuf[i][OSD_EDITLENGTH] = 0;
Bstrncpyz(osdhistorybuf[i], scripthist[scripthistend-1-i], OSD_EDITLENGTH+1);
osdhistorysize++;
osdhistorytotal++;
}

View file

@ -726,7 +726,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
{
skinfile = sk->fn;
texidx = &sk->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
strncpy(fn,skinfile,BMAX_PATH);
Bstrncpyz(fn, skinfile, BMAX_PATH);
//OSD_Printf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile);
break;
}
@ -746,7 +746,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
{
skinfile = skzero->fn;
texidx = &skzero->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
strncpy(fn,skinfile,BMAX_PATH);
Bstrncpyz(fn, skinfile, BMAX_PATH);
//OSD_Printf("Using def skin 0,0 as fallback, pal=%d\n", pal);
}
else
@ -754,7 +754,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
if ((unsigned)number >= (unsigned)m->numskins) number = 0;
skinfile = m->skinfn + number*64;
texidx = &m->texid[ number * (HICEFFECTMASK+1) + (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
strncpy(fn,m->basepath,BMAX_PATH);
Bstrncpyz(fn, m->basepath, BMAX_PATH);
if ((Bstrlen(fn) + Bstrlen(skinfile)) < BMAX_PATH)
strcat(fn,skinfile);
//OSD_Printf("Using MD2/MD3 skin (%d) %s, pal=%d\n",number,skinfile,pal);
@ -3383,8 +3383,7 @@ mdmodel_t *mdload(const char *filnam)
// smuggle the file name into the model struct.
// head.nam is unused as far as I can tell
Bstrncpy(vm3->head.nam, filnam, sizeof(vm3->head.nam));
vm3->head.nam[sizeof(vm3->head.nam)-1] = 0;
Bstrncpyz(vm3->head.nam, filnam, sizeof(vm3->head.nam));
md3postload_common(vm3);

View file

@ -1294,7 +1294,7 @@ static int32_t LoadCacheOffsets(void)
}
else
{
Bstrncpy(curcacheindex->name, fname, BMAX_PATH);
Bstrncpyz(curcacheindex->name, fname, BMAX_PATH);
curcacheindex->offset = foffset;
curcacheindex->len = fsize;
curcacheindex->next = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex));

View file

@ -155,10 +155,7 @@ int32_t wm_ynbox(char *name, char *fmt, ...)
void wm_setapptitle(char *name)
{
if (name)
{
Bstrncpy(apptitle, name, sizeof(apptitle)-1);
apptitle[ sizeof(apptitle)-1 ] = 0;
}
Bstrncpyz(apptitle, name, sizeof(apptitle));
SDL_WM_SetCaption(apptitle, NULL);
@ -493,13 +490,13 @@ int32_t initinput(void)
for (i=0; i<SDLK_LAST; i++)
{
if (!keytranslation[i]) continue;
Bstrncpy((char *)key_names[ keytranslation[i] ], SDL_GetKeyName(i), sizeof(key_names[i])-1);
Bstrncpyz(key_names[ keytranslation[i] ], SDL_GetKeyName(i), sizeof(key_names[i]));
}
#else
for (i=0; i<SDL_NUM_SCANCODES; i++)
{
if (!keytranslation[i]) continue;
Bstrncpy((char *)key_names[ keytranslation[i] ], SDL_GetKeyName(SDL_SCANCODE_TO_KEYCODE(i)), sizeof(key_names[i])-1);
Bstrncpyz(key_names[ keytranslation[i] ], SDL_GetKeyName(SDL_SCANCODE_TO_KEYCODE(i)), sizeof(key_names[i]));
}
#endif

View file

@ -251,8 +251,7 @@ void G_PlayAnim(const char *fn,char t)
int32_t running = 1;
int32_t animidx, framenum=0, soundidx=0, numtotalsounds=0; // custom anim sounds
Bstrncpy(vpxfn, fn, BMAX_PATH);
vpxfn[BMAX_PATH-1] = 0;
Bstrncpyz(vpxfn, fn, BMAX_PATH);
dot = Bstrrchr(vpxfn, '.');
if (!dot || (dot-vpxfn)+4 >= BMAX_PATH)

View file

@ -338,8 +338,7 @@ static void drawgradient(void)
static void message_common1(const char *tmpstr)
{
Bstrncpy(getmessage,tmpstr,sizeof(getmessage));
getmessage[sizeof(getmessage)-1] = 0;
Bstrncpyz(getmessage, tmpstr, sizeof(getmessage));
getmessageleng = Bstrlen(getmessage);
getmessagetimeoff = totalclock + 120*2 + getmessageleng*(120/30);
@ -964,8 +963,7 @@ int32_t taglab_save(const char *mapname)
if (g_taglab.numlabels==0)
return 1;
Bstrncpy(buf, mapname, BMAX_PATH);
buf[BMAX_PATH-1] = 0;
Bstrncpyz(buf, mapname, BMAX_PATH);
len = Bstrlen(buf);
//
@ -1009,8 +1007,7 @@ int32_t taglab_add(const char *label, int16_t tag)
if (tag < 0)
return -1;
Bstrncpy(buf, label, sizeof(buf));
buf[sizeof(buf)-1] = 0;
Bstrncpyz(buf, label, sizeof(buf));
// upcase the tag for storage and comparison
tstrtoupper(buf);
@ -1063,8 +1060,7 @@ int32_t taglab_gettag(const char *label)
{
char buf[TAGLAB_MAX];
Bstrncpy(buf, label, TAGLAB_MAX);
buf[sizeof(buf)-1] = 0;
Bstrncpyz(buf, label, TAGLAB_MAX);
// need to upcase since hash_findcase doesn't work as expected:
// getting the code is still (necessarily) case-sensitive...
@ -3586,8 +3582,7 @@ static int32_t m32gettile(int32_t idInitialTile)
{
int32_t i, i0, slen=Bstrlen(searchstr)-1;
Bstrncpy(laststr, searchstr, 25);
laststr[24] = 0;
Bstrncpyz(laststr, searchstr, 25);
i0 = localartlookup[iTile];
Bmemcpy(buf[0], laststr, 25);
@ -8428,11 +8423,10 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
{
#ifdef USE_OPENGL
Bsnprintf(tempbuf,sizeof(tempbuf),"%s/%s",argv[i+1],TEXCACHEFILE);
Bstrncpy(TEXCACHEFILE,tempbuf, sizeof(TEXCACHEFILE));
TEXCACHEFILE[sizeof(TEXCACHEFILE)-1] = 0;
Bstrncpyz(TEXCACHEFILE, tempbuf, sizeof(TEXCACHEFILE));
#endif
Bstrncpy(g_modDir, argv[i+1], sizeof(g_modDir));
g_modDir[sizeof(g_modDir)-1] = 0;
Bstrncpyz(g_modDir, argv[i+1], sizeof(g_modDir));
G_AddPath(argv[i+1]);
COPYARG(i);
@ -9247,8 +9241,7 @@ static int32_t osdcmd_endisableevent(const osdfuncparm_t *parm)
else if (!Bstrncmp(parm->parms[i], "EVENT_", 6))
{
j = hash_find(&h_labels, parm->parms[i]);
Bstrncpy(buf2, parm->parms[i], sizeof(buf2));
buf2[sizeof(buf2)-1] = '\0';
Bstrncpyz(buf2, parm->parms[i], sizeof(buf2));
}
else
{
@ -12654,8 +12647,7 @@ void registerMenuFunction(const char *funcname, int32_t stateidx)
// register menu entry named FUNCNAME to call the M32script
// state with index STATEIDX
Bstrncpy(fn, funcname, sizeof(fn));
fn[sizeof(fn)-1] = 0;
Bstrncpyz(fn, funcname, sizeof(fn));
for (i=8; i<numMenuFunctions; i++)
{

View file

@ -426,7 +426,8 @@ void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scan
Bstrcat(tempbuf,buf);
}
}
Bstrncpy(KeyBindings[ii[k]].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
Bstrncpyz(KeyBindings[ii[k]].cmd, tempbuf, MAXBINDSTRINGLENGTH);
i = Bstrlen(KeyBindings[ii[k]].cmd);
if (i)
@ -656,8 +657,7 @@ int32_t CONFIG_ReadSetup(void)
while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10)
tempbuf[Bstrlen(tempbuf)-1] = '\0';
Bstrncpy(szPlayerName,tempbuf,sizeof(szPlayerName)-1);
szPlayerName[sizeof(szPlayerName)-1] = '\0';
Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
if (g_rtsNamePtr == NULL)
SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);

View file

@ -8665,7 +8665,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
{
if (argc > i+1)
{
Bstrncpy(g_netPassword, (char *)argv[i+1], sizeof(g_netPassword)-1);
Bstrncpyz(g_netPassword, argv[i+1], sizeof(g_netPassword));
i++;
}
i++;
@ -9454,8 +9454,7 @@ static void G_Startup(void)
while (Bstrlen(OSD_StripColors(tempbuf,tempbuf)) > 10)
tempbuf[Bstrlen(tempbuf)-1] = '\0';
Bstrncpy(szPlayerName,tempbuf,sizeof(szPlayerName)-1);
szPlayerName[sizeof(szPlayerName)-1] = '\0';
Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
}
if (CommandMap)

View file

@ -2388,8 +2388,7 @@ badindex:
int32_t sign = (tw==CON_GETNUMBERFROMUSER) ? Gv_GetVarX(*insptr++) : (max<=0);
char buf[64]; // buffers in getnumber* are 80 bytes long
Bstrncpy(buf, quotetext, sizeof(buf));
buf[sizeof(buf)-1]='\0';
Bstrncpyz(buf, quotetext, sizeof(buf));
if (max==0)
max = INT32_MAX;

View file

@ -1114,8 +1114,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t
if (spot >= 0)
{
// savegame
Bstrncpy(h.savename, ud.savegame[spot], sizeof(h.savename));
h.savename[sizeof(h.savename)-1] = 0;
Bstrncpyz(h.savename, ud.savegame[spot], sizeof(h.savename));
}
else
{
@ -1124,7 +1123,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t
const time_t t=time(NULL);
struct tm *st;
Bstrncpy(h.savename, "Eduke32 demo", sizeof(h.savename));
Bstrncpyz(h.savename, "Eduke32 demo", sizeof(h.savename));
if (t>=0 && (st = localtime(&t)))
Bsprintf(h.savename, "Edemo32 %04d%02d%02d", st->tm_year+1900, st->tm_mon+1, st->tm_mday);
}

View file

@ -70,10 +70,8 @@ static Mix_Music *music_musicchunk = NULL;
static void setErrorMessage(const char *msg)
{
Bstrncpy(errorMessage, msg, sizeof(errorMessage));
// strncpy() doesn't add the null char if there isn't room...
errorMessage[sizeof(errorMessage) - 1] = '\0';
} // setErrorMessage
Bstrncpyz(errorMessage, msg, sizeof(errorMessage));
}
// The music functions...