We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa23ad0 commit 2938967Copy full SHA for 2938967
peglib.h
@@ -97,7 +97,13 @@ inline size_t codepoint_length(const char *s8, size_t l) {
97
98
inline size_t codepoint_count(const char *s8, size_t l) {
99
size_t count = 0;
100
- for (size_t i = 0; i < l; i += codepoint_length(s8 + i, l - i)) {
+ for (size_t i = 0; i < l;) {
101
+ auto len = codepoint_length(s8 + i, l - i);
102
+ if (len == 0) {
103
+ // Invalid UTF-8 byte, treat as single byte to avoid infinite loop
104
+ len = 1;
105
+ }
106
+ i += len;
107
count++;
108
}
109
return count;
0 commit comments