ext/utf8/utf8.c in utf8-0.1.0 vs ext/utf8/utf8.c in utf8-0.1.1
- old
+ new
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdint.h>
-#define CHECK_LEN if ((size_t)(in-start) >= in_len) return 0;
+#define CHECK_LEN if ((size_t)(in-start) >= in_len) return -1;
/*
* Scans the current position of the buffer
* returning the length of this UTF8 character
*/
@@ -60,17 +60,20 @@
/*
* Scans the current position of the buffer
* returning the total number of UTF8 characters found
*/
-size_t utf8CharCount(unsigned char *in, size_t in_len) {
- size_t total = 0, leftOver = in_len;
+int64_t utf8CharCount(unsigned char *in, size_t in_len) {
+ int64_t total = 0, leftOver = in_len;
int8_t len = 0;
unsigned char *start = in;
if (in_len > 0) {
while (leftOver) {
len = utf8CharLen(start, leftOver);
+ if (len < 0) {
+ return -1;
+ }
leftOver -= len;
start += len;
total++;
}
}