diff --git a/source/frontends/sdl/imgui/sdlsettings.cpp b/source/frontends/sdl/imgui/sdlsettings.cpp index b9dfa074..1b779648 100644 --- a/source/frontends/sdl/imgui/sdlsettings.cpp +++ b/source/frontends/sdl/imgui/sdlsettings.cpp @@ -915,7 +915,7 @@ namespace sa2 { ImGui::PushID(nAddress); DisasmLine_t line; - const char* pSymbol = FindSymbolFromAddress(nAddress); + std::string const* pSymbol = FindSymbolFromAddress(nAddress); const int bDisasmFormatFlags = GetDisassemblyLine(nAddress, line); ImGui::TableNextRow(); @@ -979,7 +979,7 @@ namespace sa2 ImGui::TableNextColumn(); if (pSymbol) { - debuggerTextColored(FG_DISASM_SYMBOL, pSymbol); + debuggerTextColored(FG_DISASM_SYMBOL, pSymbol->c_str()); } ImGui::TableNextColumn(); diff --git a/source/linux/duplicates/Joystick.cpp b/source/linux/duplicates/Joystick.cpp index 388ec801..2716be94 100644 --- a/source/linux/duplicates/Joystick.cpp +++ b/source/linux/duplicates/Joystick.cpp @@ -58,8 +58,7 @@ void JoyLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { for (UINT n = 0; n < 4; n++) { - char str[sizeof(SS_YAML_KEY_PDL_INACTIVE_CYCLE) + 1]; - sprintf_s(str, sizeof(str), SS_YAML_KEY_PDL_INACTIVE_CYCLE, n); + const std::string str = StrFormat(SS_YAML_KEY_PDL_INACTIVE_CYCLE, n); yamlLoadHelper.LoadUint64(str); } } diff --git a/source/linux/libwindows/misc.h b/source/linux/libwindows/misc.h index ded5963b..a76d7408 100644 --- a/source/linux/libwindows/misc.h +++ b/source/linux/libwindows/misc.h @@ -28,6 +28,8 @@ #define IDYES 6 #define IDNO 7 +#define EINVAL 22 + BOOL WINAPI PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); int MessageBox(HWND, const char *, const char *, UINT); diff --git a/source/linux/libwindows/timeapi.h b/source/linux/libwindows/timeapi.h index a2ee00ac..a110435a 100644 --- a/source/linux/libwindows/timeapi.h +++ b/source/linux/libwindows/timeapi.h @@ -4,8 +4,6 @@ #include -typedef int errno_t; - #define _tzset tzset errno_t ctime_s(char * buf, size_t size, const time_t *time); diff --git a/source/linux/libwindows/wincompat.h b/source/linux/libwindows/wincompat.h index 71890be1..757cd209 100644 --- a/source/linux/libwindows/wincompat.h +++ b/source/linux/libwindows/wincompat.h @@ -206,6 +206,8 @@ typedef void * HWND; typedef LONG_PTR LPARAM; typedef UINT_PTR WPARAM; +typedef int errno_t; + #ifdef __cplusplus } #endif diff --git a/source/linux/libwindows/winstrings.h b/source/linux/libwindows/winstrings.h index a38b3a52..1ed567e2 100644 --- a/source/linux/libwindows/winstrings.h +++ b/source/linux/libwindows/winstrings.h @@ -1,6 +1,7 @@ #pragma once #include "wincompat.h" +#include "misc.h" #include #include @@ -18,8 +19,6 @@ int vsnprintf_s( #define _TRUNCATE ((size_t)-1) -#define sprintf_s snprintf - #define _strdup strdup #define _strtoui64 strtoull #define _vsntprintf vsnprintf @@ -51,3 +50,34 @@ inline bool IsCharUpper(char ch) { DWORD CharLowerBuff(LPTSTR lpsz, DWORD cchLength); LPSTR _strupr( LPSTR str ); + +// copied from +// https://github.com/wine-mirror/wine/blob/1d178982ae5a73b18f367026c8689b56789c39fd/dlls/msvcrt/heap.c#L833 +template +errno_t strncpy_s(char (&dest)[size], const char *src, size_t count) +{ + size_t end; + if (count != _TRUNCATE && count < size) + { + end = count; + } + else + { + end = size - 1; + } + + size_t i; + for (i = 0; i < end && src[i]; i++) + { + dest[i] = src[i]; + } + + if (!src[i] || end == count || count == _TRUNCATE) + { + dest[i] = '\0'; + return 0; + } + + dest[0] = '\0'; + return EINVAL; +}