ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.12k stars 267 forks source link

cppcheck analyzer issues #75

Closed pavelxdd closed 2 years ago

pavelxdd commented 2 years ago

There are some issues I found when checking yyjson with cppcheck.

https://github.com/ibireme/yyjson/blob/94e47ab18019129124099036ac1a1a02c5fc9b52/src/yyjson.h#L4156 The assignment of pre_key is useless, since it's never used.

https://github.com/ibireme/yyjson/blob/94e47ab18019129124099036ac1a1a02c5fc9b52/src/yyjson.c#L4129-L4130 https://github.com/ibireme/yyjson/blob/94e47ab18019129124099036ac1a1a02c5fc9b52/src/yyjson.c#L6560-L6562 Expressions after goto or return are unreachable. repeat16_incr will never be executed.

https://github.com/ibireme/yyjson/blob/94e47ab18019129124099036ac1a1a02c5fc9b52/src/yyjson.c#L5524 (file_size + 1) < 0 is always false. If you wanted to check for long overflow then this is undefined bahaviour (signed integer overflow is UB).

https://github.com/ibireme/yyjson/blob/94e47ab18019129124099036ac1a1a02c5fc9b52/src/yyjson.c#L5482 hdr is always not NULL, since it's checked after malloc.

ibireme commented 2 years ago

Thanks, I checked it before with clang analyzer, but the last two issues were not detected.

Fixed at: https://github.com/ibireme/yyjson/commit/5cb87def66ebba024e7bb8f42ecb648649f7ffde

ibireme commented 2 years ago

The repeat16_incr will never be executed warning is not accurate, the code will be executed when the repeat16_incr macro is expanded.