fix sigfault on older c compilers

This commit is contained in:
Pascal Kuthe 2022-11-14 13:43:42 +01:00
parent 8e5c76d8b3
commit b39d3a4456
No known key found for this signature in database
GPG Key ID: D715E8655AE166A6
1 changed files with 10 additions and 9 deletions

View File

@ -606,18 +606,19 @@ static char *cat2strings(char *s1, char *s2, bool spa)
else if (s1 == NULL || *s1 == '\0') {
return copy(s2);
}
size_t lges = strlen(s1) + strlen(s2) + 2;
char *nextstr;
char *strsum = TMALLOC(char, lges);
size_t l1 = strlen(s1);
size_t l2 = strlen(s2);
char *strsum = TMALLOC(char, l1 + l2 + 2);
if (spa) {
nextstr = memccpy(strsum, s1, '\0', lges);
*(nextstr - 1) = ' ';
nextstr = memccpy(nextstr, s2, '\0', lges);
memcpy(strsum, s1, l1);
memcpy(strsum + l1 + 1, s2, l2);
strsum[l1] = ' ';
strsum[l1 + l2 + 1] = '\0';
}
else {
nextstr = (char*)memccpy(strsum, s1, '\0', lges) - 1;
nextstr = (char*)memccpy(nextstr, s2, '\0', lges) - 1;
*nextstr = '\0';
memcpy(strsum, s1, l1);
memcpy(strsum + l1, s2, l2);
strsum[l1 + l2] = '\0';
}
return strsum;
}