From 355ab0d214ee0f08fb44ebeafd70d5e93db84c10 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 31 Oct 2020 12:25:36 +0100 Subject: [PATCH] Work around brokenness in FreeBSD mbtowc(). The manpage claims the return value should be 0 on a null byte, just like on Linux, but in practice, it returns -1, so we need to check for end-of-string manually. --- serializer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serializer.cpp b/serializer.cpp index f20c304..7d4ce11 100644 --- a/serializer.cpp +++ b/serializer.cpp @@ -60,7 +60,7 @@ void print_possibly_escaped(const string &str) ptr += ret; len -= ret; } - } while (all_safe); + } while (all_safe && *ptr != '\0'); if (all_safe) { printf("%s\n", str.c_str()); @@ -77,7 +77,7 @@ void print_possibly_escaped(const string &str) mbtowc(nullptr, 0, 0); ptr = str.data(); len = str.size(); - for (;;) { + while (*ptr != '\0') { int ret = mbtowc(nullptr, ptr, len); if (ret == -1) { // Malformed data. -- 2.39.2