Browse Source

- refactoring, improved code

development
Andreas Romeyke 2 years ago
parent
commit
7ae9990a85
4 changed files with 23 additions and 19 deletions
  1. +1
    -1
      src/headers/check.h
  2. +1
    -1
      src/headers/check_helper.h
  3. +20
    -16
      src/helper/check_helper.c
  4. +1
    -1
      src/helper/check_tiffparse.c

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

@ -35,7 +35,7 @@ typedef struct ctiff_s {
thandle_t fd; /* filedescriptor */
uint32 ifd0pos; /* offset in tif stream (in bytes) */
uint16 ifd0c; /* count of tags in first ifd */
char isbyteswapped; /* true if BigEndian */
int isbyteswapped; /* true if BigEndian */
char *filename; /* filename */
/* TODO: add file size */
} ctiff_t;


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

@ -40,7 +40,7 @@ uint32 get_ifd0_pos( ctiff_t * ctif);
ret_t parse_header_and_endianess(ctiff_t * ctif );
uint32 get_next_ifd_pos( ctiff_t * ctif, uint32 actual_pos );
uint16 get_ifd0_count( ctiff_t * ctif );
char is_byteswapped( ctiff_t * ctif );
int is_byteswapped( ctiff_t * ctif );
ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd);
ret_t set_value_found_ret (ret_t * rp, const char * msg);
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, rm_type_t src_type);


+ 20
- 16
src/helper/check_helper.c View File

@ -21,31 +21,35 @@
*/
char * secstrcat (char * dest, const char * src, size_t * maxsize_p) {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
if (NULL == dest) {
fprintf(stderr, "internal error, dest is NULL!\n");
exit(EXIT_FAILURE);
}
if (NULL == src) {
} else {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
size_t destsize = strnlen(dest, maxsize);
size_t srclen = strnlen(src, maxsize);
if (destsize+srclen < maxsize-1) {
strncat( dest, src, srclen);
size_t maxdest = destsize + srclen;
if (maxdest < maxsize-1) {
strncat( dest, src, srclen);
} else {
int new_maxsize=(((destsize+srclen) / RENDERSIZE)+1) * RENDERSIZE-1;
if (new_maxsize < 4096*RENDERSIZE && new_maxsize > 0) {
int 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, destsize +srclen);
}
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);
}
}
}
}
@ -59,7 +63,7 @@ const char * float2str(float v) {
}
const char* int2str(int v) {
char array[VALUESTRLEN];
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "%i", v);
return strdup(array);
}


+ 1
- 1
src/helper/check_tiffparse.c View File

@ -757,7 +757,7 @@ uint16 get_ifd0_count( ctiff_t * ctif ) {
return ctif->ifd0c;
}
char is_byteswapped( ctiff_t * ctif ) {
int is_byteswapped( ctiff_t * ctif ) {
assert( NULL != ctif);
return ctif->isbyteswapped;
}


Loading…
Cancel
Save