From f330051f8565bf0d856e215e52c39f07258dd84c Mon Sep 17 00:00:00 2001 From: Thomas Lam <79589038+tl-hbk@users.noreply.github.com> Date: Thu, 18 Mar 2021 08:18:21 -0500 Subject: [PATCH] Update long usage in regex polyfill --- win32/regexec.c | 10 +++++----- win32/tre-mem.c | 2 +- win32/tre.h | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/win32/regexec.c b/win32/regexec.c index f22586e3..61e40a58 100644 --- a/win32/regexec.c +++ b/win32/regexec.c @@ -231,7 +231,7 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, pbytes = sizeof(*reach_pos) * tnfa->num_states; xbytes = sizeof(regoff_t) * num_tags; total_bytes = - (sizeof(long) - 1) * 4 /* for alignment paddings */ + (sizeof(size_t) - 1) * 4 /* for alignment paddings */ + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes; /* Allocate the memory. */ @@ -242,16 +242,16 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, /* Get the various pointers within tmp_buf (properly aligned). */ tmp_tags = (void *)buf; tmp_buf = buf + tbytes; - tmp_buf += ALIGN(tmp_buf, long); + tmp_buf += ALIGN(tmp_buf, size_t); reach_next = (void *)tmp_buf; tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); + tmp_buf += ALIGN(tmp_buf, size_t); reach = (void *)tmp_buf; tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); + tmp_buf += ALIGN(tmp_buf, size_t); reach_pos = (void *)tmp_buf; tmp_buf += pbytes; - tmp_buf += ALIGN(tmp_buf, long); + tmp_buf += ALIGN(tmp_buf, size_t); for (i = 0; i < tnfa->num_states; i++) { reach[i].tags = (void *)tmp_buf; diff --git a/win32/tre-mem.c b/win32/tre-mem.c index 0fbf7b2d..327515b2 100644 --- a/win32/tre-mem.c +++ b/win32/tre-mem.c @@ -143,7 +143,7 @@ tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, } /* Make sure the next pointer will be aligned. */ - size += ALIGN(mem->ptr + size, long); + size += ALIGN(mem->ptr + size, size_t); /* Allocate from current block. */ ptr = mem->ptr; diff --git a/win32/tre.h b/win32/tre.h index c07c9596..390df94a 100644 --- a/win32/tre.h +++ b/win32/tre.h @@ -32,6 +32,7 @@ #include #include #include +#include #undef TRE_MBSTATE @@ -77,8 +78,8 @@ typedef wctype_t tre_ctype_t; /* Returns number of bytes to add to (char *)ptr to make it properly aligned for the type. */ #define ALIGN(ptr, type) \ - ((((long)ptr) % sizeof(type)) \ - ? (sizeof(type) - (((long)ptr) % sizeof(type))) \ + ((((uintptr_t)ptr) % sizeof(type)) \ + ? (sizeof(type) - (((uintptr_t)ptr) % sizeof(type))) \ : 0) #undef MAX -- 2.47.2