This is a small patch to avoid an endless loop. In case of an error
textwrap() adds <ERR> at the end of the string and returns with the string
that was built up to that error.
Thorsten
diff -u libtextwrap-0.1.org/textwrap.3 libtextwrap-0.1/textwrap.3
--- libtextwrap-0.1.org/textwrap.3 2003-08-24 10:13:41.000000000 +0200
+++ libtextwrap-0.1/textwrap.3 2010-01-13 04:59:57.000000000 +0100
@@ -78,6 +78,9 @@
.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 <ERR> will be
+appended to the output and processing will be aborted.
.\" ********************************************************************
.SH EXAMPLE
.nf
diff -u libtextwrap-0.1.org/textwrap.c libtextwrap-0.1/textwrap.c
--- libtextwrap-0.1.org/textwrap.c 2003-08-24 10:13:41.000000000 +0200
+++ libtextwrap-0.1/textwrap.c 2010-01-13 05:04:51.000000000 +0100
@@ -300,6 +300,14 @@
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, " <ERR>");
+ return stringt_destroy_extract(out);
+ }
w = mbwidth(p, ml);
b = breakable(p, ml, encoding_type);
p += ml;