Menu

cppcheck 2.6 : wrong assumption of "assigned value is never 0"

fenugrec
2021-12-11
2021-12-11
  • fenugrec

    fenugrec - 2021-12-11

    Hi,
    I'm having what appears to be a false positive, compiling this section, where it goes through two elements of a linked-list :

        msg = msg->next;
        if (msg == NULL) {
            return CMD_OK;
        }
    
        msg = msg->next;
        if (msg == NULL) {
            return CMD_OK;
        }
    

    (complete file: https://github.com/fenugrec/freediag/blob/master/scantool/scantool_850.c#L1240 )

    cppcheck complains about that :


    scantool/scantool_850.c:1241:10: style: Condition 'msg==NULL' is always false [knownConditionTrueFalse]
    if (msg == NULL) {
    ^
    scantool/scantool_850.c:1233:10: note: Assuming that condition 'msg==NULL' is not redundant
    if (msg == NULL) {
    ^
    scantool/scantool_850.c:1232:6: note: msg is assigned 'msg->next' here.
    msg = msg->next;
    ^
    scantool/scantool_850.c:1233:10: note: Assuming condition is false
    if (msg == NULL) {
    ^
    scantool/scantool_850.c:1240:11: note: Assignment 'msg=msg->next', assigned value is never 0
    msg = msg->next;
    ^
    scantool/scantool_850.c:1241:10: note: Condition 'msg==NULL' is always false
    if (msg == NULL) {


    Of course the issue is "msg->next" means something different the second time, and can be 0, but cppcheck fails to recognize this ?

     
  • Daniel Marjamäki

    Thanks! I can reproduce. I have created https://trac.cppcheck.net/ticket/10649

     
    👍
    1
  • fenugrec

    fenugrec - 2021-12-11

    Wow that was fast. Thanks a lot for your work on cppcheck, it's very useful even with occasional issues like this one.

     

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.