Skip to content

Commit 3122724

Browse files
authored
token.cpp: use snprintf() to fix -Wdeprecated-declarations AppleClang warning (#7744)
``` /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))) | ^ ```
1 parent a8ba17d commit 3122724

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/token.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,8 +1607,8 @@ static std::string stringFromTokenRange(const Token* start, const Token* end)
16071607
else if (c >= ' ' && c <= 126)
16081608
ret += c;
16091609
else {
1610-
char str[10];
1611-
sprintf(str, "\\x%02x", c);
1610+
char str[5];
1611+
snprintf(str, sizeof(str), "\\x%02x", c);
16121612
ret += str;
16131613
}
16141614
}

0 commit comments

Comments
 (0)