Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
678 | Not sure what you're referring to. AFAICT there are no tabs in this file. |
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
678 | oh, gerrit uses the >> symbol to mean "tab". is this tool just saying "indentation changed", not specifically "someone added a tab"? |
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
678 | Ah I see. Yes, I think that's correct, that it doesn't mean a tab here. |
LGTM % nits -- thanks for this! :)
clang/include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
836 | nit: s/Warning </Warning</ | |
838 | nit: please s/null/NUL/ for consistency with elsewhere | |
clang/lib/Sema/SemaChecking.cpp | ||
415 | optional: llvm generally prefers FunctionRefs for simplicity and speed. if it's easy to refactor to use those (seems like it may be), please do. otherwise, it's not a big deal. |
This doesn't seem to be working very well:
thakis@thakis:~/src/llvm-project$ cat test.cc #include <inttypes.h> #include <stdio.h> #include <stdint.h> int main() { uint16_t hextets[8]; int chars_scanned; char buf[] = "1234:5678:9abc:def0:1234:5678:9abc:def0"; sscanf(buf, "%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 ":%4" SCNx16 "%n", &hextets[0], &hextets[1], &hextets[2], &hextets[3], &hextets[4], &hextets[5], &hextets[6], &hextets[7], &chars_scanned); for (int i = 0; i < 8; ++i) printf("%x ", hextets[i]); printf("%d\n", chars_scanned); } thakis@thakis:~/src/llvm-project$ out/gn/bin/clang test.cc -Wall test.cc:9:3: warning: 'sscanf' may overflow; destination buffer in argument 9 has size 4, but the corresponding field width plus NUL byte is 5 [-Wfortify-source] sscanf(buf, ^ test.cc:9:3: warning: 'sscanf' may overflow; destination buffer in argument 10 has size 2, but the corresponding field width plus NUL byte is 5 [-Wfortify-source] 2 warnings generated. thakis@thakis:~/src/llvm-project$ ./a.out 1234 5678 9abc def0 1234 5678 9abc def0 39
- The warning is emitted twice, but doesn't point at code the 2nd time round
- That code looks correct to me (ie there shouldn't be any warnings), maybe %n isn't handled correctly?
- The diag points at the start of the scanf instead of at the faulty arg.
Especially 2 is breaking builds, so I'll revert this for now. Looks like a cool warning though, looking forward to the relanding :)
Only diagnose if conversion specifier is %s.
Give the location of the particular argument rather than the location of the function call.
Test to make sure we don't warn on %d.
Thanks for reverting. Here's another try.
This just shouldn't be warning on any specifier other than %s, so I fixed that.
As far as not pointing at code for the second warning, I verified manually that it does now point at code even when warning twice, but it doesn't seem to be feasible to include a test for that.
add tests for %c and %[ too? (it's genuinely unclear to me from a quick skim whether this patch covers them.)
nit: s/Warning </Warning</