Always abort on overflow in String_cat

Not only in debug mode.
This commit is contained in:
Christian Göttsche 2022-04-30 14:51:10 +02:00 committed by BenBE
parent 08166b27b1
commit 549fcb6bb8
1 changed files with 3 additions and 1 deletions

View File

@ -115,7 +115,9 @@ inline bool String_contains_i(const char* s1, const char* s2, bool multi) {
char* String_cat(const char* s1, const char* s2) {
const size_t l1 = strlen(s1);
const size_t l2 = strlen(s2);
assert(SIZE_MAX - l1 > l2);
if (SIZE_MAX - l1 <= l2) {
fail();
}
char* out = xMalloc(l1 + l2 + 1);
memcpy(out, s1, l1);
memcpy(out + l1, s2, l2);