From 355ea6d3d7c0dee66daeabdb234bc92d758c46ae Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 15 Apr 2020 23:49:10 -0400 Subject: [PATCH] Allow EGCpools up to 1GB #425 --- src/lib/egcpool.h | 7 ++++--- tests/egcpool.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/egcpool.h b/src/lib/egcpool.h index 32b6e3c1d..f4fb716b5 100644 --- a/src/lib/egcpool.h +++ b/src/lib/egcpool.h @@ -28,6 +28,7 @@ typedef struct egcpool { } egcpool; #define POOL_MINIMUM_ALLOC BUFSIZ +#define POOL_MAXIMUM_BYTES (1u << 30u) // max 1GB static inline void egcpool_init(egcpool* p){ @@ -43,7 +44,7 @@ egcpool_grow(egcpool* pool, size_t len){ while(len > newsize - pool->poolsize){ // ensure we make enough space newsize *= 2; } - if(newsize > 1u << 25u){ + if(newsize > POOL_MAXIMUM_BYTES){ return -1; } // nasty cast here because c++ source might include this header :/ @@ -107,8 +108,8 @@ egcpool_alloc_justified(const egcpool* pool, int len){ // stash away the provided UTF8, NUL-terminated grapheme cluster. the cluster // should not be less than 2 bytes (such a cluster should be directly stored in -// the cell). returns -1 on error, and otherwise a non-negative 25-bit offset. -// 'ulen' must be the number of bytes to lift from egc (utf8_egc_len()). +// the cell). returns -1 on error, and otherwise a non-negative offset. 'ulen' +// must be the number of bytes to lift from egc (utf8_egc_len()). static inline int egcpool_stash(egcpool* pool, const char* egc, size_t ulen){ int len = ulen + 1; // count the NUL terminator diff --git a/tests/egcpool.cpp b/tests/egcpool.cpp index f94e8ab29..fb2d0516d 100644 --- a/tests/egcpool.cpp +++ b/tests/egcpool.cpp @@ -205,6 +205,19 @@ TEST_CASE("EGCpool") { CHECK(candidates.size() / 13 > no); } + // common cleanup + egcpool_dump(&pool_); + +} + +TEST_CASE("EGCpoolLong" * doctest::skip(true)) { + + if(!enforce_utf8()){ + return; + } + + egcpool pool_{}; + // ensure that a hard error comes up when we fill the EGCpool SUBCASE("ExhaustPool") { wchar_t wcs = 0x4e00;