From 636082c835b4b2947630c98d1bbec66ff807f3aa Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 13 Aug 2025 13:05:52 +0200 Subject: [PATCH] token.cpp: use `snprintf()` to fix `-Wdeprecated-declarations` AppleClang warning ``` /Users/runner/work/cppcheck/cppcheck/lib/token.cpp:1611:21: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations] 1611 | sprintf(str, "\\x%02x", c); | ^ /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/_stdio.h:274:1: note: 'sprintf' has been explicitly marked deprecated here 274 | __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.") | ^ /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/sys/cdefs.h:218:48: note: expanded from macro '__deprecated_msg' 218 | #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg))) | ^ ``` --- lib/token.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index 98f79b4bb1d..44e62e21507 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1607,8 +1607,8 @@ static std::string stringFromTokenRange(const Token* start, const Token* end) else if (c >= ' ' && c <= 126) ret += c; else { - char str[10]; - sprintf(str, "\\x%02x", c); + char str[5]; + snprintf(str, sizeof(str), "\\x%02x", c); ret += str; } }