|
|
@ -20,7 +20,8 @@ |
|
|
|
#define DEBUG |
|
|
|
*/ |
|
|
|
|
|
|
|
char * secstrcat (char * dest, const char * src, size_t * maxsize_p) { |
|
|
|
/* dest should not exceed maxsize */ |
|
|
|
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p) { |
|
|
|
if (NULL == dest) { |
|
|
|
fprintf(stderr, "internal error, dest is NULL!\n"); |
|
|
|
exit(EXIT_FAILURE); |
|
|
@ -35,22 +36,8 @@ char * secstrcat (char * dest, const char * src, size_t * maxsize_p) { |
|
|
|
if (maxdest < maxsize-1) { |
|
|
|
strncat( dest, src, srclen); |
|
|
|
} else { |
|
|
|
size_t new_maxsize=(((maxdest) / RENDERSIZE)+1) * RENDERSIZE-1; |
|
|
|
if ( |
|
|
|
(new_maxsize < 4096*RENDERSIZE) && |
|
|
|
(new_maxsize > 0) |
|
|
|
) { |
|
|
|
char * dest_new = NULL; |
|
|
|
dest_new = realloc(dest, (new_maxsize+1) * sizeof(char)); |
|
|
|
if (NULL == dest_new) { |
|
|
|
perror( "Could not realloc memory"); |
|
|
|
exit( could_not_allocate_memory ); |
|
|
|
} else { |
|
|
|
*maxsize_p = new_maxsize; |
|
|
|
dest = dest_new; |
|
|
|
strncat( dest, src, maxdest); |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", destsize, srclen, maxsize); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
|
return dest; |
|
|
|