]> git.sesse.net Git - plocate/commitdiff
Work around brokenness in FreeBSD mbtowc().
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 31 Oct 2020 11:25:36 +0000 (12:25 +0100)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 31 Oct 2020 11:25:36 +0000 (12:25 +0100)
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

index f20c304de54e690a5c41852127da93b6b8c3c2bb..7d4ce119fceff9683584dbc8898682e1e9c9662e 100644 (file)
@@ -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.