Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 12 additions & 0 deletions utf8proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ typedef bool utf8proc_bool;
#endif
#include <limits.h>

/** 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
Expand Down