-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visual Studio static analyzer warnings #305
Comments
Thanks for taking the time to report this. Is this for cJSON 1.7.8 ? It seems to me like maybe some of the warnings belong to different lines than what I looked at? Let's take a look at the issues? Arithmetic Overflow 1 & 2
Line 327 in 08103f0
Line 349 in 08103f0
This doesn't make any sense to me. Not only are there no 4 byte values in cJSON nor is there any cast to any 8 byte value or any subtractions involved. Dereferencing NULL
Lines 1367 to 1371 in 08103f0
In isolation this could be a Lines 1346 to 1349 in 08103f0
BUT there is only one place where Lines 1253 to 1256 in 08103f0
And this ensures that Line 260 in 08103f0
Arithmetic Overflow 3
Lines 1678 to 1679 in 08103f0
Arithmetic Overflow 4cjson\cjson.c(2303): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). Line 2303 in 08103f0
?? Same as the first two. Doesn't really make sense to me. |
Is this static analysis option built in directly to Visual Studio? |
Hi Max, Correct, this was using cJSON 1.7.8, and the lines match up with what I'm seeing. This functionality is built into Visual Studio, more information can be found here: For arithmetic overflow 1 and 2, For the null pointer dereference, I think the analyzer is not taking the holistic view that you are, it's only looking at that function in isolation. Imagine if a new call site was added that passed a null pointer for For arithmetic overflow 3, it's pretty silly since both sides of the For arithmetic overflow 4, it's the same as 1 and 2, casting So the overall the patch for these reported issues might look like this:
If that works for you I can put together a pull request. Thanks, |
Yesterday was too late ... of course
I don't want to do anything about that at the moment. But I'll consider using
Casting to I would be glad to accept a pull request! |
Hi,
I just ran the VStudio static analyzer on cJSON, and it reported these issues (which generally look pretty minor):
I can put together a pull request to address these if you'd like.
Thanks,
Benbuck
The text was updated successfully, but these errors were encountered: