diff --git a/src/libutil/strutil.cpp b/src/libutil/strutil.cpp index ff8e2067bc..432b120081 100644 --- a/src/libutil/strutil.cpp +++ b/src/libutil/strutil.cpp @@ -1436,13 +1436,15 @@ decode(uint32_t* state, uint32_t* codep, uint32_t byte) void Strutil::utf8_to_unicode(string_view str, std::vector& uvec) { - const char* begin = str.begin(); - const char* end = str.end(); - uint32_t state = 0; + const char* begin = str.begin(); + const char* end = str.end(); + uint32_t state = 0; + uint32_t codepoint = 0; for (; begin != end; ++begin) { - uint32_t codepoint = 0; - if (!decode(&state, &codepoint, (unsigned char)*begin)) + if (!decode(&state, &codepoint, (unsigned char)*begin)) { uvec.push_back(codepoint); + codepoint = 0; + } } }