Menu

Could you please explain me an error?

G-Shadow
2015-03-07
2015-04-06
  • G-Shadow

    G-Shadow - 2015-03-07

    Hi!
    Since updating CppCheck 1.65 -> 1.68 a new error found in my code.
    Below is minimalistic source to reproduce it.
    If I uncomment m_nCounter definition here, error will gone.
    In my real project this is an class member with m_nCounter declared in
    header file.
    First I assume it treats if (x) as a boolean, but declaring "bool
    m_nConfig" removes error as well.
    Of course I know I could write "if (m_nCounter > 0u)" and it helps, but
    I prefer short way and wish to understand source of error.
    Thanks in advance!

    //uint m_nCounter;
    uint Release() {
    if (m_nCounter) {
    m_nCounter--;
    if (!m_nCounter) printf ("Resource is free.\n");
    }
    return m_nCounter;
    }

     
  • Alexander Mai

    Alexander Mai - 2015-03-08

    You did not tell us what error you see. Based on my local result (oppositeInnerCondition) I've created a ticket: http://trac.cppcheck.net/ticket/6574

     
  • G-Shadow

    G-Shadow - 2015-03-11

    Yes, you are right. Thanks!

     
  • Daniel Marjamäki

    In my real project this is an class member with m_nCounter declared in
    header file.

    I recommend that you include the header file so the declaration is seen.

     

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.