Re: mutt/1536: Segment fault with long lines when LANG=*.UTF-8
On Fri, 05 Aug 2005, Brendan Cully wrote:
> Ok, this sounds a little bit risky. How about another suggestion: we
> only do the check when b_read == blen - 2? that is, when fgets has run
> all the way to the end of the buffer. That should keep things speedy
> in the normal case.
Sounds good!
But please don't forget the following issue:
> On Friday, 05 August 2005 at 18:40, TAKAHASHI Tamotsu wrote:
> > And I'm afraid the patches should malloc, clear and use mbstate
> > instead of NULL. Every other mbrtowc() in mutt is using its own
> > mbstate, AFAIK. It could work well even without its own mbstate,
> > but it would be hard to debug once a problem occurred.
Probably it would look like this:
+ if (b_read == blen - 2)
+ {
+ mbstate_t mbstate;
+ memset(&mbstate, 0, sizeof(mbstate));
+ /* trim tail of buf so that it contains complete multibyte characters */
+ for (n = b_read, p = buf; n > 0; p += k, n -= k)
+ {
+ k = mbrtowc (&wc, (char *) p, n, &mbstate);
+ if (k == -2)
+ break;
+ else if (k == -1 || k == 0)
+ k = 1;
+ }
+ b_read -= n;
+ buf[b_read] = 0;
..
--
tamo