on master help sign in
attempt to fix a segfault possibly due to not NUL terminated strings

The strings used in withCWStringLen are (despite the incorrect comment) supposed to come equipped with length, but no NUL at the end (in particular nothing is allocated for an empty string). Fortunately, here the length suffices. See http://hackage.haskell.org/trac/ghc/ticket/5396 and https://github.com/coreyoconnor/vty/issues/14#issuecomment-1813397

commit18fe87aa967a563c63930ad1819b56b4ff00957a authorMikolaj <mikolaj.konarski@gmail.com> dateTue 16 Aug 2011, 21:47 (15 years ago) parenta2cdd07
1 file changed+3−3
cbits/mk_wcwidth.c+3−3
cbits/mk_wcwidth.c+3−3
@@ -187,7 +187,7 @@ int mk_wcwidth(wchar_t ucs)
187187
188188 /* if we arrive here, ucs is not a combining or C0/C1 control character */
189189
190− return 1 +
190+ return 1 +
191191 (ucs >= 0x1100 &&
192192 (ucs <= 0x115f || /* Hangul Jamo init. consonants */
193193 ucs == 0x2329 || ucs == 0x232a ||
@@ -208,7 +208,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n)
208208{
209209 int w, width = 0;
210210
211− for (;*pwcs && n-- > 0; pwcs++)
211+ for (;n-- > 0; pwcs++)
212212 if ((w = mk_wcwidth(*pwcs)) < 0)
213213 return -1;
214214 else
@@ -299,7 +299,7 @@ int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
299299{
300300 int w, width = 0;
301301
302− for (;*pwcs && n-- > 0; pwcs++)
302+ for (;n-- > 0; pwcs++)
303303 if ((w = mk_wcwidth_cjk(*pwcs)) < 0)
304304 return -1;
305305 else