Any splint experts out there?? I'm trying to use splint to statically analyze a large project I have in C. I'm seeing an excess number of bounds checking errors that are obviously not bounds errors. I wrote a small test program to try to isolate the problem, and noticed some really strange warnings when I ran splint on the code. I have 3 different examples. Here is the first:
int arr[3];
int main(void)
{
int i;
int var;
arr[3] = 0; // (1) warning with +bounds, no warning with +likely-bounds
return 0;
}
The arr[3]
assignment generates a warning when using +bounds
as I would expect, but does nothing when I use +likely-bounds
. What does +likely-bounds
even do? It seems to not work. The second example:
int arr[3];
int main(void)
{
int i;
int var;
for (i = 0; i < 3; i++)
var = arr[i]; // (2) warning, even though I'm within the bounds.
return 0;
}
In this example splint complains that I'm reading outside the bounds of the array ("A memory read references memory beyond the allocated storage.") for var = arr[i]
, even though I'm obviously not. This should be a warning because the values in array are not initialized, but that's not the warning I get. Initializing the last value in the array will clear the error (but initializing the first or second won't). Am I doing something wrong? In the third example:
int arr[3];
int main(void)
{
int i;
int var;
arr[3] = 0; // warning
for (i = 0; i < 4; i++)
var = arr[i]; // (3) no warning because arr[3] = 0 statement.
return 0;
}
A warning is generated for arr[3] = 0
, but not var = arr[i]
, even though it's obvious that the loop goes outside the bounds of the array. It looks like writing to the end of an array expands how large splint thinks the array is. How is that possible?
In short my questions are:
- What does the likely-bounds flag do?
- Is there any way that I can make splint give me legitimate errors that relate to going out of bounds?
- Is there any way to make splint not increase the size of arrays that are accessed past their bounds? Right now splint is reporting more than 750 warnings and I don't have time to verify each warning one by one.