commit 195946ab880bddbf6296fe47da5152163a126022
Author:     Laslo Hunhold <[email protected]>
AuthorDate: Tue Dec 14 13:45:02 2021 +0100
Commit:     Laslo Hunhold <[email protected]>
CommitDate: Tue Dec 14 13:45:02 2021 +0100

    Avoid undefined signed integer overflow in heisenstate_set()
    
    Instead, specify explicitly that we're working with unsigned (at least)
    64 bit integers.
    
    This was found using clang's UB-sanitizer and (interestingly) leads
    to another speedup of around 3-5%. On my machine, it's now at roughly
    4 million CP/s.
    
    Signed-off-by: Laslo Hunhold <[email protected]>

diff --git a/src/util.c b/src/util.c
index de3cbad..1455621 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,11 +27,11 @@ heisenstate_set(struct lg_internal_heisenstate *h, int 
slot, int state)
                /* no state given or slot out of range */
                return 1;
        } else {
-               h->determined |= (1 << slot);
+               h->determined |= (UINT64_C(1) << slot);
                if (state) {
-                       h->state |= (1 << slot);
+                       h->state |= (UINT64_C(1) << slot);
                } else {
-                       h->state &= ~(1 << slot);
+                       h->state &= ~(UINT64_C(1) << slot);
                }
        }
 

Reply via email to