((uint64_t)-1) may be undefined

Issue #67 resolved
Martin Albrecht repo owner created an issue

Mate Soos write:

"Undefined behaviour sanitizer is giving me a bug in M4RI and it's usually a good idea to fix these, undefined behaviour is... undefined. Here:

 /usr/local/include/m4ri/mzd.h:582:3: runtime error: negation of 1 cannot be
 represented in type  'word' (aka 'unsigned long') 

The line of code is:

 static inline void mzd_write_bit(mzd_t *M, rci_t const row, rci_t const col, BIT const
 value) { 
 __M4RI_WRITE_BIT(M->rows[row][col/m4ri_radix], col%m4ri_radix, value); 
 } 

"

Comments (8)

  1. Mate Soos

    Here is how I use it:

    for(uint32_t v: thisXor) {
                const uint32_t var = outerToInterVarMap[v];
                assert(var < numCols-1);
                mzd_write_bit(mat, row, var, 1);
            }
    
            //Add RHS to the augmented columns
            if (thisXor.rhs)
                mzd_write_bit(mat, row, numCols-1, 1);
    

    I think that should be OK? If not, I am happy to change it of course, but I think a lot of people are likely to use it this way?

  2. Martin Albrecht reporter

    Nope, this is exactly how I'd expect you to call it :) Will need to fix the undefined behaviour thing.

  3. Mate Soos

    :) By the way, I just built it with ASAN+UBSAN and it gave this right away so once it's fixed it's easy to check that it's good :)

  4. Mate Soos

    I have been fuzzing CMS with this change for a couple of days now, it seems fine :) So there is a good chance that no bug has been introduced, and the original issue is definitely gone :) Thanks!

  5. Log in to comment