From 647b5a29e9ff9b30fc4292c3c8b96124b1b43d69 Mon Sep 17 00:00:00 2001 From: Murai Takashi Date: Tue, 8 Jan 2019 21:07:26 +0900 Subject: [PATCH] utf8_functions.h: Fix PVS 359 Fix integer constant SIZE_MAX is converted to pointer. Change-Id: Ifdff4e08a9b2c31e466580ba9a71f6ea7c0191d4 Reviewed-on: https://review.haiku-os.org/c/865 Reviewed-by: Adrien Destugues --- headers/private/interface/utf8_functions.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/headers/private/interface/utf8_functions.h b/headers/private/interface/utf8_functions.h index f04e59ca22..5711382c96 100644 --- a/headers/private/interface/utf8_functions.h +++ b/headers/private/interface/utf8_functions.h @@ -141,15 +141,17 @@ UTF8CountChars(const char *bytes, int32 numBytes) return 0; uint32 length = 0; - const char *last; - if (numBytes < 0) - last = (const char *)SIZE_MAX; - else - last = bytes + numBytes - 1; - - while (bytes[0] && bytes <= last) { - if ((bytes++[0] & 0xc0) != 0x80) - length++; + if (numBytes < 0) { + while (bytes[0]) { + if ((bytes++[0] & 0xc0) != 0x80) + length++; + } + } else { + const char *last = bytes + numBytes - 1; + while (bytes[0] && bytes <= last) { + if ((bytes++[0] & 0xc0) != 0x80) + length++; + } } return length;