X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=serializer.cpp;h=f27a865a06e997bec1de0a408624b322c05a6dfb;hb=498466c6434e479cd973fe7655b4feb51dd2c378;hp=f20c304de54e690a5c41852127da93b6b8c3c2bb;hpb=cbecd483f57c465b2ad6d3867c760c2e5b5e79aa;p=plocate diff --git a/serializer.cpp b/serializer.cpp index f20c304..f27a865 100644 --- a/serializer.cpp +++ b/serializer.cpp @@ -56,11 +56,14 @@ void print_possibly_escaped(const string &str) break; // EOF. } else if (pwc < 32 || pwc == '\'' || pwc == '"' || pwc == '\\') { all_safe = false; + } else if (pwc == '`') { + // A rather odd case; ls quotes this but does not escape it. + all_safe = false; } else { ptr += ret; len -= ret; } - } while (all_safe); + } while (all_safe && *ptr != '\0'); if (all_safe) { printf("%s\n", str.c_str()); @@ -77,13 +80,14 @@ 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. printf("?"); ++ptr; --len; + continue; } else if (ret == 0) { break; // EOF. }