diff --git a/src/common/FFstrbuf.h b/src/common/FFstrbuf.h index 214f4cdb63..7681299d4a 100644 --- a/src/common/FFstrbuf.h +++ b/src/common/FFstrbuf.h @@ -567,7 +567,7 @@ static inline bool ffStrbufInitJsonVal(FFstrbuf* strbuf, yyjson_val* jsonVal) { // Not `pure`: the caller-supplied `fn` may have side effects [[gnu::nonnull(1, 2), nodiscard]] static inline bool ffStrbufEndsWithFn(const FFstrbuf* strbuf, int (*const fn)(int)) { - return strbuf->length == 0 ? false : fn(strbuf->chars[strbuf->length - 1]); + return strbuf->length == 0 ? false : fn((unsigned char)strbuf->chars[strbuf->length - 1]); } [[gnu::nonnull(1, 2), gnu::pure, nodiscard]] static inline bool ffStrbufEndsWith(const FFstrbuf* strbuf, const FFstrbuf* end) { diff --git a/src/common/impl/FFstrbuf.c b/src/common/impl/FFstrbuf.c index 494e487c88..cd0304360d 100644 --- a/src/common/impl/FFstrbuf.c +++ b/src/common/impl/FFstrbuf.c @@ -323,7 +323,7 @@ void ffStrbufTrimLeftSpace(FFstrbuf* strbuf) { } uint32_t index = 0; - while (index < strbuf->length && isspace(strbuf->chars[index])) { + while (index < strbuf->length && isspace((unsigned char)strbuf->chars[index])) { ++index; } diff --git a/src/common/strutil.h b/src/common/strutil.h index ee30dbc41c..a4fe126aa5 100644 --- a/src/common/strutil.h +++ b/src/common/strutil.h @@ -28,7 +28,7 @@ static inline bool ffStrSet(const char* str) { return false; } - while (isspace(*str)) { + while (isspace((unsigned char)*str)) { str++; } diff --git a/tests/strutil.c b/tests/strutil.c index 1b06ff5b74..4998889542 100644 --- a/tests/strutil.c +++ b/tests/strutil.c @@ -26,6 +26,8 @@ int main(void) { VERIFY(ffStrSet("a")); VERIFY(ffStrSet(" a")); VERIFY(ffStrSet("a ")); + VERIFY(ffStrSet("\x80")); + VERIFY(ffStrSet("\xff")); } {