summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cstr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/stc/cstr.h')
-rw-r--r--include/stc/cstr.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 8a351d02..29a2e4a4 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -420,10 +420,11 @@ fn_tocase[] = {{tolower, utf8_casefold},
cstr cstr_tocase(csview sv, int k) {
cstr out = cstr_init();
char *buf = cstr_reserve(&out, sv.size*3/2);
+ const char *end = sv.str + sv.size;
uint32_t cp; size_t sz = 0;
utf8_decode_t d = {.state=0};
- while (*sv.str) {
+ while (sv.str < end) {
do { utf8_decode(&d, (uint8_t)*sv.str++); } while (d.state);
if (d.codep < 128)
buf[sz++] = (char)fn_tocase[k].conv_asc((int)d.codep);