From 5ce9030c51c4710711aa05dbe9632f119d8188cb Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 14 Aug 2018 14:04:05 -0700 Subject: [PATCH] Remove legacy trim_incomplete_mbyte() in the pager. 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 | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/pager.c b/pager.c index 398e768c..2a1dae79 100644 --- a/pager.c +++ b/pager.c @@ -1033,31 +1033,6 @@ static int grok_ansi(unsigned char *buf, int pos, ansi_attr *a) return pos; } -/* trim tail of buf so that it contains complete multibyte characters */ -static int -trim_incomplete_mbyte(unsigned char *buf, size_t len) -{ - mbstate_t mbstate; - size_t k; - - memset (&mbstate, 0, sizeof (mbstate)); - for (; len > 0; buf += k, len -= k) - { - k = mbrtowc (NULL, (char *) buf, len, &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 len; -} - static int fill_buffer (FILE *f, LOFF_T *last_pos, LOFF_T offset, unsigned char **buf, unsigned char **fmt, size_t *blen, int *buf_ready) @@ -1081,11 +1056,6 @@ fill_buffer (FILE *f, LOFF_T *last_pos, LOFF_T offset, unsigned char **buf, safe_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; -- 2.40.0