From: Kevin McCarthy Date: Fri, 8 Apr 2016 22:20:53 +0000 (-0700) Subject: Reset mbstate for other mbrtowc() calls returning -1 X-Git-Tag: neomutt-20160822~183 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ee72bb9a25170535c59e37efa23b8ec8ae1a4ce;p=neomutt Reset mbstate for other mbrtowc() calls returning -1 Continue the cleanup started in changesets c8c76a6a1e61 and a3450fd50d11. In those changesets, a bug was occurring due to the mbstate not being reset when mbrtowc() returned -1. This patch fixes other callers of mbrtowc() to reset mbstate when it returns -1. --- diff --git a/alias.c b/alias.c index cb653fd19..0cb9ebe8d 100644 --- a/alias.c +++ b/alias.c @@ -423,6 +423,8 @@ int mutt_check_alias_name (const char *s, char *dest, size_t destlen) { if (dry) return -1; + if (l == (size_t)(-1)) + memset (&mb, 0, sizeof (mbstate_t)); *dest++ = '_'; rv = -1; } diff --git a/curs_lib.c b/curs_lib.c index 3178f2210..ee1464cac 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -1034,6 +1034,8 @@ int mutt_strwidth (const char *s) { if (k == (size_t)(-1) || k == (size_t)(-2)) { + if (k == (size_t)(-1)) + memset (&mbstate, 0, sizeof (mbstate)); k = (k == (size_t)(-1)) ? 1 : n; wc = replacement_char (); } diff --git a/help.c b/help.c index c80427437..c48c68f43 100644 --- a/help.c +++ b/help.c @@ -103,6 +103,8 @@ static int print_macro (FILE *f, int maxwidth, const char **macro) { if (k == (size_t)(-1) || k == (size_t)(-2)) { + if (k == (size_t)(-1)) + memset (&mbstate1, 0, sizeof (mbstate1)); k = (k == (size_t)(-1)) ? 1 : len; wc = replacement_char (); } @@ -165,6 +167,8 @@ static int get_wrapped_width (const char *t, size_t wid) m = n; if (k == (size_t)(-1) || k == (size_t)(-2)) { + if (k == (size_t)(-1)) + memset (&mbstate, 0, sizeof (mbstate)); k = (k == (size_t)(-1)) ? 1 : len; wc = replacement_char (); } diff --git a/pager.c b/pager.c index 8bfe72cc9..9c26d873c 100644 --- a/pager.c +++ b/pager.c @@ -1011,10 +1011,14 @@ trim_incomplete_mbyte(unsigned char *buf, size_t len) for (; len > 0; buf += k, len -= k) { k = mbrtowc (NULL, (char *) buf, len, &mbstate); - if (k == -2) + if (k == (size_t)(-2)) break; - else if (k == -1 || k == 0) + else if (k == (size_t)(-1) || k == 0) + { + if (k == (size_t)(-1)) + memset (&mbstate, 0, sizeof (mbstate)); k = 1; + } } *buf = '\0'; @@ -1125,6 +1129,8 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf, k = mbrtowc (&wc, (char *)buf+ch, cnt-ch, &mbstate); if (k == -2 || k == -1) { + if (k == -1) + memset(&mbstate, 0, sizeof(mbstate)); dprint (1, (debugfile, "%s:%d: mbrtowc returned %d; errno = %d.\n", __FILE__, __LINE__, k, errno)); if (col + 4 > wrap_cols)