From 5fb185fecc64806a772c2ad3956ecc903c508e0c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 22 Dec 2019 19:19:56 +1300 Subject: Bounds checking on character byte walk --- wtf8.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wtf8.c') diff --git a/wtf8.c b/wtf8.c index e277d1a..714a7cc 100644 --- a/wtf8.c +++ b/wtf8.c @@ -35,7 +35,7 @@ void print_characters(char *s) { /* * We need a short counter to find how long each character is */ - int c; + unsigned char c; /* * Iterate through the string @@ -46,7 +46,7 @@ void print_characters(char *s) { * Print blanks and increment a counter until we find how long this * character is */ - for (c = 1; is_utf8_cont(s[c]); c++) + for (c = 1; is_utf8_cont(s[c]) && c <= UCHAR_MAX; c++) printf(" "); /* -- cgit v1.2.3