libgrapheme

Freestanding C library for unicode string handling
git clone https://git.sinitax.com/suckless/libgrapheme
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 195946ab880bddbf6296fe47da5152163a126022
parent e57131a3dfd4e73747538a27ec472f9803e09803
Author: Laslo Hunhold <dev@frign.de>
Date:   Tue, 14 Dec 2021 13:45:02 +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 <dev@frign.de>

Diffstat:
Msrc/util.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 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); } }