diff --git a/src/components/user_config/user_config.cpp b/src/components/user_config/user_config.cpp index 42d0aef1..d930491e 100644 --- a/src/components/user_config/user_config.cpp +++ b/src/components/user_config/user_config.cpp @@ -13,8 +13,15 @@ std::string get_xdg_user_config_home() std::string home(getenv("HOME")); path = home + "/Library/Application Support"; #elif _WIN32 +#if __STDC_WANT_SECURE_LIB__ + char *app_data_env = NULL; + size_t app_data_env_sz = 0; + _dupenv_s(&app_data_env, &app_data_env_sz, "LOCALAPPDATA"); + if (!app_data_env) _dupenv_s(&app_data_env, &app_data_env_sz, "APPDATA"); +#else char *app_data_env = getenv("LOCALAPPDATA"); if (!app_data_env) app_data_env = getenv("APPDATA"); +#endif std::string app_data(app_data_env); path = app_data; #else // Unix @@ -40,8 +47,15 @@ std::string get_xdg_user_data_home() std::string home(getenv("HOME")); path = home + "/Library/Application Support"; #elif _WIN32 +#if __STDC_WANT_SECURE_LIB__ + char *app_data_env = NULL; + size_t app_data_env_sz = 0; + _dupenv_s(&app_data_env, &app_data_env_sz, "LOCALAPPDATA"); + if (!app_data_env) _dupenv_s(&app_data_env, &app_data_env_sz, "APPDATA"); +#else char *app_data_env = getenv("LOCALAPPDATA"); if (!app_data_env) app_data_env = getenv("APPDATA"); +#endif std::string app_data(app_data_env); path = app_data; #else // Unix diff --git a/src/core/base/file_util.h b/src/core/base/file_util.h index 34ca4a6a..ba32aca8 100644 --- a/src/core/base/file_util.h +++ b/src/core/base/file_util.h @@ -40,7 +40,7 @@ void utilReadDataMem(const uint8_t *&data, variable_desc *); #else // !defined(__LIBRETRO__) // strip .gz or .z off end -void utilStripDoubleExtension(const char *, char *); +void utilStripDoubleExtension(const char *, char *, size_t); gzFile utilAutoGzOpen(const char *file, const char *mode); gzFile utilGzOpen(const char *file, const char *mode); diff --git a/src/core/base/file_util_common.cpp b/src/core/base/file_util_common.cpp index 36d749a4..eade5ad8 100644 --- a/src/core/base/file_util_common.cpp +++ b/src/core/base/file_util_common.cpp @@ -27,7 +27,13 @@ FILE* utilOpenFile(const char* filename, const char* mode) { return nullptr; } +#if __STDC_WANT_SECURE_LIB__ + FILE *ret = NULL; + _wfopen_s(&ret, wfilename.data(), wmode.data()); + return ret; +#else return _wfopen(wfilename.data(), wmode.data()); +#endif #else return fopen(filename, mode); #endif // _WIN32 diff --git a/src/core/base/file_util_desktop.cpp b/src/core/base/file_util_desktop.cpp index 6f9c366d..9229e2cb 100644 --- a/src/core/base/file_util_desktop.cpp +++ b/src/core/base/file_util_desktop.cpp @@ -48,10 +48,15 @@ fex_t* scanArchive(const char* file, bool (*accept)(const char*), char (&buffer) // Scan filenames bool found = false; while (!fex_done(fe)) { +#ifdef __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof buffer, fex_name(fe), sizeof buffer); +#else strncpy(buffer, fex_name(fe), sizeof buffer); +#endif + buffer[sizeof buffer - 1] = '\0'; - utilStripDoubleExtension(buffer, buffer); + utilStripDoubleExtension(buffer, buffer, sizeof buffer); if (accept(buffer)) { found = true; @@ -153,9 +158,16 @@ IMAGE_TYPE utilFindType(const char* file) { return utilFindType(file, buffer); } -void utilStripDoubleExtension(const char* file, char* buffer) { +void utilStripDoubleExtension(const char* file, char* buffer, size_t len) { +#if !__STDC_WANT_SECURE_LIB__ + (void)len; +#endif if (buffer != file) // allows conversion in place +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(buffer, len, file); +#else strcpy(buffer, file); +#endif if (utilIsGzipFile(file)) { char* p = strrchr(buffer, '.'); diff --git a/src/core/base/image_util.cpp b/src/core/base/image_util.cpp index ce6c8edd..bf018c59 100644 --- a/src/core/base/image_util.cpp +++ b/src/core/base/image_util.cpp @@ -100,7 +100,12 @@ bool utilWritePNGFile(const char* fileName, int w, int h, uint8_t* pix) { bool utilWriteBMPFile(const char* fileName, int w, int h, uint8_t* pix) { uint8_t writeBuffer[512 * 3]; +#if __STDC_WANT_SECURE_LIB__ + FILE* fp = NULL; + fopen_s(&fp, fileName, "wb"); +#else FILE* fp = fopen(fileName, "wb"); +#endif if (!fp) { systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName); diff --git a/src/core/fex/fex/Data_Reader.cpp b/src/core/fex/fex/Data_Reader.cpp index c65bcbb7..ed96b802 100644 --- a/src/core/fex/fex/Data_Reader.cpp +++ b/src/core/fex/fex/Data_Reader.cpp @@ -518,7 +518,11 @@ static FILE* blargg_fopen( const char path [], const char mode [] ) { wmode = blargg_to_wide( mode ); if ( wmode ) +#if __STDC_WANT_SECURE_LIB__ + _wfopen_s(&file, wpath, wmode ); +#else file = _wfopen( wpath, wmode ); +#endif } // Save and restore errno in case free() clears it diff --git a/src/core/fex/fex/Zip7_Extractor.cpp b/src/core/fex/fex/Zip7_Extractor.cpp index 831ec3b1..a4b9f181 100644 --- a/src/core/fex/fex/Zip7_Extractor.cpp +++ b/src/core/fex/fex/Zip7_Extractor.cpp @@ -288,7 +288,11 @@ blargg_err_t Zip7_Extractor::next_v() time_t _time = time; #ifdef _WIN32 - tm = *localtime( &_time ); + #if __STDC_WANT_SECURE_LIB__ + localtime_s(&tm, &_time); + #else + tm = *localtime( &_time ); + #endif #else localtime_r( &_time, &tm ); #endif diff --git a/src/core/gb/gb.cpp b/src/core/gb/gb.cpp index 893c79d4..cf73b588 100644 --- a/src/core/gb/gb.cpp +++ b/src/core/gb/gb.cpp @@ -66,7 +66,11 @@ std::vector g_vbamIoVecs; void ResetMBC3RTC() { time(&gbDataMBC3.mapperLastTime); struct tm* lt; +#if __STDC_WANT_SECURE_LIB__ + localtime_s(lt, &gbDataMBC3.mapperLastTime); +#else lt = localtime(&gbDataMBC3.mapperLastTime); +#endif gbDataMBC3.mapperSeconds = lt->tm_sec; gbDataMBC3.mapperMinutes = lt->tm_min; gbDataMBC3.mapperHours = lt->tm_hour; @@ -80,7 +84,11 @@ void ResetTama5RTC() { 31, 31, 30, 31, 30, 31}; time(&gbDataTAMA5.mapperLastTime); struct tm* lt; +#if __STDC_WANT_SECURE_LIB__ + localtime_s(lt, &gbDataTAMA5.mapperLastTime); +#else lt = localtime(&gbDataTAMA5.mapperLastTime); +#endif gbDataTAMA5.mapperSeconds = lt->tm_sec; gbDataTAMA5.mapperMinutes = lt->tm_min; gbDataTAMA5.mapperHours = lt->tm_hour; @@ -111,7 +119,12 @@ void ResetTama5RTC() { void ResetHuc3RTC() { time(&gbRTCHuC3.mapperLastTime); +#if __STDC_WANT_SECURE_LIB__ + struct tm* lt; + localtime_s(lt, &gbRTCHuC3.mapperLastTime); +#else localtime(&gbRTCHuC3.mapperLastTime); +#endif } bool WriteBatteryFile(const char* file_name) { diff --git a/src/core/gb/gbCheats.cpp b/src/core/gb/gbCheats.cpp index 1cd31ec0..6f48e2c4 100644 --- a/src/core/gb/gbCheats.cpp +++ b/src/core/gb/gbCheats.cpp @@ -209,8 +209,13 @@ bool gbAddGsCheat(const char* code, const char* desc) int i = gbCheatNumber; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(gbCheatList[i].cheatCode, sizeof(gbCheatList[i].cheatCode), code); + strcpy_s(gbCheatList[i].cheatDesc, sizeof(gbCheatList[i].cheatDesc), desc); +#else strcpy(gbCheatList[i].cheatCode, code); strcpy(gbCheatList[i].cheatDesc, desc); +#endif gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 | GBCHEAT_HEX_VALUE(code[1]); @@ -318,8 +323,13 @@ bool gbAddGgCheat(const char* code, const char* desc) size_t len = strlen(code); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(gbCheatList[i].cheatCode, sizeof(gbCheatList[i].cheatCode), code); + strcpy_s(gbCheatList[i].cheatDesc, sizeof(gbCheatList[i].cheatDesc), desc); +#else strcpy(gbCheatList[i].cheatCode, code); strcpy(gbCheatList[i].cheatDesc, desc); +#endif gbCheatList[i].code = 0x101; gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) + GBCHEAT_HEX_VALUE(code[1]); diff --git a/src/core/gba/debugger-expr-lex.cpp b/src/core/gba/debugger-expr-lex.cpp index 8b0bbfe0..c1665567 100644 --- a/src/core/gba/debugger-expr-lex.cpp +++ b/src/core/gba/debugger-expr-lex.cpp @@ -899,6 +899,10 @@ static int input ( void ); #endif +#if __STDC_WANT_SECURE_LIB__ +#define sscanf sscanf_s +#endif + /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. diff --git a/src/core/gba/debugger-expr-yacc.cpp b/src/core/gba/debugger-expr-yacc.cpp index 4028be39..f6863d10 100644 --- a/src/core/gba/debugger-expr-yacc.cpp +++ b/src/core/gba/debugger-expr-yacc.cpp @@ -1516,7 +1516,12 @@ void dexp_saveVars(char *file) { std::map::iterator iter; +#if __STDC_WANT_SECURE_LIB__ + FILE* f = NULL; + fopen_s(&f, file, "w"); +#else FILE *f = fopen(file, "w"); +#endif if (!f) { printf("Could not open file %s\n", file); return; @@ -1535,14 +1540,23 @@ void dexp_loadVars(char *file) char name[500]; uint32_t val; +#if __STDC_WANT_SECURE_LIB__ + FILE* f = NULL; + fopen_s(&f, file, "r"); +#else FILE *f = fopen(file, "r"); +#endif if (!f) { printf("Could not open file %s\n", file); return; } while (fgets(buffer, 500, f) != NULL) { - if (sscanf(buffer, "%s = %x",name,&val) == 2) { +#if __STDC_WANT_SECURE_LIB__ + if (sscanf_s(buffer, "%s = %x", name, (unsigned)_countof(name), &val) == 2) { +#else + if (sscanf(buffer, "%s = %x", name, &val) == 2) { +#endif dexp_setVar(name, val); } } diff --git a/src/core/gba/gbaCheats.cpp b/src/core/gba/gbaCheats.cpp index 10ec2764..cc8854b5 100644 --- a/src/core/gba/gbaCheats.cpp +++ b/src/core/gba/gbaCheats.cpp @@ -11,6 +11,7 @@ #if __STDC_WANT_SECURE_LIB__ #define snprintf sprintf_s +#define sscanf sscanf_s #endif /** @@ -1299,8 +1300,13 @@ void cheatsAdd(const char* codeStr, cheatsList[x].rawaddress = rawaddress; cheatsList[x].address = address; cheatsList[x].value = value; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(cheatsList[x].codestring, sizeof(cheatsList[x].codestring), codeStr); + strcpy_s(cheatsList[x].desc, sizeof(cheatsList[x].desc), desc); +#else strcpy(cheatsList[x].codestring, codeStr); strcpy(cheatsList[x].desc, desc); +#endif cheatsList[x].enabled = true; cheatsList[x].status = 0; @@ -1461,7 +1467,11 @@ bool cheatsVerifyCheatCode(const char* code, const char* desc) uint32_t value = 0; char buffer[10]; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), code, 8); +#else strncpy(buffer, code, 8); +#endif buffer[8] = 0; sscanf(buffer, "%x", &address); @@ -1486,7 +1496,12 @@ bool cheatsVerifyCheatCode(const char* code, const char* desc) return false; } +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), &code[9], 8); +#else strncpy(buffer, &code[9], 8); +#endif + sscanf(buffer, "%x", &value); int type = 0; if (len == 13) @@ -1574,11 +1589,19 @@ void cheatsAddGSACode(const char* code, const char* desc, bool v3) } char buffer[10]; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), code, 8); +#else strncpy(buffer, code, 8); +#endif buffer[8] = 0; uint32_t address; sscanf(buffer, "%x", &address); +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), &code[8], 8); +#else strncpy(buffer, &code[8], 8); +#endif buffer[8] = 0; uint32_t value; sscanf(buffer, "%x", &value); @@ -2459,11 +2482,19 @@ void cheatsAddCBACode(const char* code, const char* desc) } char buffer[10]; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), code, 8); +#else strncpy(buffer, code, 8); +#endif buffer[8] = 0; uint32_t address; sscanf(buffer, "%x", &address); +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), &code[9], 4); +#else strncpy(buffer, &code[9], 4); +#endif buffer[4] = 0; uint32_t value; sscanf(buffer, "%x", &value); @@ -2640,12 +2671,20 @@ void cheatsReadGame(gzFile file, int version) if (cheatsList[i].code == 512 && firstCodeBreaker) { firstCodeBreaker = false; char buffer[10]; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), cheatsList[i].codestring, 8); +#else strncpy(buffer, cheatsList[i].codestring, 8); +#endif buffer[8] = 0; uint32_t address; sscanf(buffer, "%x", &address); if ((address >> 28) == 9) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), &cheatsList[i].codestring[9], 4); +#else strncpy(buffer, &cheatsList[i].codestring[9], 4); +#endif buffer[4] = 0; uint32_t value; sscanf(buffer, "%x", &value); @@ -2780,12 +2819,20 @@ bool cheatsLoadCheatList(const char* file) if (cheatsList[i].code == 512 && firstCodeBreaker) { firstCodeBreaker = false; char buffer[10]; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), cheatsList[i].codestring, 8); +#else strncpy(buffer, cheatsList[i].codestring, 8); +#endif buffer[8] = 0; uint32_t address; sscanf(buffer, "%x", &address); if ((address >> 28) == 9) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), &cheatsList[i].codestring[9], 4); +#else strncpy(buffer, &cheatsList[i].codestring[9], 4); +#endif buffer[4] = 0; uint32_t value; sscanf(buffer, "%x", &value); diff --git a/src/core/gba/gbaCpuThumb.cpp b/src/core/gba/gbaCpuThumb.cpp index c1ba0c2d..10e84290 100644 --- a/src/core/gba/gbaCpuThumb.cpp +++ b/src/core/gba/gbaCpuThumb.cpp @@ -20,8 +20,12 @@ #endif #ifdef _MSC_VER +#if __STDC_WANT_SECURE_LIB__ +#define snprintf sprintf_s +#else #define snprintf _snprintf #endif +#endif /////////////////////////////////////////////////////////////////////////// diff --git a/src/core/gba/gbaElf.cpp b/src/core/gba/gbaElf.cpp index 044901d7..59305be4 100644 --- a/src/core/gba/gbaElf.cpp +++ b/src/core/gba/gbaElf.cpp @@ -280,7 +280,11 @@ const char* elfGetAddressSymbol(uint32_t addr) if (offset) snprintf(buffer, 256, "%s+%d", name, offset); else { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), name, 255); //strncpy_s does not allways append a '\0' +#else strncpy(buffer, name, 255); //strncpy does not allways append a '\0' +#endif buffer[255] = '\0'; } return buffer; @@ -300,16 +304,28 @@ const char* elfGetAddressSymbol(uint32_t addr) if (offset) snprintf(buffer, 256,"%s+%d", name, addr - s->value); else { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), name, 255); +#else strncpy(buffer, name, 255); +#endif buffer[255] = '\0'; } return buffer; } else if (addr == s->value) { if (s->name) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), s->name, 255); +#else strncpy(buffer, s->name, 255); +#endif buffer[255] = '\0'; } else +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(buffer, sizeof(buffer), ""); +#else strcpy(buffer, ""); +#endif return buffer; } } diff --git a/src/core/gba/gbaLink.cpp b/src/core/gba/gbaLink.cpp index 4bb45a51..c35f1855 100644 --- a/src/core/gba/gbaLink.cpp +++ b/src/core/gba/gbaLink.cpp @@ -538,21 +538,37 @@ bool GetLinkServerHost(char* const host, size_t size) host[0] = '\0'; if (linkDriver && linkDriver->mode == LINK_GAMECUBE_DOLPHIN) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(host, size, joybusHostAddr.toString().c_str(), size); +#else strncpy(host, joybusHostAddr.toString().c_str(), size); +#endif } else if (lanlink.server) { if (IP_LINK_BIND_ADDRESS == "*") { auto local_addr = sf::IpAddress::getLocalAddress(); if (local_addr) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(host, size, local_addr.value().toString().c_str(), size); +#else strncpy(host, local_addr.value().toString().c_str(), size); +#endif } else { return false; } } else { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(host, size, IP_LINK_BIND_ADDRESS.c_str(), size); +#else strncpy(host, IP_LINK_BIND_ADDRESS.c_str(), size); +#endif } } else { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(host, size, lc.serveraddr.toString().c_str(), size); +#else strncpy(host, lc.serveraddr.toString().c_str(), size); +#endif } return true; diff --git a/src/core/gba/gbaRemote.cpp b/src/core/gba/gbaRemote.cpp index 9ba9923e..76ec669b 100644 --- a/src/core/gba/gbaRemote.cpp +++ b/src/core/gba/gbaRemote.cpp @@ -50,6 +50,7 @@ #if __STDC_WANT_SECURE_LIB__ #define snprintf sprintf_s +#define sscanf sscanf_s #endif extern int emulating; @@ -392,7 +393,11 @@ void debuggerDumpLoad(int n, char** args) return; } +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, file, "rb"); +#else f = fopen(file, "rb"); +#endif if (f == NULL) { { snprintf(monbuf, sizeof(monbuf), "Error opening file.\n"); @@ -442,7 +447,12 @@ void debuggerDumpSave(int n, char** args) return; } +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, file, "wb"); +#else f = fopen(file, "wb"); +#endif + if (f == NULL) { { snprintf(monbuf, sizeof(monbuf), "Error opening file.\n"); @@ -935,10 +945,18 @@ void debuggerFindText(int n, char** args) if (n == 4) { sscanf(args[2], "%u", &SearchMaxMatches); +#if __STDC_WANT_SECURE_LIB__ + strncpy_s((char*)SearchData, sizeof(SearchData), args[3], 64); +#else strncpy((char*)SearchData, args[3], 64); +#endif SearchLength = (unsigned int)strlen(args[3]); } else if (n == 3) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s((char*)SearchData, sizeof(SearchData), args[2], 64); +#else strncpy((char*)SearchData, args[2], 64); +#endif SearchLength = (unsigned int)strlen(args[2]); }; @@ -971,10 +989,18 @@ void debuggerFindHex(int n, char** args) char SearchHex[128]; if (n == 4) { sscanf(args[2], "%u", &SearchMaxMatches); +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(SearchHex, sizeof(SearchHex), args[3], 128); +#else strncpy(SearchHex, args[3], 128); +#endif SearchLength = (unsigned int)strlen(args[3]); } else if (n == 3) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(SearchHex, sizeof(SearchHex), args[2], 128); +#else strncpy(SearchHex, args[2], 128); +#endif SearchLength = (unsigned int)strlen(args[2]); }; @@ -1507,7 +1533,12 @@ void debuggerReadCharTable(int n, char** args) } return; } +#if __STDC_WANT_SECURE_LIB__ + FILE* tlb = NULL; + fopen_s(&tlb, args[1], "r"); +#else FILE* tlb = fopen(args[1], "r"); +#endif if (!tlb) { { snprintf(monbuf, sizeof(monbuf), "Could not open specified file. Abort.\n"); @@ -1520,8 +1551,11 @@ void debuggerReadCharTable(int n, char** args) char* character = (char*)calloc(10, sizeof(char)); wordSymbol = (char**)calloc(256, sizeof(char*)); while (fgets(buffer, 30, tlb)) { - +#if __STDC_WANT_SECURE_LIB__ + sscanf_s(buffer, "%02x=%s", &slot, character, 10); +#else sscanf(buffer, "%02x=%s", &slot, character); +#endif if (character[0]) { if (strlen(character) == 4) { @@ -1789,7 +1823,12 @@ void debuggerExecuteCommands(int n, char** args) n--; args++; while (n) { +#if __STDC_WANT_SECURE_LIB__ + FILE* toExec = NULL; + fopen_s(&toExec, args[0], "r"); +#else FILE* toExec = fopen(args[0], "r"); +#endif if (toExec) { while (fgets(buffer, 4096, toExec)) { std::string buf(buffer); @@ -3388,7 +3427,11 @@ void dbgExecute(char* toRun) void dbgExecute(std::string& cmd) { char* dbgCmd = new char[cmd.length() + 1]; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(dbgCmd, cmd.length() + 1, cmd.c_str()); +#else strcpy(dbgCmd, cmd.c_str()); +#endif dbgExecute(dbgCmd); delete[] dbgCmd; } @@ -4314,7 +4357,11 @@ void monprintf(std::string line) if (output.length() <= 1000) { char dbgReply[1000]; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(dbgReply, sizeof(dbgReply), output.c_str()); +#else strcpy(dbgReply, output.c_str()); +#endif remotePutPacket(dbgReply); } } diff --git a/src/core/gba/gbaRtc.cpp b/src/core/gba/gbaRtc.cpp index 56bd17d5..d8c4d876 100644 --- a/src/core/gba/gbaRtc.cpp +++ b/src/core/gba/gbaRtc.cpp @@ -111,7 +111,11 @@ void SetGBATime() { time_t long_time; time(&long_time); /* Get time as long integer. */ +#if __STDC_WANT_SECURE_LIB__ + localtime_s(&gba_time, &long_time); /* Convert to local time. */ +#else gba_time = *localtime(&long_time); /* Convert to local time. */ +#endif } void rtcUpdateTime(int ticks) diff --git a/src/core/gba/internal/gbaBreakpoint.cpp b/src/core/gba/internal/gbaBreakpoint.cpp index 0dac4ac5..57374a55 100644 --- a/src/core/gba/internal/gbaBreakpoint.cpp +++ b/src/core/gba/internal/gbaBreakpoint.cpp @@ -110,6 +110,7 @@ sw, sword, int32_t, int --> signed word #if (defined __WIN32__ || defined _WIN32) #define strdup _strdup +#define sscanf sscanf_s #endif extern bool dexp_eval(char*, uint32_t*); diff --git a/src/sdl/ConfigManager.cpp b/src/sdl/ConfigManager.cpp index ba07d44c..74ce0de6 100644 --- a/src/sdl/ConfigManager.cpp +++ b/src/sdl/ConfigManager.cpp @@ -18,6 +18,7 @@ #if __STDC_WANT_SECURE_LIB__ #define snprintf sprintf_s +#define sscanf sscanf_s #endif #define getcwd _getcwd @@ -472,7 +473,13 @@ const char* FindConfigFile(const char *name) } #ifdef _WIN32 +#if __STDC_WANT_SECURE_LIB__ + char *home = NULL; + size_t home_sz = 0; + _dupenv_s(&home, &home_sz, "USERPROFILE"); +#else char *home = getenv("USERPROFILE"); +#endif if (home != NULL) { snprintf(path, "%s%c%s", home, kFileSep, name); if (FileExists(path)) @@ -483,12 +490,28 @@ const char* FindConfigFile(const char *name) if (!strchr(arg0, '/') && !strchr(arg0, '\\')) { +#if __STDC_WANT_SECURE_LIB__ + char *env_path = NULL; + size_t env_path_sz = 0; + _dupenv_s(&env_path, &env_path_sz, "PATH"); +#else char *env_path = getenv("PATH"); +#endif if (env_path != NULL) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(buffer, sizeof(buffer), env_path, 4096); +#else strncpy(buffer, env_path, 4096); +#endif buffer[4095] = 0; +#if __STDC_WANT_SECURE_LIB__ + char *next_tok1 = NULL; + char *next_tok2 = NULL; + char *tok = strtok_s(buffer, PATH_SEP, &next_tok1); +#else char *tok = strtok(buffer, PATH_SEP); +#endif while (tok) { snprintf(env_path, 4096, "%s%c%s", tok, kFileSep, EXE_NAME); @@ -499,13 +522,21 @@ const char* FindConfigFile(const char *name) return path2; } } +#if __STDC_WANT_SECURE_LIB__ + tok = strtok_s(NULL, PATH_SEP, &next_tok2); +#else tok = strtok(NULL, PATH_SEP); +#endif } } } else { // executable is relative to some directory +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(buffer, sizeof(buffer), arg0); +#else strcpy(buffer, arg0); +#endif char *p = strrchr(buffer, kFileSep); if (p) { *p = 0; @@ -550,7 +581,11 @@ void SaveConfigFile() FILE *f = utilOpenFile(configFile, "w"); if (f == NULL) { char err_msg[4096] = "unknown error"; +#if __STDC_WANT_SECURE_LIB__ + strerror_s(err_msg, sizeof(err_msg), errno); +#else strncpy(err_msg, strerror(errno), 4096); +#endif fprintf(stderr, "Configuration file '%s' could not be written to: %s\n", configFile, err_msg); return; } @@ -633,7 +668,11 @@ static char *xstrdup(const char *s) return NULL; t = (char *)malloc(strlen(s) + 1); if (t) { +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(t, strlen(s) + 1, s); +#else strcpy(t, s); +#endif } return t; } @@ -659,7 +698,11 @@ int ReadOpts(int argc, char ** argv) { //char* cpy; //cpy = (char *)malloc(1 + strlen(optarg)); + //#if __STDC_WANT_SECURE_LIB__ + //strcpy_s(cpy, 1 + strlen(optarg), optarg); + //#else //strcpy(cpy, optarg); + //#endif //preparedCheatCodes[preparedCheats++] = cpy; std::string cpy = optarg; preparedCheatCodes[preparedCheats++] = cpy.c_str(); @@ -712,7 +755,11 @@ int ReadOpts(int argc, char ** argv) } else { patchNames[patchNum] = (char *)malloc(1 + strlen(optarg)); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(patchNames[patchNum], 1 + strlen(optarg), optarg); +#else strcpy(patchNames[patchNum], optarg); +#endif patchNum++; } break; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 20ffd1a6..e3f20057 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -388,9 +388,17 @@ char* sdlGetFilename(const char* name) char path[1024]; const char *_filename = strrchr(name, kFileSep); if (_filename) +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(path, sizeof(path), _filename + 1); +#else strcpy(path, _filename + 1); +#endif else +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(path, sizeof(path), name); +#else strcpy(path, name); +#endif return strdup(path); } @@ -432,7 +440,12 @@ FILE* sdlFindFile(const char* name) fprintf(stdout, "Searching current directory: %s\n", buffer); } +#if __STDC_WANT_SECURE_LIB__ + FILE* f = NULL; + fopen_s(&f, name, "r"); +#else FILE* f = fopen(name, "r"); +#endif if (f != NULL) { return f; } @@ -440,55 +453,105 @@ FILE* sdlFindFile(const char* name) if (strlen(homeDataDir)) { fprintf(stdout, "Searching home directory: %s\n", homeDataDir); snprintf(path, sizeof(path), "%s%c%s", homeDataDir, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) return f; } #ifdef _WIN32 +#if __STDC_WANT_SECURE_LIB__ + char* profileDir = NULL; + size_t profileDirSz = 0; + _dupenv_s(&profileDir, &profileDirSz, "USERPROFILE"); +#else char* profileDir = getenv("USERPROFILE"); +#endif if (profileDir != NULL) { fprintf(stdout, "Searching user profile directory: %s\n", profileDir); snprintf(path, sizeof(path), "%s%c%s", profileDir, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) return f; } if (!strchr(home, '/') && !strchr(home, '\\')) { +#if __STDC_WANT_SECURE_LIB__ + char* _path = NULL; + size_t _pathSz = 0; + _dupenv_s(&_path, &_pathSz, "PATH"); +#else char* _path = getenv("PATH"); +#endif if (_path != NULL) { fprintf(stdout, "Searching PATH\n"); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(buffer, sizeof(buffer), _path); +#else strcpy(buffer, _path); +#endif buffer[sizeof(buffer) - 1] = 0; +#if __STDC_WANT_SECURE_LIB__ + char* tok_next1 = NULL; + char* tok_next2 = NULL; + char* tok = strtok_s(buffer, PATH_SEP, &tok_next1); +#else char* tok = strtok(buffer, PATH_SEP); +#endif while (tok) { snprintf(path, sizeof(path), "%s%c%s", tok, kFileSep, EXE_NAME); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) { char path2[2048]; fclose(f); snprintf(path2, sizeof(path2), "%s%c%s", tok, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path2, "r"); +#else f = fopen(path2, "r"); +#endif if (f != NULL) { fprintf(stdout, "Found at %s\n", path2); return f; } } +#if __STDC_WANT_SECURE_LIB__ + tok = strtok_s(NULL, PATH_SEP, &tok_next2); +#else tok = strtok(NULL, PATH_SEP); +#endif } } } else { // executable is relative to some directory fprintf(stdout, "Searching executable directory\n"); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(buffer, sizeof(buffer), home); +#else strcpy(buffer, home); +#endif char* p = strrchr(buffer, kFileSep); if (p) { *p = 0; snprintf(path, sizeof(path), "%s%c%s", buffer, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) return f; } @@ -496,13 +559,21 @@ FILE* sdlFindFile(const char* name) #else // ! _WIN32 fprintf(stdout, "Searching data directory: %s\n", PKGDATADIR); snprintf(path, sizeof(path), "%s%c%s", PKGDATADIR, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) return f; fprintf(stdout, "Searching system config directory: %s\n", SYSCONF_INSTALL_DIR); snprintf(path, sizeof(path), "%s%c%s", SYSCONF_INSTALL_DIR, kFileSep, name); +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&f, path, "r"); +#else f = fopen(path, "r"); +#endif if (f != NULL) return f; #endif // ! _WIN32 @@ -631,7 +702,12 @@ static void sdlApplyPerImagePreferences() if (p) *p = 0; +#if __STDC_WANT_SECURE_LIB__ + char* token_next = NULL; + char* token = strtok_s(s, " \t\n\r=", &token_next); +#else char* token = strtok(s, " \t\n\r="); +#endif if (!token) continue; @@ -655,7 +731,12 @@ static void sdlApplyPerImagePreferences() if (p) *p = 0; +#if __STDC_WANT_SECURE_LIB__ + char* token_next = NULL; + char* token = strtok_s(s, " \t\n\r=", &token_next); +#else char* token = strtok(s, " \t\n\r="); +#endif if (!token) continue; if (strlen(token) == 0) @@ -663,7 +744,12 @@ static void sdlApplyPerImagePreferences() if (token[0] == '[') // starting another image settings break; +#if __STDC_WANT_SECURE_LIB__ + char* value_next = NULL; + char* value = strtok_s(NULL, "\t\n\r=", &value_next); +#else char* value = strtok(NULL, "\t\n\r="); +#endif if (value == NULL) continue; @@ -774,13 +860,25 @@ void sdlWriteBackupStateExchange(int from, int to, int backup) dmp = sdlStateName(from); stateNameOrig = (char*)realloc(stateNameOrig, strlen(dmp) + 1); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(stateNameOrig, strlen(dmp) + 1, dmp); +#else strcpy(stateNameOrig, dmp); +#endif dmp = sdlStateName(to); stateNameDest = (char*)realloc(stateNameDest, strlen(dmp) + 1); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(stateNameDest, strlen(dmp) + 1, dmp); +#else strcpy(stateNameDest, dmp); +#endif dmp = sdlStateName(backup); stateNameBack = (char*)realloc(stateNameBack, strlen(dmp) + 1); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(stateNameBack, strlen(dmp) + 1, dmp); +#else strcpy(stateNameBack, dmp); +#endif /* on POSIX, rename would not do anything anyway for identical names, but let's check it ourselves anyway */ if (to != backup) { @@ -2078,7 +2176,7 @@ int main(int argc, char** argv) if (optind < argc) { char* szFile = argv[optind]; - utilStripDoubleExtension(szFile, filename); + utilStripDoubleExtension(szFile, filename, sizeof(filename)); char* p = strrchr(filename, '.'); if (p) @@ -2173,7 +2271,11 @@ int main(int argc, char** argv) } else { soundInit(); cartridgeType = 0; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(filename, sizeof(filename), "gnu_stub"); +#else strcpy(filename, "gnu_stub"); +#endif g_rom = (uint8_t*)malloc(0x2000000); g_workRAM = (uint8_t*)calloc(1, 0x40000); g_bios = (uint8_t*)calloc(1, 0x4000); @@ -2678,7 +2780,11 @@ void systemConsoleMessage(const char* msg) struct tm now_time_broken; now_time = time(NULL); +#if __STDC_WANT_SECURE_LIB__ + localtime_s(&now_time_broken, &now_time); +#else now_time_broken = *(localtime(&now_time)); +#endif fprintf( stdout, "%02d:%02d:%02d %02d.%02d.%4d: %s\n", @@ -2697,10 +2803,18 @@ void systemScreenMessage(const char* msg) screenMessage = true; screenMessageTime = systemGetClock(); if (strlen(msg) > 20) { +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(screenMessageBuffer, sizeof(screenMessageBuffer), msg, 20); +#else strncpy(screenMessageBuffer, msg, 20); +#endif screenMessageBuffer[20] = 0; } else +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(screenMessageBuffer, sizeof(screenMessageBuffer), msg); +#else strcpy(screenMessageBuffer, msg); +#endif systemConsoleMessage(msg); } @@ -2799,7 +2913,11 @@ void log(const char* defaultMsg, ...) static FILE* out = NULL; if (out == NULL) { +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&out, "trace.log", "w"); +#else out = fopen("trace.log", "w"); +#endif } va_list valist; diff --git a/src/sdl/dictionary.c b/src/sdl/dictionary.c index d6841cb0..77807b1b 100644 --- a/src/sdl/dictionary.c +++ b/src/sdl/dictionary.c @@ -68,7 +68,11 @@ static char *xstrdup(const char *s) return NULL; t = (char *)malloc(strlen(s) + 1); if (t) { +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(t, strlen(s) + 1, s); +#else strcpy(t, s); +#endif } return t; } diff --git a/src/sdl/iniparser.c b/src/sdl/iniparser.c index 0de0b259..b2e0e899 100644 --- a/src/sdl/iniparser.c +++ b/src/sdl/iniparser.c @@ -13,6 +13,7 @@ #if __STDC_WANT_SECURE_LIB__ #define snprintf sprintf_s +#define sscanf sscanf_s #endif /*---------------------------- Defines -------------------------------------*/ @@ -89,7 +90,11 @@ static char *strstrip(const char *s) while (isspace((int)*s) && *s) s++; memset(l, 0, ASCIILINESZ + 1); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(l, sizeof(l), s); +#else strcpy(l, s); +#endif last = l + strlen(l); while (last > l) { if (!isspace((int)*(last - 1))) @@ -577,7 +582,11 @@ static line_status iniparser_line(const char *input_line, char *section, char *k char line[ASCIILINESZ + 1]; int len; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(line, sizeof(line), strstrip(input_line)); +#else strcpy(line, strstrip(input_line)); +#endif len = (int)strlen(line); sta = LINE_UNPROCESSED; @@ -589,6 +598,19 @@ static line_status iniparser_line(const char *input_line, char *section, char *k sta = LINE_COMMENT; } else if (line[0] == '[' && line[len - 1] == ']') { /* Section name */ +#if __STDC_WANT_SECURE_LIB__ + sscanf_s(line, "[%[^]]", section, (unsigned)_countof(section)); + strcpy_s(section, ASCIILINESZ, strstrip(section)); + strcpy_s(section, ASCIILINESZ, strlwc(section)); + sta = LINE_SECTION; + } else if (sscanf_s(line, "%[^=] = \"%[^\"]\"", key, (unsigned)_countof(key), value, (unsigned)_countof(value)) == 2 || + sscanf_s(line, "%[^=] = '%[^\']'", key, (unsigned)_countof(key), value, (unsigned)_countof(value)) == 2 || + sscanf_s(line, "%[^=] = %[^;#]", key, (unsigned)_countof(key), value, (unsigned)_countof(value)) == 2) { + /* Usual key=value, with or without comments */ + strcpy_s(key, ASCIILINESZ, strstrip(key)); + strcpy_s(key, ASCIILINESZ, strlwc(key)); + strcpy_s(value, ASCIILINESZ, strstrip(value)); +#else sscanf(line, "[%[^]]", section); strcpy(section, strstrip(section)); strcpy(section, strlwc(section)); @@ -596,10 +618,11 @@ static line_status iniparser_line(const char *input_line, char *section, char *k } else if (sscanf(line, "%[^=] = \"%[^\"]\"", key, value) == 2 || sscanf(line, "%[^=] = '%[^\']'", key, value) == 2 || sscanf(line, "%[^=] = %[^;#]", key, value) == 2) { - /* Usual key=value, with or without comments */ + /* Usual key=value, with or without comments */ strcpy(key, strstrip(key)); strcpy(key, strlwc(key)); strcpy(value, strstrip(value)); + #endif /* * sscanf cannot handle '' or "" as empty values * this is done here @@ -608,16 +631,26 @@ static line_status iniparser_line(const char *input_line, char *section, char *k value[0] = 0; } sta = LINE_VALUE; +#if __STDC_WANT_SECURE_LIB__ + } else if (sscanf_s(line, "%[^=] = %[;#]", key, (unsigned)_countof(key), value, (unsigned)_countof(value)) == 2 || + sscanf_s(line, "%[^=] %[=]", key, (unsigned)_countof(key), value, (unsigned)_countof(value)) == 2) { +#else } else if (sscanf(line, "%[^=] = %[;#]", key, value) == 2 || sscanf(line, "%[^=] %[=]", key, value) == 2) { +#endif /* * Special cases: * key= * key=; * key=# */ +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(key, ASCIILINESZ, strstrip(key)); + strcpy_s(key, ASCIILINESZ, strlwc(key)); +#else strcpy(key, strstrip(key)); strcpy(key, strlwc(key)); +#endif value[0] = 0; sta = LINE_VALUE; } else { @@ -658,7 +691,12 @@ dictionary *iniparser_load(const char *ininame) dictionary *dict; +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&in, ininame, "r"); + if (in == NULL) { +#else if ((in = fopen(ininame, "r")) == NULL) { +#endif fprintf(stderr, "iniparser: cannot open %s\n", ininame); return NULL; } diff --git a/src/wx/bin2c.c b/src/wx/bin2c.c index 6c6e40f7..73dc2532 100644 --- a/src/wx/bin2c.c +++ b/src/wx/bin2c.c @@ -48,9 +48,15 @@ const char* msg_prefix = "bin2c: "; void format_perror(const char* fmt, va_list args) { static char error_str[MSG_SIZE]; static char fmt_str[MSG_SIZE]; +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(fmt_str, sizeof(fmt_str), msg_prefix); + strncat_s(fmt_str, sizeof(fmt_str), fmt, MSG_SIZE - strlen(msg_prefix)); + vsprintf_s(error_str, MSG_SIZE, fmt_str, args); +#else strcpy(fmt_str, msg_prefix); strncat(fmt_str, fmt, MSG_SIZE - strlen(msg_prefix)); vsnprintf(error_str, MSG_SIZE, fmt_str, args); +#endif perror(error_str); } @@ -80,7 +86,11 @@ char* file_name_to_identifier(const char* file_name_cstr) { size_t file_name_len = 0; int between_tokens = 0; +#if __STDC_WANT_SECURE_LIB__ + mbstowcs_s(&file_name_len, file_name, WBUF_SIZE, file_name_cstr, BUF_SIZE - 1); +#else file_name_len = mbstowcs(file_name, file_name_cstr, BUF_SIZE - 1); +#endif if (file_name_len == (size_t)(-1)) { die("cannot convert '%s' to locale representation", file_name_cstr); } @@ -96,7 +106,12 @@ char* file_name_to_identifier(const char* file_name_cstr) { between_tokens = 0; } else if (!between_tokens) { +#if __STDC_WANT_SECURE_LIB__ + size_t identifier_ptr_sz = 0; + mbstowcs_s(&identifier_ptr_sz, identifier_ptr, WBUF_SIZE, "_", 1); +#else mbstowcs(identifier_ptr, "_", 1); +#endif identifier_ptr++; between_tokens = 1; } @@ -109,7 +124,13 @@ char* file_name_to_identifier(const char* file_name_cstr) { *identifier_ptr = 0; +#if __STDC_WANT_SECURE_LIB__ + size_t identifier_cstr_sz = 0; + wcstombs_s(&identifier_cstr_sz, identifier_cstr, BUF_SIZE, identifier, WBUF_SIZE - 1); + if (identifier_cstr_sz == (size_t)(-1)) +#else if (wcstombs(identifier_cstr, identifier, WBUF_SIZE - 1) == (size_t)(-1)) +#endif die("failed to convert wide character string to bytes"); free(file_name); @@ -151,10 +172,19 @@ void die_usage(const char* fmt, ...) { static char fmt_str[MSG_SIZE]; va_list args; va_start(args, fmt); +#if __STDC_WANT_SECURE_LIB__ + strcpy_s(fmt_str, sizeof(fmt_str), msg_prefix); +#else strcpy(fmt_str, msg_prefix); +#endif // Need to reserve 1 byte for the newline. +#if __STDC_WANT_SECURE_LIB__ + strncat_s(fmt_str, sizeof(fmt_str), fmt, MSG_SIZE - strlen(msg_prefix) - 1); + strcat_s(fmt_str, sizeof(fmt_str), "\n"); +#else strncat(fmt_str, fmt, MSG_SIZE - strlen(msg_prefix) - 1); strcat(fmt_str, "\n"); +#endif vfprintf(stderr, fmt_str, args); va_end(args); usage(1); @@ -200,7 +230,11 @@ int main(int argc, const char** argv) { if (!in_file_name || !strcmp(in_file_name, "-")) { in_file = stdin; } else { +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&in_file, in_file_name, "rb"); +#else in_file = fopen(in_file_name, "rb"); +#endif if (!in_file) { die("can't open input file '%s'", in_file_name); } @@ -209,7 +243,11 @@ int main(int argc, const char** argv) { if (!out_file_name || !strcmp(out_file_name, "-")) { out_file = stdout; } else { +#if __STDC_WANT_SECURE_LIB__ + fopen_s(&out_file, out_file_name, "w"); +#else out_file = fopen(out_file_name, "w"); +#endif if (!out_file) { die("can't open output file '%s'", out_file_name); } diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index ee60d8f9..25e5b7b1 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -67,6 +67,10 @@ const #undef wxvbam #endif +#if __STDC_WANT_SECURE_LIB__ +#define sscanf sscanf_s +#endif + #define GetXRCDialog(n) \ wxStaticCast(wxGetApp().frame->FindWindowByName(n), wxDialog) @@ -650,7 +654,11 @@ public: } else if (ce_desc != odesc) { *dirty = true; char* p = isgb ? gbCheatList[id].cheatDesc : cheatsList[id].desc; +#if __STDC_WANT_SECURE_LIB__ + strncpy_s(p, sizeof(cheatsList[0].desc), ce_desc.utf8_str(), sizeof(cheatsList[0].desc)); +#else strncpy(p, ce_desc.utf8_str(), sizeof(cheatsList[0].desc)); +#endif p[sizeof(cheatsList[0].desc) - 1] = 0; item1.SetId(id); item1.SetText(wxString(p, wxConvUTF8)); diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 2223f020..0307d1d8 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -107,8 +107,15 @@ int __stdcall WinMain(HINSTANCE hInstance, // https://github.com/dolphin-emu/dolphin/blob/6cf99195c645f54d54c72322ad0312a0e56bc985/Source/Core/DolphinQt/Main.cpp#L112 HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); if (console_attached && stdout_handle) { +#if __STDC_WANT_SECURE_LIB__ + FILE *ostream; + FILE *estream; + freopen_s(&ostream, "CONOUT$", "w", stdout); + freopen_s(&estream, "CONOUT$", "w", stderr); +#else freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); +#endif } // Set up logging. diff --git a/third_party/sfml/src/SFML/System/Utils.cpp b/third_party/sfml/src/SFML/System/Utils.cpp index a4aff623..00b8f6e9 100644 --- a/third_party/sfml/src/SFML/System/Utils.cpp +++ b/third_party/sfml/src/SFML/System/Utils.cpp @@ -56,7 +56,13 @@ std::FILE* openFile(const ghc::filesystem::path& filename, std::string mode) { #ifdef SFML_SYSTEM_WINDOWS const std::wstring wmode(mode.begin(), mode.end()); +#if __STDC_WANT_SECURE_LIB__ + std::FILE* ret = NULL; + _wfopen_s(&ret, filename.c_str(), wmode.data()); + return ret; +#else return _wfopen(filename.c_str(), wmode.data()); +#endif #else return std::fopen(filename.c_str(), mode.data()); #endif