ext/console/console.c in console-0.3 vs ext/console/console.c in console-0.4

- old
+ new

@@ -15,12 +15,14 @@ #endif static inline int calc_width(char* string, long strlen, long byte_offset, size_t* num_bytes, size_t* num_cols) { wchar_t wc; size_t width = -1; + mbstate_t state; - *num_bytes = mbrtowc(&wc, string + byte_offset, strlen - byte_offset, NULL); + memset(&state, 0, sizeof(state)); + *num_bytes = mbrtowc(&wc, string + byte_offset, strlen - byte_offset, &state); if(*num_bytes == (size_t)-2) { rb_raise(rb_eArgError, "malformed string: incomplete multibyte character at position %ld", byte_offset); return -1; } @@ -32,12 +34,9 @@ rb_raise(rb_eArgError, "malformed string: NULL byte at position %ld", byte_offset); return -1; } *num_cols = wcwidth(wc); - /* sometimes this seems to happen! maybe it's not bad... - if(width == 0) rb_raise(rb_eArgError, "bad string: non-printable character at position %ld", RSTRING_LEN(v_string) - remaining_bytes); - */ return 0; } /*