diff --git a/textwrap.3 b/textwrap.3 index 4bac77b..67f1f84 100644 --- a/textwrap.3 +++ b/textwrap.3 @@ -78,6 +78,9 @@ proper number of space code (0x20) by \fBtextwrap\fR. .SH RETURN VALUE \fBtextwrap()\fR returns the line-folded text. You can free(3) the given value. + +In case of any error while processing the string, the text will be +appended to the output and processing will be aborted. .\" ******************************************************************** .SH EXAMPLE .nf diff --git a/textwrap.c b/textwrap.c index 5753ec9..5c14781 100644 --- a/textwrap.c +++ b/textwrap.c @@ -300,6 +300,14 @@ textwrap(const textwrap_t *prop, const char *text) now = p; /* current character */ ml = mblen(p, MB_CUR_MAX); + if (ml<0) { + /* + * stringt_addstr will take care about enough + * memory for out + */ + stringt_addstr(out, " "); + return stringt_destroy_extract(out); + } w = mbwidth(p, ml); b = breakable(p, ml, encoding_type); p += ml;