I stumbled over this when checking a Firmware (MSP430 16bit controller).
The description sounds like there is a serious error, because we really do not want to lose information.
Then i reduced it to the following code and i would say it is a FP. Or at least the description maybe could sound a bit more conservative? What would you say? Is it worth a ticket?
>typetruncLongCastAssignment.ctypedefunsignedlonguint32_t;staticuint32_tconstvalue=1U*1U;>"C:\Program Files\Cppcheck\cppcheck"--versionCppcheck1.81>"C:\Program Files\Cppcheck\cppcheck"--enable=all--debug-v"truncLongCastAssignment.c"CheckingtruncLongCastAssignment.c...Defines:Includes:Platform:win64[truncLongCastAssignment.c:3]:(style)intresultisassignedtolongvariable.Ifthevariableislongtoavoidlossofinformation,thenthereislossofinformation.Toavoidlossofinformationyoumustcastacalculationoperandtolong,forexample'l = a * b;'=>'l = (long)a * b;'.##file truncLongCastAssignment.c3:### Symbol database ###Scope:0000000000460630GlobalclassName:classDef:0000000000000000classStart:0000000000000000classEnd:0000000000000000nestedIn:0000000000000000definedType:0000000000000000nestedList[0]=()functionOf:0000000000000000function:0000000000000000_variableList[1]:0000000000000000##Value flow
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I stumbled over this when checking a Firmware (MSP430 16bit controller).
The description sounds like there is a serious error, because we really do not want to lose information.
Then i reduced it to the following code and i would say it is a FP. Or at least the description maybe could sound a bit more conservative? What would you say? Is it worth a ticket?
since we can clearly see there is not loss of precision, that is a false positive. Please report a ticket.
Thank you Daniel. I created the ticket: https://trac.cppcheck.net/ticket/8274