From aca30fd7dac4d02721508e31c51656773f78a6b7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 17 Jul 2016 21:34:24 +0200 Subject: Ungeneralise verify_utf8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.c | 8 +++----- src/util.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/util.c b/src/util.c index 0d6b715..2fdbeae 100644 --- a/src/util.c +++ b/src/util.c @@ -195,11 +195,10 @@ void msleep(unsigned ms) /** * Check whether a NUL-terminated string is encoded in UTF-8 * - * @param string The string - * @param allow_modified_nul Whether Modified UTF-8 is allowed, which allows a two-byte encoding for NUL - * @return Zero if good, -1 on encoding error + * @param string The string + * @return Zero if good, -1 on encoding error */ -int verify_utf8(const char* restrict string, int allow_modified_nul) +int verify_utf8(const char* restrict string) { static long BYTES_TO_MIN_BITS[] = {0, 0, 8, 12, 17, 22, 37}; static long BYTES_TO_MAX_BITS[] = {0, 7, 11, 16, 21, 26, 31}; @@ -256,7 +255,6 @@ int verify_utf8(const char* restrict string, int allow_modified_nul) /* Check that the character is not unnecessarily long. */ while (character) character >>= 1, bits++; - bits = ((bits == 0) && (bytes == 2) && allow_modified_nul) ? 8 : bits; if ((bits < BYTES_TO_MIN_BITS[bytes]) || (BYTES_TO_MAX_BITS[bytes] < bits)) return -1; diff --git a/src/util.h b/src/util.h index 915c44a..6eafcb4 100644 --- a/src/util.h +++ b/src/util.h @@ -99,7 +99,7 @@ void msleep(unsigned ms); * @return Zero if good, -1 on encoding error */ GCC_ONLY(__attribute__((pure, nonnull))) -int verify_utf8(const char* restrict string, int allow_modified_nul); +int verify_utf8(const char* restrict string); /** * Make identity mapping ramps -- cgit v1.2.3-70-g09d2