From f3011f826389b2a1174e9f1e101e726c78b994a6 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Fri, 25 Sep 2015 16:48:32 +0200 Subject: [PATCH] allocate 256 bits, not 256 bytes, for a charset --- src/internal.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/internal.h b/src/internal.h index b11186dd..b35b7d5a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -155,20 +155,20 @@ static inline void h_sarray_clear(HSArray *arr) { typedef unsigned int *HCharset; static inline HCharset new_charset(HAllocator* mm__) { - HCharset cs = h_new(unsigned int, 256 / sizeof(unsigned int)); - memset(cs, 0, 256); + HCharset cs = h_new(unsigned int, 256 / (sizeof(unsigned int) * 8)); + memset(cs, 0, 32); // 32 bytes = 256 bits return cs; } static inline int charset_isset(HCharset cs, uint8_t pos) { - return !!(cs[pos / sizeof(*cs)] & (1 << (pos % sizeof(*cs)))); + return !!(cs[pos / (sizeof(*cs)*8)] & (1 << (pos % (sizeof(*cs)*8)))); } static inline void charset_set(HCharset cs, uint8_t pos, int val) { - cs[pos / sizeof(*cs)] = + cs[pos / (sizeof(*cs)*8)] = val - ? cs[pos / sizeof(*cs)] | (1 << (pos % sizeof(*cs))) - : cs[pos / sizeof(*cs)] & ~(1 << (pos % sizeof(*cs))); + ? cs[pos / (sizeof(*cs)*8)] | (1 << (pos % (sizeof(*cs)*8))) + : cs[pos / (sizeof(*cs)*8)] & ~(1 << (pos % (sizeof(*cs)*8))); } typedef unsigned int HHashValue; -- GitLab