@@ -192,7 +192,7 @@ static const char *getCurrentTimeString(void)
192192static const char *getCurrentTickString (void )
193193{
194194 static char TheTickString[32 ];
195- sprintf (TheTickString, " (T=%08lx)" ,::GetTickCount ());
195+ snprintf (TheTickString, ARRAY_SIZE (TheTickString), " (T=%08lx)" , ::GetTickCount ());
196196 return TheTickString;
197197}
198198
@@ -385,14 +385,20 @@ void DebugInit(int flags)
385385 strcat (theLogFileNamePrev, gAppPrefix );
386386 strcat (theLogFileNamePrev, DEBUG_FILE_NAME_PREV);
387387 if (rts::ClientInstance::getInstanceId () > 1u )
388- sprintf (theLogFileNamePrev + strlen (theLogFileNamePrev), " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
388+ {
389+ size_t offset = strlen (theLogFileNamePrev);
390+ snprintf (theLogFileNamePrev + offset, ARRAY_SIZE (theLogFileNamePrev) - offset, " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
391+ }
389392 strcat (theLogFileNamePrev, " .txt" );
390393
391394 strcpy (theLogFileName, dirbuf);
392395 strcat (theLogFileName, gAppPrefix );
393396 strcat (theLogFileName, DEBUG_FILE_NAME);
394397 if (rts::ClientInstance::getInstanceId () > 1u )
395- sprintf (theLogFileName + strlen (theLogFileName), " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
398+ {
399+ size_t offset = strlen (theLogFileNamePrev);
400+ snprintf (theLogFileName + offset, ARRAY_SIZE (theLogFileName) - offset, " _Instance%.2u" , rts::ClientInstance::getInstanceId ());
401+ }
396402 strcat (theLogFileName, " .txt" );
397403
398404 remove (theLogFileNamePrev);
@@ -428,7 +434,8 @@ void DebugLog(const char *format, ...)
428434
429435 va_list args;
430436 va_start (args, format);
431- vsprintf (theBuffer + strlen (theBuffer), format, args);
437+ size_t offset = strlen (theBuffer);
438+ vsnprintf (theBuffer + offset, ARRAY_SIZE (theBuffer) - offset, format, args);
432439 va_end (args);
433440
434441 if (strlen (theBuffer) >= sizeof (theBuffer))
@@ -454,7 +461,7 @@ void DebugLogRaw(const char *format, ...)
454461
455462 va_list args;
456463 va_start (args, format);
457- vsprintf (theBuffer, format, args);
464+ vsnprintf (theBuffer, ARRAY_SIZE (theBuffer) , format, args);
458465 va_end (args);
459466
460467 if (strlen (theBuffer) >= sizeof (theBuffer))
0 commit comments