coreyoconnor/vty — Issue #19: Segfault caused by mk_wcswidth
Author: pbmichel
Created: 2011-11-02 09:08:33+00:00
State: open

I am using the great VTY library for a small robot simulator in teaching beginners programming.

After making all the necessary adjustments to make the robot run again with the current version of the library, it started to produce segmentation faults at random. GDB tells me its from mk_wcswidth, which I identified to be custom C code of this library.

A web search found me a related discussion, most importantly this posting:

http://www.haskell.org/pipermail/glasgow-haskell-bugs/2011-August/032006.html

I then unpacked VTY with cabal and made the suggested change in the C code, i.e. line 211 in mk_wcswidth:

< for (;*pwcs && n-- > 0; pwcs++)

to

> for (;n-- && *pwcs > 0; pwcs++)

It makes an awful lot of sense to me, as the length argument is given precedence over reading over the string bounds...
The segfault does no longer occur, at least as far as testing can show that... :-D

I would appreciate an update in the library, so our service center can just deploy it using cabal.

Thanks!