diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-12-22 19:19:56 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-12-22 19:20:56 +1300 |
commit | d82f9c33571d361b3cccb2a76d1637575f4f17a4 (patch) | |
tree | 9c045b6974bc318a3f138d83531469e2c7f674d3 | |
parent | Merge branch 'release/v1.2.0' into develop (diff) | |
download | wtf8-d82f9c33571d361b3cccb2a76d1637575f4f17a4.tar.gz wtf8-d82f9c33571d361b3cccb2a76d1637575f4f17a4.zip |
Bounds checking on character byte walk
-rw-r--r-- | wtf8.c | 4 | ||||
-rw-r--r-- | wtf8.h | 1 |
2 files changed, 3 insertions, 2 deletions
@@ -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(" "); /* @@ -1,3 +1,4 @@ +#include <limits.h> #include <stdio.h> #include <stdlib.h> |