From: David Lawrence Ramsey Date: Fri, 14 Jan 2005 04:38:48 +0000 (+0000) Subject: fix the multibyte equivalent of strnlen() so that it actually works X-Git-Tag: v1.3.6~142 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=8f2906ba61d49e515ad6037613828bb38a235e81;p=nano.git 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 --- 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;