summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cstr.h
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-04 21:11:26 +0100
committerTyge Løvset <[email protected]>2022-12-04 21:11:26 +0100
commita8babcaefe5751698a33a45b6bd2cfe40a7e060b (patch)
tree7a609750538dc39d4e972c744c043a2623489c2d /include/stc/cstr.h
parent20400977b40599fd1c6637dd659e72b900794d0f (diff)
downloadSTC-modified-a8babcaefe5751698a33a45b6bd2cfe40a7e060b.tar.gz
STC-modified-a8babcaefe5751698a33a45b6bd2cfe40a7e060b.zip
Fixed BUG in cstr_tocase().
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);