Browse Source

- simplified secstrcat()

development
Andreas Romeyke 2 years ago
parent
commit
793bc9a8ca
2 changed files with 5 additions and 18 deletions
  1. +1
    -1
      src/headers/check_helper.h
  2. +4
    -17
      src/helper/check_helper.c

+ 1
- 1
src/headers/check_helper.h View File

@ -33,7 +33,7 @@ ret_t TIFFGetFieldLONG(ctiff_t * ctif, const tag_t tag, uint32 ** result_long_p,
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, const tag_t tag, uint16 ** result_short_p, uint32 * result_countp);
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, const tag_t tag, float ** result_float_p, uint32 * result_countp);
ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count, const uint16 datatype, offset_t * result_offsetp, ret_t * ret_p);
char * secstrcat (char * dest, const char * src, size_t * maxsize_p);
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p);
ctiff_t * initialize_ctif( const char * tiff_file, ct_ioflag_t );
void free_ctif( ctiff_t * ctif);
uint32 get_ifd0_pos( ctiff_t * ctif);


+ 4
- 17
src/helper/check_helper.c View File

@ -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;


Loading…
Cancel
Save