I saw a false positive where the analyzer made wrong conclusions about a static variable.
Static variables that are not written have known values (initialized values).
This is the (simplified) code that motivated me to create this patch:
static char *allv[] = { "rpcgen", "-s", "udp", "-s", "tcp", }; static int allc = sizeof(allv) / sizeof(allv[0]); static void f(void) { int i; for (i = 1; i < allc; i++) { const char *p = allv[i]; // <- line 28 i++; } }
Clang output:
array-fp3.c:28:19: warning: Access out-of-bound array element (buffer overflow) const char *p = allv[i]; ^~~~~~~
I added testcases that shows this patch solves both false positives and false negatives
A hint, even if we don't use visitors: the whole point of having a visitor is about not needing to make a pattern-matching (switch or sequence of dyn_casts) by statement kind yourself, like you do in this function. You already have VisitUnaryOperator, VisitBinaryOperator, VisitCallExpr, etc., so you can add the code there.