From e0dae1215e8e3b8855ea465eb65af71730b67d3b Mon Sep 17 00:00:00 2001 From: "Chris (ChrisJr404)" <11917633+ChrisJr404@users.noreply.github.com> Date: Wed, 26 Aug 2026 19:02:31 -0400 Subject: [PATCH] Define UTF8PROC_SSIZE_MAX for the maximum utf8proc_ssize_t value --- test/misc.c | 12 ++++++++++++ utf8proc.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/misc.c b/test/misc.c index 7ea2ebc..6bd6ade 100644 --- a/test/misc.c +++ b/test/misc.c @@ -44,11 +44,23 @@ static void issue317(void) /* #317 */ } } +static void issue103(void) /* #103 */ +{ + /* UTF8PROC_SSIZE_MAX should be the largest value of utf8proc_ssize_t. + Since utf8proc_ssize_t is a two's-complement signed type the same + size as utf8proc_size_t, that value is all bits set shifted right by one. */ + utf8proc_ssize_t computed = (utf8proc_ssize_t)((utf8proc_size_t)-1 >> 1); + check(UTF8PROC_SSIZE_MAX == computed, + "UTF8PROC_SSIZE_MAX (%lld) != computed max (%lld)", + (long long)UTF8PROC_SSIZE_MAX, (long long)computed); +} + int main(void) { issue128(); issue102(); issue317(); + issue103(); #ifdef UNICODE_VERSION printf("Unicode version: Makefile has %s, has API %s\n", UNICODE_VERSION, utf8proc_unicode_version()); check(!strcmp(UNICODE_VERSION, utf8proc_unicode_version()), "utf8proc_unicode_version mismatch"); diff --git a/utf8proc.h b/utf8proc.h index 83bb5f6..34abc4c 100644 --- a/utf8proc.h +++ b/utf8proc.h @@ -120,6 +120,18 @@ typedef bool utf8proc_bool; #endif #include +/** The maximum value representable by the ::utf8proc_ssize_t type, useful + * for checked conversions from ::utf8proc_size_t (or size_t) lengths. */ +#if defined(_MSC_VER) && _MSC_VER < 1800 +# ifdef _WIN64 +# define UTF8PROC_SSIZE_MAX _I64_MAX +# else +# define UTF8PROC_SSIZE_MAX INT_MAX +# endif +#else +# define UTF8PROC_SSIZE_MAX PTRDIFF_MAX +#endif + #ifdef UTF8PROC_STATIC # ifndef UTF8PROC_DLLEXPORT # define UTF8PROC_DLLEXPORT