]> git.ozlabs.org Git - petitboot/blobdiff - lib/fold/fold.c
lib/fold: Handle extra mbrtowc return case
[petitboot] / lib / fold / fold.c
index 8bf133c8b34a9e0e37762eda8122dce4ac210141..2566253aca8de697149d2c17477eb26ba14b455a 100644 (file)
@@ -34,10 +34,11 @@ void fold_text(const char *text,
 
                bytes = mbrtowc(&wc, end, len - (end - text), &ps);
 
 
                bytes = mbrtowc(&wc, end, len - (end - text), &ps);
 
-               assert(bytes >= 0);
+               assert(bytes != (size_t)-1);
 
 
-               /* we'll get a zero size for the nul terminator */
-               if (!bytes) {
+               /* we'll get a zero size for the nul terminator, or (size_t) -2
+                * if we've reached the end of the buffer */
+               if (!bytes || bytes == (size_t) -2) {
                        line_cb(arg, start, end - start);
                        break;
                }
                        line_cb(arg, start, end - start);
                        break;
                }