From 3c16105936320e4095dbe84fa9a33a4a6d46a597 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Mon, 21 Oct 2024 18:41:41 +0300 Subject: [PATCH] tuklib_mbstr_width: Use stricter return value checking This should make no difference in practice (at least if mbrtowc() isn't broken). --- src/common/tuklib_mbstr_width.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/tuklib_mbstr_width.c b/src/common/tuklib_mbstr_width.c index 3c63dd1a..e7052235 100644 --- a/src/common/tuklib_mbstr_width.c +++ b/src/common/tuklib_mbstr_width.c @@ -41,7 +41,7 @@ tuklib_mbstr_width(const char *str, size_t *bytes) while (i < len) { wchar_t wc; const size_t ret = mbrtowc(&wc, str + i, len - i, &state); - if (ret < 1 || ret > len) + if (ret < 1 || ret > len - i) return (size_t)-1; i += ret;