ref: 2a0405f5f4d1c1afc80edb786d36748a6f39fdb8
parent: ca91daeae645d6ec3d2705195e80702d2c9dec37
author: LTCHIPS <ltchips994@gmail.com>
date: Mon Jul 9 12:55:07 EDT 2018
replaced more strcpy lines with strncpy, also added a function that counts how many digits are in an integer
--- a/src/dosutil.c
+++ b/src/dosutil.c
@@ -95,6 +95,41 @@
return 0;
}
+/*
+ * GetDigitCount returns the number of digits that are found in an integer
+ *
+ * Params: number - number to measure # of digits
+ *
+ * Returns: number of digits founded in number
+*/
+int CountDigits(const int number)
+{
+ int lenResult = 1;
+
+ //int remainder = number;
+
+ if(number)
+ {
+ int oldRemainder;
+ int remainder = number;
+
+ while(1)
+ {
+ oldRemainder = remainder;
+
+ remainder%=10;
+ if (oldRemainder == remainder)
+ break;
+
+ lenResult++;
+
+ }
+ }
+
+ return lenResult;
+}
+
+
/* from Dan Olson */
void put_dos2ansi(byte attrib)
{
--- a/src/rt_game.c
+++ b/src/rt_game.c
@@ -374,12 +374,6 @@
}
}
-void QueueItemToDraw(pic_t * source, int x, int y)
-{
-
-
-}
-
int topBarCenterOffsetX;
extern int hudRescaleFactor;
--- a/src/rt_in.c
+++ b/src/rt_in.c
@@ -269,7 +269,9 @@
if (kp_enter_hack)
{
kp_enter_hack = 0;
- retval = scancodes = Lookup(scancodes, SDLK_KP_ENTER);
+ //retval = scancodes = Lookup(scancodes, SDLK_KP_ENTER);
+ retval = Lookup(scancodes, SDLK_KP_ENTER);
+
//retval = scancodes[SDLK_KP_ENTER];
} /* if */
} /* if */
@@ -1408,8 +1410,8 @@
if ( CommbatMacros[ msg ].avail )
{
MSG.length = strlen( CommbatMacros[ msg ].macro ) + 1;
- strcpy( Messages[ MSG.textnum ].text,
- CommbatMacros[ msg ].macro );
+ strncpy( Messages[ MSG.textnum ].text,
+ CommbatMacros[ msg ].macro, MSG.length) ;
MSG.messageon = false;
FinishModemMessage( MSG.textnum, true );
--- a/src/rt_main.c
+++ b/src/rt_main.c
@@ -153,6 +153,8 @@
extern void RecordDemoQuery ( void );
+extern int CountDigits(const int number);
+
int main (int argc, char *argv[])
{
extern char *BATTMAPS;
@@ -398,16 +400,20 @@
if (CheckParm("QUIET") == 0)
{
SetTextMode();
- strcpy (title,"Rise of the Triad Startup Version ");
- strcat (title,itoa(ROTTMAJORVERSION,&buf[0],10));
- strcat (title,".");
+
+ char rottStartupStr[] = "Rise of the Triad Startup Version ";
+
+ strncpy (title,rottStartupStr, sizeof(rottStartupStr));
+
+ strncat (title,itoa(ROTTMAJORVERSION,&buf[0],10), CountDigits(ROTTMAJORVERSION));
+ strncat (title,".", 1);
//MED
#if (SHAREWARE==1)||(DOPEFISH==0)
- strcat (title,itoa(ROTTMINORVERSION,&buf[0],10));
+ strncat (title,itoa(ROTTMINORVERSION,&buf[0],10), CountDigits(ROTTMINORVERSION));
#else
strcat (title,"DFISH");
#endif
- strcat (title,"\n");
+ strncat (title,"\n", 1);
px=(80-strlen(title))>>1;
py=0;
@@ -415,23 +421,36 @@
printf("%s ", title);
memset (title,0,sizeof(title));
-
+
if (gamestate.Product == ROTT_SHAREWARE)
{
#if (DELUXE==1)
- strcpy(title,"Lasersoft Deluxe Version");
+ char header[] = "Lasersoft Deluxe Version";
#elif (LOWCOST==1)
- strcpy(title,"Episode One");
+ char header[] = "Episode One";
#else
- strcpy(title,"Shareware Version");
+ char header[] = "Shareware Version";
+
#endif
+ strncpy(title,header, strlen(header));
}
else if (gamestate.Product == ROTT_SUPERCD)
- strcpy(title,"CD Version");
+ {
+ char header[] = "CD Version";
+ strncpy(title,header, strlen(header));
+ }
else if (gamestate.Product == ROTT_SITELICENSE)
- strcpy(title,"Site License CD Version");
+ {
+ char header[] = "Site License CD Version";
+ strncpy(title,header, strlen(header));
+ }
else
- strcpy(title,"Commercial Version");
+ {
+ char header[] = "Commercial Version";
+ strncpy(title,header, strlen(header));
+ }
+
+ //strncpy(title, header, )
px=(80-strlen(title))>>1;
py=1;
@@ -771,19 +790,24 @@
char *buf = malloc(32);
if (_argv[arg+1] != 0) { //are there a filename included
tempstr = realloc(tempstr, 129 + strlen(_argv[arg+1]));
- strcpy (tempstr,_argv[arg+1]);//copy it to tempstr
+ strncpy (tempstr,_argv[arg+1], strlen(_argv[arg+1]));//copy it to tempstr
if (strlen (tempstr) < MAX_PATH) {
if (access (tempstr, 0) != 0) { //try open
- strcat (tempstr,".rtc");//non exists, try add .rtc
+ strncat (tempstr,".rtc", 4);//non exists, try add .rtc
if (access (tempstr, 0) != 0) { //try open again
//stil no useful filename
- strcat (tempstr," not found, skipping RTL file ");
+
+ char notfoundStr[] = " not found, skipping RTL file \n";
+
+ strncat (tempstr,notfoundStr, strlen(notfoundStr));
printf("%s", tempstr);
goto NoRTL;
}
}
if((f = fopen( tempstr, "r" )) == NULL ) { //try opnong file
- strcat (tempstr," not could not be opened, skipping RTL file ");
+ char cannotOpenStr[] = " not could be opened, skipping RTL file \n";
+
+ strncat (tempstr, cannotOpenStr, strlen(cannotOpenStr));
printf("%s", tempstr);
goto NoRTL;
} else {
@@ -792,9 +816,9 @@
GameLevels.file = strdup(tempstr);
GameLevels.avail++;
buf = realloc(buf, 32 + strlen(tempstr));
- strcpy (buf,"Adding ");
- strcat (buf,tempstr);
- printf("%s", buf);
+ strncpy (buf,"Adding ", 7);
+ strncat (buf,tempstr, strlen(&tempstr) + 32);
+ printf("%s \n", buf);
}
fclose(f);
}
@@ -805,7 +829,6 @@
free(buf);
}
NoRTL:
- ;
// Check for rtc files
arg = CheckParm ("filertc");
if (arg!=0)
@@ -814,20 +837,24 @@
char *buf = malloc(32);
if (_argv[arg+1] != 0) { //are there a filename included
tempstr = realloc(tempstr, 129 + strlen(_argv[arg+1]));
- strcpy (tempstr,_argv[arg+1]);//copy it to tempstr
+ strncpy (tempstr,_argv[arg+1], sizeof(&_argv[arg+1]));//copy it to tempstr
if (strlen (tempstr) < MAX_PATH) {
if (access (tempstr, 0) != 0) { //try open
- strcat (tempstr,".rtc");//non exists, try add .rtc
+ strncat (tempstr,".rtc", 4);//non exists, try add .rtc
if (access (tempstr, 0) != 0) { //try open again
//stil no useful filename
- strcat (tempstr," not found, skipping RTC file ");
- printf("%s", tempstr);
+ char notfoundRTC[] = " not found, skipping RTC file ";
+
+ strncat (tempstr,notfoundRTC, strlen(notfoundRTC));
+ printf("%s \n", tempstr);
goto NoRTL;
}
}
if((f = fopen( tempstr, "r" )) == NULL ) { //try opening file
- strcat (tempstr," not could not be opened, skipping RTC file ");
- printf("%s", tempstr);
+ char cannotOpenRTC[] = " could not be opened, skipping RTC file ";
+
+ strncat (tempstr,cannotOpenRTC, strlen(cannotOpenRTC));
+ printf("%s \n", tempstr);
goto NoRTL;
} else {
fread(buf,3,3,f);//is the 3 first letters RTL (RTC)
@@ -835,8 +862,8 @@
BattleLevels.file = strdup(tempstr);
BattleLevels.avail++;
buf = realloc(buf, 32 + strlen(tempstr));
- strcpy (buf,"Adding ");
- strcat (buf,tempstr);
+ strncpy (buf,"Adding ", 7);
+ strncat (buf,tempstr, strlen(tempstr) + 32);
printf("%s", buf);
}
fclose(f);
@@ -896,11 +923,11 @@
char *src;
tempstr = realloc(tempstr, strlen(RemoteSounds.path) + strlen(RemoteSounds.file) + 2);
- strcpy (tempstr,RemoteSounds.path);
+ strncpy (tempstr,RemoteSounds.path, strlen(RemoteSounds.path));
src = RemoteSounds.path + strlen(RemoteSounds.path) - 1;
if (*src != '\\')
- strcat (tempstr,"\\\0");
- strcat (tempstr,RemoteSounds.file);
+ strncat (tempstr,"\\\0", 1);
+ strncat (tempstr,RemoteSounds.file, strlen(RemoteSounds.file));
newargs [argnum++] = strdup(tempstr);
}
else
@@ -1381,7 +1408,7 @@
lbm_t * LBM;
byte *s;
patch_t *p;
- char str[50];
+ char * str = '\0';
int width, height;
LBM = (lbm_t *) W_CacheLumpName( "deadboss", PU_CACHE, Cvt_lbm_t, 1);
@@ -1411,16 +1438,20 @@
switch (gamestate.mapon)
{
case 6:
- strcpy(&str[0],"\"General\" John Darian");
+ str = "\"General\" John Darian";
+ //strncpy(&str[0],"\"General\" John Darian");
break;
case 14:
- strcpy(&str[0],"Sebastian \"Doyle\" Krist");
+ str = "Sebastian \"Doyle\" Krist";
+ //strcpy(&str[0],"Sebastian \"Doyle\" Krist");
break;
case 22:
- strcpy(&str[0],"the NME");
+ str = "the NME";
+ //strcpy(&str[0],"the NME");
break;
case 33:
- strcpy(&str[0],"El Oscuro");
+ str = "El Oscuro";
+ //strcpy(&str[0],"El Oscuro");
break;
// default:
// Error("Boss died on an illegal level\n");
@@ -2332,7 +2363,7 @@
}
VL_SetPalette( origpal );
itoa( gammaindex, str2, 10 );
- strcat( str, str2 );
+ strncat( str, str2, strlen(str2) );
AddMessage( str, MSG_SYSTEM );
while( Keyboard[ sc_F11 ] )
@@ -2355,7 +2386,7 @@
MU_SetVolume( MUvolume );
itoa( MUvolume, str2, 10 );
- strcat( str, str2 );
+ strncat( str, str2, strlen(str2) );
AddMessage( str, MSG_SYSTEM );
}
else
@@ -2370,7 +2401,7 @@
FX_SetVolume( FXvolume );
itoa( FXvolume, str2, 10 );
- strcat( str, str2 );
+ strncat( str, str2, strlen(str2) );
AddMessage( str, MSG_SYSTEM );
}
}
@@ -2390,7 +2421,7 @@
MU_SetVolume( MUvolume );
itoa( MUvolume, str2, 10 );
- strcat( str, str2 );
+ strncat( str, str2, strlen(str2) );
AddMessage( str, MSG_SYSTEM );
}
else
@@ -2405,7 +2436,7 @@
FX_SetVolume( FXvolume );
itoa( FXvolume, str2, 10 );
- strcat( str, str2 );
+ strncat( str, str2, strlen(str2) );
AddMessage( str, MSG_SYSTEM );
}
}
--- a/src/rt_map.c
+++ b/src/rt_map.c
@@ -711,6 +711,7 @@
void DrawMapInfo ( void )
{
char temp[80];
+
int width,height;
CurrentFont=tinyfont;
@@ -717,14 +718,16 @@
PrintX = 2;
PrintY = 2;
- strcpy (&temp[0], &(LevelName[0]));
+ strncpy (&temp[0], LevelName, strlen(LevelName));
US_MeasureStr (&width, &height, "%s", &temp[0]);
VWB_TBar (0, 0, 320, height+4);
US_BufPrint (&temp[0]);
+
+ strncpy (&temp[0], "", strlen(LevelName)); //reset temp
- strcpy (&temp[0], "TAB=EXIT");
+ strncpy (&temp[0], "TAB=EXIT", 8);
US_MeasureStr (&width, &height, "%s", &temp[0]);
PrintX = 316-width;
@@ -732,7 +735,9 @@
US_BufPrint (&temp[0]);
- strcpy (&temp[0], "< > CHANGE BACKGROUND COLOR");
+ strncpy (&temp[0], "", strlen(LevelName)); //reset temp
+
+ strncpy (&temp[0], "< > CHANGE BACKGROUND COLOR", 27);
US_MeasureStr (&width, &height, "%s", &temp[0]);
PrintX = (320-width)>>1;
--- a/src/rt_msg.c
+++ b/src/rt_msg.c
@@ -725,8 +725,8 @@
{
if ( i != consoleplayer )
{
- strcpy( str, "0 - " );
- strcat( str, PLAYERSTATE[ i ].codename );
+ strncpy( str, "0 - ", 4 );
+ strncat( str, PLAYERSTATE[ i ].codename, strlen(PLAYERSTATE[ i ].codename) );
str[ 0 ] = '0' + p;
p++;
if ( p > 9 )
--- a/src/rt_str.c
+++ b/src/rt_str.c
@@ -587,7 +587,7 @@
*se,
*s;
- strcpy(strbuf, string);
+ strncpy(strbuf, string, strlen(string));
s = strbuf;
while (*s)
@@ -634,7 +634,7 @@
int oldx = px;
int oldy = py;
- strcpy (buf,s);
+ strncpy (buf,s, strlen(s));
buf[cursor] = '\0';
USL_MeasureString (buf, &w, &h, CurrentFont);
@@ -716,7 +716,7 @@
if (def)
- strcpy (s, def);
+ strncpy (s, def, strlen(def));
else
*s = '\0';
@@ -800,7 +800,7 @@
case sc_Return:
- strcpy (buf,s);
+ strncpy (buf,s, strlen(s));
done = true;
result = true;
lastkey = key_None;
@@ -821,7 +821,7 @@
if (cursor)
{
- strcpy (s + cursor - 1,s + cursor);
+ strncpy (s + cursor - 1,s + cursor, strlen(s + cursor));
cursor--;
redraw = true;
cursormoved = true;
@@ -836,7 +836,7 @@
if (s[cursor])
{
- strcpy (s + cursor,s + cursor + 1);
+ strncpy (s + cursor,s + cursor + 1, strlen(s + cursor + 1));
redraw = true;
cursormoved = true;
MN_PlayMenuSnd (SD_MOVECURSORSND);
@@ -900,7 +900,7 @@
else
EraseMenuBufRegion (x, y, BKw, BKh);
- strcpy (olds, s);
+ strncpy (olds, s, strlen(s));
px = x;
py = y;
@@ -1010,7 +1010,7 @@
if (def)
- strcpy (s, def);
+ strncpy (s, def, strlen(def));
else
*s = '\0';
@@ -1093,7 +1093,7 @@
break;
case sc_Return:
- strcpy (buf,s);
+ strncpy (buf,s, strlen(s));
done = true;
result = true;
lastkey = key_None;
@@ -1114,8 +1114,8 @@
if (cursor)
{
- strcpy (s + cursor - 1,s + cursor);
- strcpy (xx + cursor - 1,xx + cursor);
+ strncpy (s + cursor - 1,s + cursor, strlen(s + cursor));
+ strncpy (xx + cursor - 1,xx + cursor, strlen(xx + cursor));
cursor--;
redraw = true;
MN_PlayMenuSnd (SD_MOVECURSORSND);
@@ -1130,8 +1130,8 @@
if (s[cursor])
{
- strcpy (s + cursor,s + cursor + 1);
- strcpy (xx + cursor,xx + cursor + 1);
+ strncpy (s + cursor,s + cursor + 1, strlen(s + cursor + 1));
+ strncpy (xx + cursor,xx + cursor + 1, strlen(xx + cursor + 1));
redraw = true;
cursormoved = true;
MN_PlayMenuSnd (SD_MOVECURSORSND);
@@ -1195,7 +1195,7 @@
else
EraseMenuBufRegion (x, y, BKw, BKh);
- strcpy (olds, s);
+ strncpy (olds, s, strlen(s));
px = x;
py = y;