Skip to content

Commit 696cb63

Browse files
authored
[GEN][ZH] Fix unsafe calls to _vsnprintf, _vsnwprintf, _snprintf, _snwprintf (#858)
1 parent f47115f commit 696cb63

File tree

44 files changed

+205
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+205
-179
lines changed

Core/Libraries/Source/WWVegas/WW3D2/statistics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "dx8caps.h"
2525
#include "textureloader.h"
2626
#include "texture.h"
27-
#include <cstdio>
27+
#include <Utility/stdio_adapter.h>
2828

2929
#include <memory.h>
3030
#ifdef _UNIX
@@ -94,7 +94,7 @@ static void Record_Texture_End()
9494
texture_statistics_string="";
9595
if (record_texture_mode==Debug_Statistics::RECORD_TEXTURE_DETAILS) {
9696
char tmp_text[1024];
97-
_snprintf(tmp_text,sizeof(tmp_text),
97+
snprintf(tmp_text,sizeof(tmp_text),
9898
"Set_DX8_Texture count: %d\nactual changes: %d\n\n"
9999
"id refs changes size name\n"
100100
"--------------------------------------\n",

Core/Libraries/Source/WWVegas/WWDownload/urlBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#include <string>
20-
#include <stdio.h>
20+
#include <Utility/stdio_adapter.h>
2121
#include "Registry.h"
2222

2323
void FormatURLFromRegistry( std::string& gamePatchURL, std::string& mapPatchURL,
@@ -41,13 +41,13 @@ void FormatURLFromRegistry( std::string& gamePatchURL, std::string& mapPatchURL,
4141
GetUnsignedIntFromRegistry("", "MapPackVersion", mapVersion);
4242

4343
char buf[256];
44-
_snprintf(buf, 256, "%s%s-%d.txt", baseURL.c_str(), language.c_str(), version);
44+
snprintf(buf, 256, "%s%s-%d.txt", baseURL.c_str(), language.c_str(), version);
4545
gamePatchURL = buf;
46-
_snprintf(buf, 256, "%smaps-%d.txt", baseURL.c_str(), mapVersion);
46+
snprintf(buf, 256, "%smaps-%d.txt", baseURL.c_str(), mapVersion);
4747
mapPatchURL = buf;
48-
_snprintf(buf, 256, "%sconfig.txt", baseURL.c_str());
48+
snprintf(buf, 256, "%sconfig.txt", baseURL.c_str());
4949
configURL = buf;
50-
_snprintf(buf, 256, "%sMOTD-%s.txt", baseURL.c_str(), language.c_str());
50+
snprintf(buf, 256, "%sMOTD-%s.txt", baseURL.c_str(), language.c_str());
5151
motdURL = buf;
5252
}
5353

Core/Libraries/Source/WWVegas/WWLib/ini.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
#include "win.h"
9595
#include "XPIPE.H"
9696
#include "XSTRAW.H"
97-
#include <stdio.h>
97+
#include <Utility/stdio_adapter.h>
9898
#include <malloc.h>
9999
#ifdef _UNIX
100100
#include <ctype.h>
@@ -2281,7 +2281,7 @@ int INIClass::CRC(const char *string)
22812281
void INIClass::DuplicateCRCError(const char *message, const char *section, const char *entry)
22822282
{
22832283
char buffer[512];
2284-
_snprintf(buffer, sizeof(buffer), "%s - Duplicate Entry \"%s\" in section \"%s\" (%s)\n", message,
2284+
snprintf(buffer, sizeof(buffer), "%s - Duplicate Entry \"%s\" in section \"%s\" (%s)\n", message,
22852285
entry, section, Filename);
22862286

22872287
OutputDebugString(buffer);

Core/Libraries/Source/WWVegas/WWLib/widestring.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#include "widestring.h"
4040
#include "win.h"
41-
#include <stdio.h>
41+
#include <Utility/stdio_adapter.h>
4242

4343

4444
///////////////////////////////////////////////////////////////////
@@ -258,7 +258,7 @@ WideStringClass::Format_Args (const WCHAR *format, va_list arg_list )
258258
//
259259
// Format the string
260260
//
261-
int retval = _vsnwprintf (temp_buffer, 512, format, arg_list);
261+
int retval = vswprintf (temp_buffer, 512, format, arg_list);
262262

263263
//
264264
// Copy the string into our buffer
@@ -292,7 +292,7 @@ WideStringClass::Format (const WCHAR *format, ...)
292292
//
293293
// Format the string
294294
//
295-
int retval = _vsnwprintf (temp_buffer, 512, format, arg_list);
295+
int retval = vswprintf (temp_buffer, 512, format, arg_list);
296296

297297
//
298298
// Copy the string into our buffer

Core/Libraries/Source/WWVegas/WWLib/wwfile.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,19 @@
3434
* Functions: *
3535
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3636

37-
#include <stdio.h>
37+
#include <Utility/stdio_adapter.h>
3838
#include <stdarg.h>
3939
#include <memory.h>
4040
#include "WWFILE.H"
4141

42-
// TheSuperHackers @compile feliwir 17/04/2025 include _vsnprintf macros
43-
#include <Utility/compat.h>
44-
4542
#pragma warning(disable : 4514)
4643

4744
int FileClass::Printf(char *str, ...)
4845
{
4946
char text[PRINTF_BUFFER_SIZE];
5047
va_list args;
5148
va_start(args, str);
52-
int length = _vsnprintf(text, PRINTF_BUFFER_SIZE, str, args);
49+
int length = vsnprintf(text, PRINTF_BUFFER_SIZE, str, args);
5350
va_end(args);
5451
return Write(text, length);
5552
}
@@ -58,7 +55,7 @@ int FileClass::Printf(char *buffer, int bufferSize, char *str, ...)
5855
{
5956
va_list args;
6057
va_start(args, str);
61-
int length = _vsnprintf(buffer, bufferSize, str, args);
58+
int length = vsnprintf(buffer, bufferSize, str, args);
6259
va_end(args);
6360
return Write(buffer, length);
6461
}
@@ -76,7 +73,7 @@ int FileClass::Printf_Indented(unsigned depth, char *str, ...)
7673

7774
int length;
7875
if(depth < PRINTF_BUFFER_SIZE)
79-
length = _vsnprintf(text + depth, PRINTF_BUFFER_SIZE - depth, str, args);
76+
length = vsnprintf(text + depth, PRINTF_BUFFER_SIZE - depth, str, args);
8077
else
8178
length = PRINTF_BUFFER_SIZE;
8279

Core/Libraries/Source/WWVegas/WWLib/wwstring.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "wwstring.h"
3838
#include "wwmemlog.h"
3939
#include "mutex.h"
40-
#include <stdio.h>
40+
#include <Utility/stdio_adapter.h>
4141

4242

4343
///////////////////////////////////////////////////////////////////
@@ -249,9 +249,9 @@ StringClass::Format_Args (const TCHAR *format, va_list arg_list )
249249
// Format the string
250250
//
251251
#ifdef _UNICODE
252-
retval = _vsnwprintf (temp_buffer, 512, format, arg_list);
252+
retval = vswprintf (temp_buffer, 512, format, arg_list);
253253
#else
254-
retval = _vsnprintf (temp_buffer, 512, format, arg_list);
254+
retval = vsnprintf (temp_buffer, 512, format, arg_list);
255255
#endif
256256

257257
//
@@ -284,9 +284,9 @@ StringClass::Format (const TCHAR *format, ...)
284284
// Format the string
285285
//
286286
#ifdef _UNICODE
287-
retval = _vsnwprintf (temp_buffer, 512, format, arg_list);
287+
retval = vswprintf (temp_buffer, 512, format, arg_list);
288288
#else
289-
retval = _vsnprintf (temp_buffer, 512, format, arg_list);
289+
retval = vsnprintf (temp_buffer, 512, format, arg_list);
290290
#endif
291291

292292
//

Core/Libraries/Source/debug/debug_debug.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//////////////////////////////////////////////////////////////////////////////
2929
#include "_pch.h"
3030
#include <stdlib.h>
31-
#include <stdio.h>
31+
#include <Utility/stdio_adapter.h>
3232
#include <string.h>
3333
#include <new> // needed for placement new prototype
3434

@@ -240,7 +240,7 @@ Debug::Format::Format(const char *format, ...)
240240
{
241241
va_list va;
242242
va_start(va,format);
243-
_vsnprintf(m_buffer,sizeof(m_buffer)-1,format,va);
243+
vsnprintf(m_buffer,sizeof(m_buffer)-1,format,va);
244244
va_end(va);
245245
}
246246

@@ -783,15 +783,15 @@ Debug& Debug::operator<<(float val)
783783
{
784784
/// @todo_opt shouldn't use snprintf here - brings in most of the old C IO lib...
785785
char help[200];
786-
_snprintf(help,sizeof(help),"%f",val);
786+
snprintf(help,sizeof(help),"%f",val);
787787
return (*this) << help;
788788
}
789789

790790
Debug& Debug::operator<<(double val)
791791
{
792792
/// @todo_opt shouldn't use snprintf here - brings in most of the old C IO lib...
793793
char help[200];
794-
_snprintf(help,sizeof(help),"%f",val);
794+
snprintf(help,sizeof(help),"%f",val);
795795
return (*this) << help;
796796
}
797797

Core/Libraries/Source/profile/profile_highlevel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//////////////////////////////////////////////////////////////////////////////
2929
#include "_pch.h"
3030
#include <new>
31-
#include <stdio.h>
31+
#include <Utility/stdio_adapter.h>
3232

3333
// our own fast critical section
3434
static ProfileFastCS cs;
@@ -202,7 +202,7 @@ const char *ProfileId::AsString(double v) const
202202
for (k=m_exp10;k<0;k++) mul*=10.0;
203203
for (;k>0;k--) mul/=10.0;
204204

205-
unsigned len=_snprintf(help,sizeof(help),help1,v*mul)+1;
205+
unsigned len=snprintf(help,sizeof(help),help1,v*mul)+1;
206206

207207
ProfileFastCS::Lock lock(cs);
208208
if (stringBufUnused+len>STRING_BUFFER_SIZE)

Core/Tools/Autorun/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ target_sources(corei_autorun INTERFACE ${AUTORUN_SRC})
5454

5555
target_link_libraries(corei_autorun INTERFACE
5656
core_config
57+
core_utility
5758
winmm
5859
)
5960

Core/Tools/Autorun/GameText.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//----------------------------------------------------------------------------
3939

4040
#include <stdlib.h>
41-
#include <stdio.h>
41+
#include <Utility/stdio_adapter.h>
4242
#include <ctype.h>
4343
#include <string.h>
4444

@@ -1072,8 +1072,7 @@ const wchar_t * GameTextManager::fetch( const Char *label )
10721072
{
10731073
// See if we already have the missing string
10741074
wchar_t tmp[256];
1075-
_snwprintf(tmp, 256, L"MISSING: '%hs'", label);
1076-
tmp[255] = 0;
1075+
swprintf(tmp, 256, L"MISSING: '%hs'", label);
10771076
std::wstring missingString = tmp;
10781077

10791078
NoString *noString = m_noStringList;

0 commit comments

Comments
 (0)