Menu

FP truncLongCastAssignment?

versat
2017-11-10
2017-11-10
  • versat

    versat - 2017-11-10

    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?

    >type truncLongCastAssignment.c
    typedef unsigned long  uint32_t;
    
    static uint32_t const value = 1U * 1U;
    
    >"C:\Program Files\Cppcheck\cppcheck" --version
    Cppcheck 1.81
    
    >"C:\Program Files\Cppcheck\cppcheck" --enable=all --debug -v "truncLongCastAssignment.c"
    Checking truncLongCastAssignment.c ...
    Defines:
    Includes:
    Platform:win64
    [truncLongCastAssignment.c:3]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'l = a * b;' => 'l = (long)a * b;'.
    
    ##file truncLongCastAssignment.c
    3:
    
    ### Symbol database ###
    Scope: 0000000000460630 Global
        className:
        classDef: 0000000000000000
        classStart: 0000000000000000
        classEnd: 0000000000000000
        nestedIn: 0000000000000000
        definedType: 0000000000000000
        nestedList[0] = ( )
        functionOf: 0000000000000000
        function: 0000000000000000
    _variableList[1]: 0000000000000000
    
    ##Value flow
    
     
  • Daniel Marjamäki

    since we can clearly see there is not loss of precision, that is a false positive. Please report a ticket.

     
  • versat

    versat - 2017-11-13

    Thank you Daniel. I created the ticket: https://trac.cppcheck.net/ticket/8274

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.