Menu

Misleading error message

2025-03-06
2025-03-06
  • Michael Clarke

    Michael Clarke - 2025-03-06

    G'Day

    I had the following coded:

    while ((a != NULL) && (b != NULL)) {
    if (a!=NULL) {
    a=a->next;

    ...and if flagged it as an incorrect inner if, indicating the if statement
    was wrong.

    while (a!=NULL)
    if (a!=NULL)

    The if statement was fine. The problem was that the while loop should have
    had an || not an &&.

    Mik

     
  • CHR

    CHR - 2025-03-06

    cppcheck cannot divine the programmer's intentions. The if was probably flagged because the same condition had already been checked in the while statement.

     

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.