From 63e623ecb2d3c191940049a0ee59c5195c10803a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Dec 2021 09:40:40 -0800 Subject: [PATCH] Build: Fix some format truncation warnings. Generally all should be safe already, but better to be sure. --- Common/GPU/Shader.h | 2 +- Common/Math/expression_parser.cpp | 2 +- Common/TimeUtil.cpp | 14 ++++++-------- Core/HLE/sceUtility.cpp | 2 +- Core/MIPS/MIPSDis.cpp | 13 +++++++++---- Core/Util/DisArm64.cpp | 2 +- Core/Util/PortManager.cpp | 12 ++++++------ UI/ControlMappingScreen.cpp | 2 +- ext/disarm.cpp | 2 +- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Common/GPU/Shader.h b/Common/GPU/Shader.h index 4fc5ba4f0a..3e21cd9a9c 100644 --- a/Common/GPU/Shader.h +++ b/Common/GPU/Shader.h @@ -55,7 +55,7 @@ struct ShaderLanguageDesc { bool bitwiseOps = false; bool forceMatrix4x4 = false; bool coefsFromBuffers = false; - char driverInfo[128]; // Really only GL uses this. + char driverInfo[256]; // Really only GL uses this. }; enum class UniformType : int8_t { diff --git a/Common/Math/expression_parser.cpp b/Common/Math/expression_parser.cpp index e24c056a07..1b9ed7ba90 100644 --- a/Common/Math/expression_parser.cpp +++ b/Common/Math/expression_parser.cpp @@ -14,7 +14,7 @@ typedef enum { typedef enum { EXCOMM_CONST, EXCOMM_CONST_FLOAT, EXCOMM_REF, EXCOMM_OP } ExpressionCommand; -static char expressionError[256]; +static char expressionError[512]; typedef struct { char Name[4]; diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index 08f48e742a..50718df979 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -66,24 +66,22 @@ void sleep_ms(int ms) { // Return the current time formatted as Minutes:Seconds:Milliseconds // in the form 00:00:000. -void GetTimeFormatted(char formattedTime[13]) { +void GetTimeFormatted(char formattedTime[11]) { time_t sysTime; - struct tm * gmTime; - char tmp[13]; - time(&sysTime); - gmTime = localtime(&sysTime); - strftime(tmp, 6, "%M:%S", gmTime); + struct tm *gmTime = localtime(&sysTime); + char tmp[6]; + strftime(tmp, sizeof(tmp), "%M:%S", gmTime); // Now tack on the milliseconds #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); - snprintf(formattedTime, 13, "%s:%03i", tmp, tp.millitm); + snprintf(formattedTime, 11, "%s:%03i", tmp, tp.millitm); #else struct timeval t; (void)gettimeofday(&t, NULL); - snprintf(formattedTime, 13, "%s:%03d", tmp, (int)(t.tv_usec / 1000)); + snprintf(formattedTime, 11, "%s:%03d", tmp, (int)(t.tv_usec / 1000)); #endif } diff --git a/Core/HLE/sceUtility.cpp b/Core/HLE/sceUtility.cpp index f3b473fc92..437278cf3e 100644 --- a/Core/HLE/sceUtility.cpp +++ b/Core/HLE/sceUtility.cpp @@ -146,7 +146,7 @@ static void CleanupDialogThreads(bool force = false) { accessThread = nullptr; accessThreadState = "cleaned up"; } else if (force) { - ERROR_LOG_REPORT(SCEUTILITY, "Utility access thread still running, state: %s, dialog=%d/%d", accessThreadState, currentDialogType, currentDialogActive); + ERROR_LOG_REPORT(SCEUTILITY, "Utility access thread still running, state: %s, dialog=%d/%d", accessThreadState, (int)currentDialogType, currentDialogActive); // Try to force shutdown anyway. accessThread->Terminate(); diff --git a/Core/MIPS/MIPSDis.cpp b/Core/MIPS/MIPSDis.cpp index c1c61f6a9c..22d1e05b21 100644 --- a/Core/MIPS/MIPSDis.cpp +++ b/Core/MIPS/MIPSDis.cpp @@ -365,22 +365,27 @@ namespace MIPSDis void Dis_Emuhack(MIPSOpcode op, char *out) { auto resolved = Memory::Read_Instruction(disPC, true); - char disasm[256]; + union { + char disasm[256]; + char truncated[241]; + }; if (MIPS_IS_EMUHACK(resolved)) { strcpy(disasm, "(invalid emuhack)"); } else { MIPSDisAsm(resolved, disPC, disasm, true); } + // Truncate in case it was too long, just to avoid warnings. + truncated[240] = '\0'; switch (op.encoding >> 24) { case 0x68: - snprintf(out, 256, "* jitblock: %s", disasm); + snprintf(out, 256, "* jitblock: %s", truncated); break; case 0x6a: - snprintf(out, 256, "* replacement: %s", disasm); + snprintf(out, 256, "* replacement: %s", truncated); break; default: - snprintf(out, 256, "* (invalid): %s", disasm); + snprintf(out, 256, "* (invalid): %s", truncated); break; } } diff --git a/Core/Util/DisArm64.cpp b/Core/Util/DisArm64.cpp index 5d1afbe786..b03fc0d111 100644 --- a/Core/Util/DisArm64.cpp +++ b/Core/Util/DisArm64.cpp @@ -206,7 +206,7 @@ static const char *GetSystemRegName(int o0, int op1, int CRn, int CRm, int op2) } static void BranchExceptionAndSystem(uint32_t w, uint64_t addr, Instruction *instr, SymbolCallback symbolCallback) { - char buffer[128]; + char buffer[125]; int Rt = w & 0x1f; int Rn = (w >> 5) & 0x1f; if (((w >> 26) & 0x1F) == 5) { diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index 0bd27db7db..20ffaeb79e 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -340,7 +340,7 @@ bool PortManager::Clear() { #ifdef WITH_UPNP int r; int i = 0; - char index[6]; + char index[16]; char intAddr[40]; char intPort[6]; char extPort[6]; @@ -359,7 +359,7 @@ bool PortManager::Clear() { //unsigned int num = 0; //UPNP_GetPortMappingNumberOfEntries(urls->controlURL, datas->first.servicetype, &num); // Not supported by many routers do { - snprintf(index, 6, "%d", i); + snprintf(index, sizeof(index), "%d", i); rHost[0] = '\0'; enabled[0] = '\0'; duration[0] = '\0'; desc[0] = '\0'; protocol[0] = '\0'; extPort[0] = '\0'; intPort[0] = '\0'; intAddr[0] = '\0'; @@ -387,7 +387,7 @@ bool PortManager::Clear() { } } i++; - } while (r == 0); + } while (r == 0 && i < 65536); return true; #else return false; @@ -398,7 +398,7 @@ bool PortManager::RefreshPortList() { #ifdef WITH_UPNP int r; int i = 0; - char index[6]; + char index[16]; char intAddr[40]; char intPort[6]; char extPort[6]; @@ -419,7 +419,7 @@ bool PortManager::RefreshPortList() { //unsigned int num = 0; //UPNP_GetPortMappingNumberOfEntries(urls->controlURL, datas->first.servicetype, &num); // Not supported by many routers do { - snprintf(index, 6, "%d", i); + snprintf(index, sizeof(index), "%d", i); rHost[0] = '\0'; enabled[0] = '\0'; duration[0] = '\0'; desc[0] = '\0'; protocol[0] = '\0'; extPort[0] = '\0'; intPort[0] = '\0'; intAddr[0] = '\0'; @@ -444,7 +444,7 @@ bool PortManager::RefreshPortList() { } } i++; - } while (r == 0); + } while (r == 0 && i < 65536); return true; #else return false; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 2120435efc..9058f52960 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -809,7 +809,7 @@ void TouchTestScreen::render() { ui_context->Begin(); - char buffer[2048]; + char buffer[4096]; for (int i = 0; i < MAX_TOUCH_POINTS; i++) { if (touches_[i].id != -1) { ui_context->Draw()->Circle(touches_[i].x, touches_[i].y, 100.0, 3.0, 80, 0.0f, 0xFFFFFFFF, 1.0); diff --git a/ext/disarm.cpp b/ext/disarm.cpp index 8f665d0f9a..45e01fdef2 100644 --- a/ext/disarm.cpp +++ b/ext/disarm.cpp @@ -422,7 +422,7 @@ static bool DisasmNeonImmVal(uint32_t op, char *text) { int quad = (op >> 6) & 1; const char *operation = "MOV"; const char *size = "(unk)"; - char temp[256] = "(unk)"; + char temp[64] = "(unk)"; switch (cmode) { case VIMM___x___x: case VIMM___x___x + 1: