From 8f2906ba61d49e515ad6037613828bb38a235e81 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 14 Jan 2005 04:38:48 +0000 Subject: [PATCH] fix the multibyte equivalent of strnlen() so that it actually works git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2260 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/chars.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chars.c b/src/chars.c index b97813b9..2977fd83 100644 --- a/src/chars.c +++ b/src/chars.c @@ -144,7 +144,7 @@ size_t nstrnlen(const char *s, size_t maxlen) size_t mbstrnlen(const char *s, size_t maxlen) { #ifdef NANO_WIDE - if (ISSET(NO_UTF8)) { + if (!ISSET(NO_UTF8)) { size_t n = 0; char *s_mb = charalloc(mb_cur_max()); int s_mb_len; @@ -158,6 +158,9 @@ size_t mbstrnlen(const char *s, size_t maxlen) #endif , NULL); + if (s_mb_len > maxlen) + s_mb_len = maxlen; + maxlen -= s_mb_len; n += s_mb_len; -- 2.39.5