[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 9 16:11:49 PST 2024
================
@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s bugprone-undefined-sprintf-overlap %t
+
+using size_t = decltype(sizeof(int));
+
+extern "C" int sprintf(char *s, const char *format, ...);
+extern "C" int snprintf(char *s, size_t n, const char *format, ...);
+
+namespace std {
+ int snprintf(char *s, size_t n, const char *format, ...);
+}
+
+struct st_t {
+ char buf[10];
+ char buf2[10];
+};
+
+void first_arg_overlaps() {
+ char buf[10];
+ sprintf(buf, "%s", buf);
----------------
nicovank wrote:
Add a test case where `buf` is the the first argument, e.g. `sprintf(buf, "%d%s", 0, buf);` to catch possible regressions.
https://github.com/llvm/llvm-project/pull/114244
More information about the cfe-commits
mailing list