From 155aaa5967e262728b8f2952817078f54e3dec08 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 16 Feb 2025 15:31:36 +0100 Subject: [PATCH] Fix fd2949d: use std::prev() to walk back from a possible string::end() --- src/string_func.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/string_func.h b/src/string_func.h index 00f1d3fcfd..25cc86489e 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -166,9 +166,11 @@ inline const char *Utf8PrevChar(const char *s) inline std::string::iterator Utf8PrevChar(std::string::iterator &s) { - auto *cur = &*s; - auto *prev = Utf8PrevChar(cur); - return s - (cur - prev); + auto cur = s; + do { + cur = std::prev(cur); + } while (IsUtf8Part(*cur)); + return cur; } size_t Utf8StringLength(const char *s);