]> granicus.if.org Git - neomutt/commitdiff
Remove legacy trim_incomplete_mbyte() in the pager
authorKevin McCarthy <kevin@8t8.us>
Tue, 14 Aug 2018 21:04:05 +0000 (14:04 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Sep 2018 17:06:08 +0000 (18:06 +0100)
Commit 4b1deb57 added the trim_incomplete_mbyte() call, but at
that time, the function was using fgets() into a fixed-sized
buffer.  The function was passing in "blen - 1" to the size
parameter of fgets, so the check for blen-2 was to see if the
buffer was completely filled by the fgets.

Commit d39d9c0c converted to use a dynamic buffer, but the
trim_incomplete_mbyte() was left in.  It now serves no purpose
because the entire line will be read in.  Presumably the buggy
regexp lib should have been fixed by now too.

pager.c

diff --git a/pager.c b/pager.c
index 36edda1147cb7933de57856dfdfb51a9053b9167..bf8e707b1f19943f4da5412ef00ffbc3b8247b0d 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1223,37 +1223,6 @@ static int grok_ansi(unsigned char *buf, int pos, struct AnsiAttr *a)
   return pos;
 }
 
-/**
- * trim_incomplete_mbyte - Remove an incomplete character
- * @param buf    Buffer containing string
- * @param buflen Length of buffer
- * @retval num Number of bytes remaining
- *
- * trim tail of buf so that it contains complete multibyte characters
- */
-static int trim_incomplete_mbyte(unsigned char *buf, size_t buflen)
-{
-  mbstate_t mbstate;
-  size_t k;
-
-  memset(&mbstate, 0, sizeof(mbstate));
-  for (; buflen > 0; buf += k, buflen -= k)
-  {
-    k = mbrtowc(NULL, (char *) buf, buflen, &mbstate);
-    if (k == (size_t)(-2))
-      break;
-    else if (k == (size_t)(-1) || k == 0)
-    {
-      if (k == (size_t)(-1))
-        memset(&mbstate, 0, sizeof(mbstate));
-      k = 1;
-    }
-  }
-  *buf = '\0';
-
-  return buflen;
-}
-
 /**
  * fill_buffer - Fill a buffer from a file
  * @param[in]     f         File to read from
@@ -1289,11 +1258,6 @@ static int fill_buffer(FILE *f, LOFF_T *last_pos, LOFF_T offset, unsigned char *
 
     mutt_mem_realloc(fmt, *blen);
 
-    /* incomplete mbyte characters trigger a segfault in regex processing for
-     * certain versions of glibc. Trim them if necessary. */
-    if (b_read == *blen - 2)
-      b_read -= trim_incomplete_mbyte(*buf, b_read);
-
     /* copy "buf" to "fmt", but without bold and underline controls */
     p = *buf;
     q = *fmt;