Skip to content

Commit

Permalink
Fix handling of multibyte characters (at start of display area)
Browse files Browse the repository at this point in the history
Previously a sequence of Unicode REPLACEMENT CHARACTER was displayed.

Use an explicitly initialized mbstate_t object in the call to mbrtowc().
While this should not strictly be necessary, it works around a bug in
certain implementations.

Closes martanne#56.
  • Loading branch information
TieDyedDevil authored and martanne committed Jul 3, 2015

Verified

This commit was signed with the committer’s verified signature.
mairacanal Maíra Canal
1 parent 87c7258 commit a9263c7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion view.c
Original file line number Diff line number Diff line change
@@ -374,6 +374,8 @@ void view_draw(View *view) {
memset(match, 0, sizeof match);
/* default and current curses attributes to use */
int default_attrs = COLOR_PAIR(0) | A_NORMAL, attrs = default_attrs;
/* start from known multibyte state */
mbstate_t mbstate = { 0 };

while (rem > 0) {

@@ -428,7 +430,7 @@ void view_draw(View *view) {
}
}

size_t len = mbrtowc(&wchar, cur, rem, NULL);
size_t len = mbrtowc(&wchar, cur, rem, &mbstate);
if (len == (size_t)-1 && errno == EILSEQ) {
/* ok, we encountered an invalid multibyte sequence,
* replace it with the Unicode Replacement Character

0 comments on commit a9263c7

Please sign in to comment.