]> diplodocus.org Git - nmh/commit
sbr/fmt_scan.c: Only wcwidth(3) a valid mbtowc(3) result.
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 25 Apr 2017 23:14:26 +0000 (00:14 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 26 Apr 2017 06:43:39 +0000 (07:43 +0100)
commitfa377c31ac72f5c8253ae96f28185e510c26a720
tree92ce9099f70399458e1b0cbc5ca558def083f8ec
parentbacae217c754a3eedd0d71bdda74397c17633123
sbr/fmt_scan.c: Only wcwidth(3) a valid mbtowc(3) result.

The assert(3) added by 80a9e99f7078199500d2d53c8d77d1b92af06fbc is
failing, but not reproducibly.  It's probable that mbtowc() is returning
a negative, and not altering wide_char, leaving it as random stack
content.  Taking its wcwidth() then sometimes also returns negative,
causing the assert() failure.  Initialising wide_char before the call
isn't a solution as it isn't documented if it's modified to an invalid
value on an error return.

Instead, delay calculating the wcwidth() until after the possible
substitution of "?".  Leave the assert() in place.
sbr/fmt_scan.c