[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 11 11:50:53 PST 2024
================
@@ -38,3 +38,17 @@ void constant_idx_unsafe(unsigned idx) {
// expected-note at -1{{change type of 'buffer' to 'std::array' to label it for hardening}}
buffer[10] = 0; // expected-note{{used in buffer access here}}
}
+
+void constant_id_string(unsigned idx) {
+ char safe_char = "abc"[1]; // no-warning
+ safe_char = ""[0];
+ safe_char = "\0"[0];
+
+ char abcd[5] = "abc";
+ abcd[2]; // no-warning
+
+ char unsafe_char = "abc"[3]; //expected-warning{{unsafe buffer access}}
+ unsafe_char = "abc"[-1]; //expected-warning{{unsafe buffer access}}
+ unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}}
----------------
jkorous-apple wrote:
Sorry, my bad. You're right
https://github.com/llvm/llvm-project/pull/115552
More information about the cfe-commits
mailing list