X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futf8.c;h=655cc771d4030ad656993c2c3a4ca49381591bb7;hb=31f7bf1;hp=3964e8b1ce300e65f07b7ae849e1c492994fe29e;hpb=4e09014daf8f98584b3f15e64e93bed232e70a6b;p=elogind.git diff --git a/src/shared/utf8.c b/src/shared/utf8.c index 3964e8b1c..655cc771d 100644 --- a/src/shared/utf8.c +++ b/src/shared/utf8.c @@ -86,11 +86,11 @@ static bool is_unicode_control(uint32_t ch) { '\t' is in C0 range, but more or less harmless and commonly used. */ - return (ch < ' ' && ch != '\t') || + return (ch < ' ' && ch != '\t' && ch != '\n') || (0x7F <= ch && ch <= 0x9F); } -char* utf8_is_printable_n(const char* str, size_t length) { +bool utf8_is_printable(const char* str, size_t length) { uint32_t val = 0; uint32_t min = 0; const uint8_t *p; @@ -113,40 +113,37 @@ char* utf8_is_printable_n(const char* str, size_t length) { min = (1 << 16); val = (uint32_t) (*p & 0x07); } else - goto error; + return false; p++; length--; if (!length || !is_continuation_char(*p)) - goto error; + return false; merge_continuation_char(&val, *p); TWO_REMAINING: p++; length--; if (!is_continuation_char(*p)) - goto error; + return false; merge_continuation_char(&val, *p); ONE_REMAINING: p++; length--; if (!is_continuation_char(*p)) - goto error; + return false; merge_continuation_char(&val, *p); if (val < min) - goto error; + return false; } if (is_unicode_control(val)) - goto error; + return false; } - return (char*) str; - -error: - return NULL; + return true; } static char* utf8_validate(const char *str, char *output) {