From 09cc7e2ddfa40190172eb38d4448c35f5e761cdb Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Fri, 7 Feb 2014 01:10:04 +1300 Subject: [PATCH 1/2] Give StringFromFormat a printf format attribute. It gives StringFromFormat printf style arguments that should be type-checked against a format string. --- Source/Core/Common/StringUtil.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 46ed382724..7846cbee3d 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -14,7 +14,14 @@ #include "Common.h" -std::string StringFromFormat(const char* format, ...); +std::string StringFromFormat(const char* format, ...) +#if !defined _WIN32 +// On compilers that support function attributes, this gives StringFromFormat +// the same errors and warnings that printf would give. + __attribute__ ((__format__(printf, 1, 2))) +#endif +; + // Cheap! bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args); From 70d2592ffbbb2252d5ac998ce4d3200175a5951c Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Fri, 7 Feb 2014 01:38:08 +1300 Subject: [PATCH 2/2] Fix warnings found by StringFromFormat having printf style checking. --- Source/Core/Common/Timer.cpp | 2 +- Source/Core/Core/CoreTiming.cpp | 2 +- Source/Core/Core/HLE/HLE_OS.cpp | 2 +- Source/Core/Core/PowerPC/PPCTables.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index b7ae848970..267755fb17 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -113,7 +113,7 @@ std::string Timer::GetTimeElapsedFormatted() const // Hours u32 Hours = Minutes / 60; - std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", + std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03lu", Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000); return TmpStr; } diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 5461692a22..ace2c9759c 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -469,7 +469,7 @@ std::string GetScheduledEventsSummary() if (!name) name = "[unknown]"; - text += StringFromFormat("%s : %i %08x%08x\n", name, ptr->time, ptr->userdata >> 32, ptr->userdata); + text += StringFromFormat("%s : %li %08lx%08lx\n", name, ptr->time, ptr->userdata >> 32, ptr->userdata); ptr = ptr->next; } return text; diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp index ed80a68154..ed02672110 100644 --- a/Source/Core/Core/HLE/HLE_OS.cpp +++ b/Source/Core/Core/HLE/HLE_OS.cpp @@ -155,7 +155,7 @@ void GetStringVA(std::string& _rOutBuffer, u32 strReg) case 'p': // Override, so 64bit dolphin prints 32bit pointers, since the ppc is 32bit :) - _rOutBuffer += StringFromFormat("%x", Parameter); + _rOutBuffer += StringFromFormat("%x", (u32)Parameter); break; default: diff --git a/Source/Core/Core/PowerPC/PPCTables.cpp b/Source/Core/Core/PowerPC/PPCTables.cpp index 758fbae6c9..ce7d299f92 100644 --- a/Source/Core/Core/PowerPC/PPCTables.cpp +++ b/Source/Core/Core/PowerPC/PPCTables.cpp @@ -231,7 +231,7 @@ void LogCompiledInstructions() } #ifdef OPLOG - f.Open(StringFromFormat("%s" OP_TO_LOG "_at.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), "w"); + f.Open(StringFromFormat("%s" OP_TO_LOG "_at%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), "w"); for (auto& rsplocation : rsplocations) { fprintf(f.GetHandle(), OP_TO_LOG ": %08x\n", rsplocation);