From debb288115ed22897c31eb78a1d5326647773678 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 7 Apr 2021 17:21:25 +0200 Subject: [PATCH] tweaks: reduce the maximum character length from six bytes to four In UTF-8 valid multibyte characters are at most four bytes long, and now that we no longer make use of mblen() and mbtowc() from the underlying system, we won't get five- or six-byte sequences mistakenly reported as valid (by glibc). So it is always enough to reserve space for just four bytes per character. --- src/definitions.h | 4 ++-- src/nano.c | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/definitions.h b/src/definitions.h index 8a2beadc..b772e498 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -111,9 +111,9 @@ #define REPLACING 1 #define INREGION 2 -/* In UTF-8 a character is at most six bytes long. */ #ifdef ENABLE_UTF8 -#define MAXCHARLEN 6 +/* In UTF-8 a valid character is at most four bytes long. */ +#define MAXCHARLEN 4 #else #define MAXCHARLEN 1 #endif diff --git a/src/nano.c b/src/nano.c index 6e40ab12..f2cb0a30 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1804,12 +1804,6 @@ int main(int argc, char **argv) textdomain(PACKAGE); #endif -#if defined(ENABLE_UTF8) && !defined(NANO_TINY) - if (MB_CUR_MAX > MAXCHARLEN) - fprintf(stderr, "Unexpected large character size: %i bytes" - " -- please report a bug\n", (int)MB_CUR_MAX); -#endif - /* Set sensible defaults, different from what Pico does. */ SET(NO_WRAP); SET(SMOOTH_SCROLL);