Menu

False-positive redundant assignment

Daniel
2022-09-20
2022-09-20
  • Daniel

    Daniel - 2022-09-20

    The following false-positive occurs when using multiple structs in the same union:

    (style) Variable 'm.u16.ab' is reassigned a value before the old one has been used. [redundantAssignment]

    /* Fixed-point math union */
    typedef union fixed32_union {
        struct {
            unsigned32 abcd;
        } u32;
        struct {
            unsigned16 ab;
            unsigned16 cd;
        } u16;
        struct {
            unsigned8 a;
            unsigned8 b;
            unsigned8 c;
            unsigned8 d;
        } u8;
    } fixed32;
    
    void func1(void) {
        fixed32 m;
        m.u16.ab = 47;
        m.u16.cd = 0;
        m.u16.ab = m.u32.abcd / 53;
    }
    
     
  • CHR

    CHR - 2022-09-20

    Thanks for reporting, I've added your example to this ticket: https://trac.cppcheck.net/ticket/10093

     

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.