From fb7a8886f147f169431d023a47776407aa1fb2ea Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Mon, 29 Mar 2021 13:56:19 -0600 Subject: [PATCH 1/3] Add more printflike macros. --- src/common/progress_callback.h | 16 ++++++++-------- src/common/string.h | 10 +++++----- src/common/string_util.h | 2 +- src/common/vulkan/util.h | 2 +- src/core/cpu_core.h | 2 +- src/core/host_interface.h | 14 +++++++------- src/frontend-common/cheevos.cpp | 1 + 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/common/progress_callback.h b/src/common/progress_callback.h index 9ea431cc1..65fb80581 100644 --- a/src/common/progress_callback.h +++ b/src/common/progress_callback.h @@ -23,7 +23,7 @@ public: virtual void SetProgressValue(u32 value) = 0; virtual void IncrementProgressValue() = 0; - void SetFormattedStatusText(const char* Format, ...); + void SetFormattedStatusText(const char* Format, ...) printflike(2, 3); virtual void DisplayError(const char* message) = 0; virtual void DisplayWarning(const char* message) = 0; @@ -34,13 +34,13 @@ public: virtual bool ModalConfirmation(const char* message) = 0; virtual void ModalInformation(const char* message) = 0; - void DisplayFormattedError(const char* format, ...); - void DisplayFormattedWarning(const char* format, ...); - void DisplayFormattedInformation(const char* format, ...); - void DisplayFormattedDebugMessage(const char* format, ...); - void DisplayFormattedModalError(const char* format, ...); - bool DisplayFormattedModalConfirmation(const char* format, ...); - void DisplayFormattedModalInformation(const char* format, ...); + void DisplayFormattedError(const char* format, ...) printflike(2, 3); + void DisplayFormattedWarning(const char* format, ...) printflike(2, 3); + void DisplayFormattedInformation(const char* format, ...) printflike(2, 3); + void DisplayFormattedDebugMessage(const char* format, ...) printflike(2, 3); + void DisplayFormattedModalError(const char* format, ...) printflike(2, 3); + bool DisplayFormattedModalConfirmation(const char* format, ...) printflike(2, 3); + void DisplayFormattedModalInformation(const char* format, ...) printflike(2, 3); void UpdateProgressFromStream(ByteStream* stream); diff --git a/src/common/string.h b/src/common/string.h index 05e145ed7..5cb2fdba6 100644 --- a/src/common/string.h +++ b/src/common/string.h @@ -104,7 +104,7 @@ public: void AppendSubString(const char* appendText, s32 Offset = 0, s32 Count = std::numeric_limits::max()); // append formatted string to this string - void AppendFormattedString(const char* FormatString, ...); + void AppendFormattedString(const char* FormatString, ...) printflike(2, 3); void AppendFormattedStringVA(const char* FormatString, va_list ArgPtr); // append a single character to this string @@ -122,7 +122,7 @@ public: void PrependSubString(const char* appendText, s32 Offset = 0, s32 Count = std::numeric_limits::max()); // append formatted string to this string - void PrependFormattedString(const char* FormatString, ...); + void PrependFormattedString(const char* FormatString, ...) printflike(2, 3); void PrependFormattedStringVA(const char* FormatString, va_list ArgPtr); // insert a string at the specified offset @@ -133,7 +133,7 @@ public: void InsertString(s32 offset, const std::string_view& appendStr); // set to formatted string - void Format(const char* FormatString, ...); + void Format(const char* FormatString, ...) printflike(2, 3); void FormatVA(const char* FormatString, va_list ArgPtr); // compare one string to another @@ -229,7 +229,7 @@ public: } // creates a new string from the specified format - static String FromFormat(const char* FormatString, ...); + static String FromFormat(const char* FormatString, ...) printflike(1, 2); // accessor operators // const char &operator[](u32 i) const { DebugAssert(i < m_pStringData->StringLength); return @@ -345,7 +345,7 @@ public: } // Override the fromstring method - static StackString FromFormat(const char* FormatString, ...) + static StackString FromFormat(const char* FormatString, ...) printflike(1, 2) { va_list argPtr; va_start(argPtr, FormatString); diff --git a/src/common/string_util.h b/src/common/string_util.h index 54cad5872..02f75c291 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -21,7 +21,7 @@ namespace StringUtil { /// Constructs a std::string from a format string. -std::string StdStringFromFormat(const char* format, ...); +std::string StdStringFromFormat(const char* format, ...) printflike(1, 2); std::string StdStringFromFormatV(const char* format, std::va_list ap); /// Checks if a wildcard matches a search string. diff --git a/src/common/vulkan/util.h b/src/common/vulkan/util.h index 1787627eb..dfdde6cb3 100644 --- a/src/common/vulkan/util.h +++ b/src/common/vulkan/util.h @@ -74,7 +74,7 @@ VkShaderModule CompileAndCreateFragmentShader(std::string_view source_code); VkShaderModule CompileAndCreateComputeShader(std::string_view source_code); const char* VkResultToString(VkResult res); -void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...); +void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...) printflike(4, 5); #define LOG_VULKAN_ERROR(res, ...) ::Vulkan::Util::LogVulkanResult(1, __func__, res, __VA_ARGS__) diff --git a/src/core/cpu_core.h b/src/core/cpu_core.h index c91991537..98ecb228f 100644 --- a/src/core/cpu_core.h +++ b/src/core/cpu_core.h @@ -148,7 +148,7 @@ void DisassembleAndLog(u32 addr); void DisassembleAndPrint(u32 addr, u32 instructions_before, u32 instructions_after); // Write to CPU execution log file. -void WriteToExecutionLog(const char* format, ...); +void WriteToExecutionLog(const char* format, ...) printflike(1, 2); // Trace Routines bool IsTraceEnabled(); diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 20edd48ab..bba76465e 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -64,23 +64,23 @@ public: virtual void ReportDebuggerMessage(const char* message); virtual bool ConfirmMessage(const char* message); - void ReportFormattedError(const char* format, ...); - void ReportFormattedMessage(const char* format, ...); - void ReportFormattedDebuggerMessage(const char* format, ...); - bool ConfirmFormattedMessage(const char* format, ...); + void ReportFormattedError(const char* format, ...) printflike(2, 3); + void ReportFormattedMessage(const char* format, ...) printflike(2, 3); + void ReportFormattedDebuggerMessage(const char* format, ...) printflike(2, 3); + bool ConfirmFormattedMessage(const char* format, ...) printflike(2, 3); /// Adds OSD messages, duration is in seconds. virtual void AddOSDMessage(std::string message, float duration = 2.0f); - void AddFormattedOSDMessage(float duration, const char* format, ...); + void AddFormattedOSDMessage(float duration, const char* format, ...) printflike(3, 4); /// Returns the base user directory path. ALWAYS_INLINE const std::string& GetUserDirectory() const { return m_user_directory; } /// Returns a path relative to the user directory. - std::string GetUserDirectoryRelativePath(const char* format, ...) const; + std::string GetUserDirectoryRelativePath(const char* format, ...) const printflike(2, 3); /// Returns a path relative to the application directory (for system files). - std::string GetProgramDirectoryRelativePath(const char* format, ...) const; + std::string GetProgramDirectoryRelativePath(const char* format, ...) const printflike(2, 3); /// Returns a string which can be used as part of a filename, based on the current date/time. static TinyString GetTimestampStringForFileName(); diff --git a/src/frontend-common/cheevos.cpp b/src/frontend-common/cheevos.cpp index c7c1ffa08..cb20db0cb 100644 --- a/src/frontend-common/cheevos.cpp +++ b/src/frontend-common/cheevos.cpp @@ -85,6 +85,7 @@ static ALWAYS_INLINE CommonHostInterface* GetHostInterface() return static_cast(g_host_interface); } +static void FormattedError(const char* format, ...) printflike(2, 3); static void FormattedError(const char* format, ...) { std::va_list ap; From e4735bcf7a3ef11fee974bfa13bce392d9392b21 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Mon, 29 Mar 2021 13:59:22 -0600 Subject: [PATCH 2/3] Fix string formatting warnings. --- src/common/cd_image_memory.cpp | 2 +- src/core/host_interface.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/cd_image_memory.cpp b/src/common/cd_image_memory.cpp index c8be96949..fa1d1121c 100644 --- a/src/common/cd_image_memory.cpp +++ b/src/common/cd_image_memory.cpp @@ -61,7 +61,7 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress) static_cast(std::malloc(static_cast(RAW_SECTOR_SIZE) * static_cast(m_memory_sectors))); if (!m_memory) { - progress->DisplayFormattedModalError("Failed to allocate memory for %llu sectors", m_memory_sectors); + progress->DisplayFormattedModalError("Failed to allocate memory for %u sectors", m_memory_sectors); return false; } diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 8d7373c83..ec87c62fa 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -101,7 +101,7 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters) if (!AcquireHostDisplay()) { - ReportFormattedError(g_host_interface->TranslateString("System", "Failed to acquire host display.")); + ReportError(g_host_interface->TranslateString("System", "Failed to acquire host display.")); OnSystemDestroyed(); return false; } @@ -118,7 +118,7 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters) { if (!System::IsStartupCancelled()) { - ReportFormattedError( + ReportError( g_host_interface->TranslateString("System", "System failed to boot. The log may contain more information.")); } From b8e85798a63422dd20989760f21944f17b24bd26 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Mon, 29 Mar 2021 14:04:23 -0600 Subject: [PATCH 3/3] Fix wrong printflike for FormattedError in Cheevos. --- src/frontend-common/cheevos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend-common/cheevos.cpp b/src/frontend-common/cheevos.cpp index cb20db0cb..08a648b2e 100644 --- a/src/frontend-common/cheevos.cpp +++ b/src/frontend-common/cheevos.cpp @@ -85,7 +85,7 @@ static ALWAYS_INLINE CommonHostInterface* GetHostInterface() return static_cast(g_host_interface); } -static void FormattedError(const char* format, ...) printflike(2, 3); +static void FormattedError(const char* format, ...) printflike(1, 2); static void FormattedError(const char* format, ...) { std::va_list ap;