Menu

Fallse positive - Overflow is expected on uint8_t .

2025-03-22
2025-03-23
  • Mario De Weerd

    Mario De Weerd - 2025-03-22

    Hi

    I had a few false positives - at least the messages would need to be updated (PossiblyAlwaysFalse, conditionTrueFalseWithoutOverflow, ...).

    Test case:

    #include <stdint.h>
    // Test case for cppcheck
    // Run with
    //    cppcheck --enable=style,portability,warning,performance,unusedFunction te
    st.c
    // Results from cppcheck 2.16.0  - all false positive because overflow is expected
    
    uint8_t page_count = 0;
    uint8_t page_no = 0;
    
    void inc_address(void)
        {
            // test.c:13:30: note: Assignment 'page_count=page_count+16', assigned 
    value is greater than 15
        page_count = (page_count + 16);
        // test.c:15:20: style: Condition 'page_count==0' is always false [knownConditionTrueFalse]
        if (page_count == 0) {
                    page_no ++;
                set_page_address(page_no);
            }
    }
    
    int main() {
            uint8_t i = 0;
        // test.c:24:9: style: Condition '++i' is always true [knownConditionTrueFalse]
            while (++i) {
                    inc_address();
         }
    }
    
     
  • CHR

    CHR - 2025-03-23
     

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.