1// This function finds the positions of the nibbles in the checksum table2voidCDataCodec::FindPosInChecksumTable(uint8u8Data,int32*pi32Low,int32*pi32High)const3{4try5{6CHECK_MEM_LEAKS78uint8u8Nibble;910// Set the low nibble11u8Nibble=uint8(u8Data&0xf0);1213// Find the low nibble in the checksum look-up table14for(*pi32Low=0;*pi32Low<16;(*pi32Low)++)15{16// Do we have the correct low nibble value?17if(u8Nibble==uint8(g_u8ChecksumTable[*pi32Low]&0xf0))18break;19}2021// Set the high nibble22u8Nibble=uint8(u8Data&0x0f);2324// Find the high nibble in the checksum look-up table25for(*pi32High=0;*pi32High<16;(*pi32High)++)26{27// Do we have the correct high nibble value?28if(u8Nibble==uint8(g_u8ChecksumTable[*pi32High]&0x0f))29break;30}31}32catch(...){OnException(nullptr,__FILE__,__LINE__,__FUNCSIG__,__TIMESTAMP__,nullptr);}33}
But, I get 2 errors stating:
line 14 : 'Condition '*pi32Low<16' is always true'
line 25 : 'Condition '*pi32High<16' is always true'*
Clearly, the value of pi32Low and pi32High can be [0,MAX_INT32] (after initialization in the for loop)?
Last edit: Sander Bouwhuis 2019-08-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Seems to be another false positive, i can reproduce this with 1.89 dev.
The values clearly can be from 0 to 16 in the for loops. And the loops are exited when 16 is reached.
Here is a small compilable example that shows the false positive:
I have the following function:
But, I get 2 errors stating:
Clearly, the value of pi32Low and pi32High can be [0,MAX_INT32] (after initialization in the for loop)?
Last edit: Sander Bouwhuis 2019-08-30
Seems to be another false positive, i can reproduce this with 1.89 dev.
The values clearly can be from 0 to 16 in the for loops. And the loops are exited when 16 is reached.
Here is a small compilable example that shows the false positive:
Output of Cppcheck 1.89 dev:
I found a ticket that looks related and added your example: https://trac.cppcheck.net/ticket/9036
Thanks for reporting!