diff mbox series

[uclibc-ng-devel] iconv: fix parameter type of utf8seq_is_{overlong,surrogate,illegal}

Message ID 20240729115804.30385-1-marcus.haehnel@kernkonzept.com
State Accepted
Headers show
Series [uclibc-ng-devel] iconv: fix parameter type of utf8seq_is_{overlong,surrogate,illegal} | expand

Commit Message

Marcus Haehnel July 29, 2024, 11:58 a.m. UTC
From: Frank Mehnert <frank.mehnert@kernkonzept.com>

Use `unsigned char *s` rather than `char *s`. First, this fixes compiler
warnings when these functions are called from utf8dec_wchar() passing
the `in` pointer of type `unsigned char *`.

Second, these functions are always called with characters >= 0x80 so the
sign bit is set. Shifting right a negative signed value will insert `1`
from the left side, so `foo >> 1` where foo is negative will always have
the sign bit set. So at least "case 2" would never return true.

There is a similar problem with tests like

  (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF)

This condition is always false with `char *s`.

Signed-off-by: Marcus Haehnel <marcus.haehnel@kernkonzept.com>
---
 libiconv/iconv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libiconv/iconv.c b/libiconv/iconv.c
index 6876ab5f7..095932fd6 100644
--- a/libiconv/iconv.c
+++ b/libiconv/iconv.c
@@ -242,7 +242,7 @@  static inline int utf8enc_wchar(char *outb, wchar_t c)
 	}
 }
 
-static inline int utf8seq_is_overlong(char *s, int n)
+static inline int utf8seq_is_overlong(unsigned char *s, int n)
 {
 	switch (n)
 	{
@@ -268,12 +268,12 @@  static inline int utf8seq_is_overlong(char *s, int n)
 	return 0;
 }
 
-static inline int utf8seq_is_surrogate(char *s, int n)
+static inline int utf8seq_is_surrogate(unsigned char *s, int n)
 {
 	return ((n == 3) && (*s == 0xED) && (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF));
 }
 
-static inline int utf8seq_is_illegal(char *s, int n)
+static inline int utf8seq_is_illegal(unsigned char *s, int n)
 {
 	return ((n == 3) && (*s == 0xEF) && (*(s+1) == 0xBF) &&
 	        (*(s+2) >= 0xBE) && (*(s+2) <= 0xBF));