X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump2.c;h=d7f8ad3d68abbcff43539cae1f56ef4515aa2e06;hb=e8da3d80c173b248addd7f6133cacc63b3389c3f;hp=af01b408cdc5f77c1ae6021458d1001e1e6473cd;hpb=992e58c9b4d996d98e26c55151201ff1216b4d08;p=pspp diff --git a/dump2.c b/dump2.c index af01b408cd..d7f8ad3d68 100644 --- a/dump2.c +++ b/dump2.c @@ -7,6 +7,7 @@ #include #include #include +#include "u8-mbtouc.h" static uint8_t *data; static size_t n, pos; @@ -86,10 +87,25 @@ all_ascii(const uint8_t *p) return true; } +static bool +all_utf8(const uint8_t *p) +{ + size_t len = strlen ((char *) p); + for (size_t ofs = 0, mblen; ofs < len; ofs += mblen) + { + ucs4_t uc; + + mblen = u8_mbtouc (&uc, p + ofs, len - ofs); + if (uc < 32 || uc == 127 || uc == 0xfffd) + return false; + } + return true; +} + static char * get_fixed_string(int len, const char *where) { - if (pos + len > n || !memchr(&data[pos], 0, len) || !all_ascii(&data[pos])) + if (pos + len > n || !memchr(&data[pos], 0, len) || !all_utf8(&data[pos])) { fprintf(stderr, "%s: 0x%x: bad fixed-width string\n", where, pos); exit(1);