================ @@ -38,3 +38,17 @@ void constant_idx_unsafe(unsigned idx) { // expected-note@-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}} ---------------- malavikasamak wrote:
This I think should warn, as the length here including the null terminator is 1. https://github.com/llvm/llvm-project/pull/115552 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits