Browse Source

- rewritten secstrcat() using strbuff_t

development
art1pirat 2 months ago
committed by Andreas Romeyke
parent
commit
6441c2c19b
  1. 2
      src/headers/check_helper.h
  2. 24
      src/helper/check_helper.c
  3. 145
      src/helper/renderer/check_renderer_ansi.c
  4. 109
      src/helper/renderer/check_renderer_default.c

2
src/headers/check_helper.h

@ -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, const size_t * maxsize_p);
strbuff_t * secstrcat (strbuff_t * dest, const char * src);
ctiff_t * initialize_ctif( const char * tiff_file, ct_ioflag_t );
void free_ctif( ctiff_t * ctif);
uint32 get_ifd0_pos( ctiff_t * ctif);

24
src/helper/check_helper.c

@ -22,23 +22,19 @@
*/
/* 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);
}
strbuff_t * secstrcat (strbuff_t * dest, const char * src) {
if (NULL != src) {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
size_t destsize = strnlen(dest, maxsize);
size_t srclen = strnlen(src, maxsize);
size_t maxdest = destsize + srclen;
if (maxdest < maxsize-1) {
strncat( dest, src, srclen);
} else {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", destsize, srclen, maxsize);
assert(NULL != dest );
size_t srclen = strlen(src);
if ((dest->pos + srclen) > dest->bufsize) {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", dest->pos, srclen, dest->bufsize);
exit(EXIT_FAILURE);
}
memcpy(dest->bufpos, src, srclen);
dest->bufpos += srclen;
// fprintf(stderr, "DEBUG: dest->pos=%zu, src len=%zu", dest->pos, srclen);
dest->pos += srclen;
// fprintf(stderr, " new dest_pos=%zu\n", dest->pos);
}
return dest;
}

145
src/helper/renderer/check_renderer_ansi.c

@ -53,122 +53,131 @@
const char * renderer_ansi ( const retmsg_t * ret, short int is_quiet ) {
assert (ret != NULL);
/*
char * res = malloc( sizeof(char) * RENDERSIZE);
strbuff_t * res = malloc(sizeof(strbuff_t));
if (NULL == res) {
exit(could_not_allocate_memory);
}
memset( res, '\0', RENDERSIZE);
*/
char * res = calloc(RENDERMAXSIZE, sizeof(char));
if (NULL == res) {
res->buf = malloc( RENDERMAXSIZE * sizeof(char));
if (NULL == res->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_res = RENDERMAXSIZE;
/*
char * tmp = malloc( sizeof(char) * RENDERSIZE);
res->bufpos = res->buf;
res->pos=0;
res->bufsize = RENDERMAXSIZE;
memset( res->buf, 0, RENDERMAXSIZE);
strbuff_t * tmp;
tmp = malloc( sizeof( tmp ) );
if (NULL == tmp) {
exit(could_not_allocate_memory);
}
memset( tmp, '\0', RENDERSIZE);
*/
char * tmp = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp) {
tmp->buf = malloc( RENDERMINSIZE * sizeof(char));
if (NULL == tmp->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_tmp = RENDERMINSIZE;
tmp->bufpos = tmp->buf;
tmp->pos=0;
tmp->bufsize = RENDERMINSIZE;
memset( tmp->buf, 0, RENDERMINSIZE);
const retmsg_t * startp = ret;
short int rc_is_valid = 1;
while (NULL != startp) {
assert(startp->rm_msg != NULL);
switch (startp->rm_type) {
case rm_rule: tmp=secstrcat(tmp, ANSI_NORMAL , & rendersize_tmp);
tmp=secstrcat(tmp, "\t--> ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_rule: tmp=secstrcat(tmp, ANSI_NORMAL );
tmp=secstrcat(tmp, "\t--> ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_tag:
case rm_mode: tmp=secstrcat(tmp, "\t", & rendersize_tmp );
tmp=secstrcat(tmp, ANSI_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_mode: tmp=secstrcat(tmp, "\t" );
tmp=secstrcat(tmp, ANSI_BOLD );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_value: tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, " found: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_value: tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, " found: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_expected: tmp=secstrcat(tmp, ANSI_BLUE, & rendersize_tmp);
tmp=secstrcat(tmp, " expected: " , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_expected: tmp=secstrcat(tmp, ANSI_BLUE);
tmp=secstrcat(tmp, " expected: " );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_hard_error: tmp=secstrcat(tmp, ANSI_RED_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, "(HE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_hard_error: tmp=secstrcat(tmp, ANSI_RED_BOLD );
tmp=secstrcat(tmp, "(HE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error: tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, "(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_error: tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, "(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error_description:
tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, " ", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, " " );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_warning: tmp=secstrcat(tmp, ANSI_GREY , & rendersize_tmp);
tmp=secstrcat(tmp, "(WW)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_warning: tmp=secstrcat(tmp, ANSI_GREY );
tmp=secstrcat(tmp, "(WW)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_logicalor_error:
tmp=secstrcat(tmp, ANSI_YELLOW , & rendersize_tmp);
tmp=secstrcat(tmp, "(LE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_YELLOW );
tmp=secstrcat(tmp, "(LE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_file: res=secstrcat(res, "file: ", & rendersize_res );
res=secstrcat(res, ANSI_BLUE_BOLD, & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, ANSI_NORMAL , & rendersize_res);
res=secstrcat(res, "\n", & rendersize_res);
case rm_file: res=secstrcat(res, "file: ");
res=secstrcat(res, ANSI_BLUE_BOLD);
res=secstrcat(res, startp->rm_msg);
res=secstrcat(res, ANSI_NORMAL );
res=secstrcat(res, "\n");
break;
case rm_lineno: tmp=secstrcat(tmp, ANSI_GREY, & rendersize_tmp);
tmp=secstrcat(tmp, " (lineno: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ")", & rendersize_tmp);
case rm_lineno: tmp=secstrcat(tmp, ANSI_GREY);
tmp=secstrcat(tmp, " (lineno: ");
tmp=secstrcat(tmp, startp->rm_msg);
tmp=secstrcat(tmp, ")");
break;
case rm_endrule:
case rm_endtiff:
tmp=secstrcat(tmp, ANSI_NORMAL, & rendersize_tmp);
tmp=secstrcat(tmp, "\n", & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_NORMAL);
tmp=secstrcat(tmp, "\n");
/* copy tmp to res, reset tmp */
if ((rc_is_valid == 0) && (is_quiet == 0)) {
} else {
res=secstrcat(res, tmp, & rendersize_res);
res=secstrcat(res, tmp->buf);
}
memset( tmp, '\0', rendersize_tmp);
memset(tmp->buf, 0, tmp->bufsize);
tmp->bufpos= tmp->buf;
tmp->pos = 0;
rc_is_valid =1;
break;
case rm_is_valid: tmp=secstrcat(tmp, ANSI_GREEN_BOLD, & rendersize_tmp);
tmp=secstrcat(tmp, "(./)", & rendersize_tmp);
case rm_is_valid: tmp=secstrcat(tmp, ANSI_GREEN_BOLD);
tmp=secstrcat(tmp, "(./)");
rc_is_valid = 0;
break;
case rm_summary_valid:
tmp=secstrcat(tmp, ANSI_GREEN_BOLD, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(./)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_GREEN_BOLD);
tmp=secstrcat(tmp, "\n(./)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_summary_invalid:
tmp=secstrcat(tmp, ANSI_RED_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, "\n(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_RED_BOLD );
tmp=secstrcat(tmp, "\n(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
default: tmp=secstrcat(tmp, ANSI_NORMAL , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
default: tmp=secstrcat(tmp, ANSI_NORMAL );
tmp=secstrcat(tmp, startp->rm_msg);
}
startp=startp->next;
}
res=secstrcat( res, ANSI_NORMAL, & rendersize_res);
res=secstrcat( res, "\n", & rendersize_res);
res=secstrcat( res, ANSI_NORMAL);
res=secstrcat( res, "\n");
if (NULL != tmp->buf) {
free(tmp->buf);
}
if (NULL != tmp) {
free(tmp);
}
return res;
char * result_string = res->buf;
if (NULL != res) {
free(res);
}
return result_string;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

109
src/helper/renderer/check_renderer_default.c

@ -12,104 +12,111 @@
const char * renderer_default ( const retmsg_t * ret, short int is_quiet ) {
assert (ret != NULL);
/*
char * res = malloc( sizeof(char) * RENDERSIZE);
strbuff_t * res = malloc(sizeof(strbuff_t));
if (NULL == res) {
exit(could_not_allocate_memory);
}
memset( res, '\0', RENDERSIZE);
*/
char * res = calloc(RENDERMAXSIZE, sizeof(char));
if (NULL == res) {
res->buf = malloc( RENDERMAXSIZE * sizeof(char));
if (NULL == res->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_res = RENDERMAXSIZE;
/*
char * tmp = malloc( sizeof(char) * RENDERSIZE);
res->bufpos = res->buf;
res->pos=0;
res->bufsize = RENDERMAXSIZE;
memset( res->buf, 0, RENDERMAXSIZE);
strbuff_t * tmp;
tmp = malloc( sizeof( tmp ) );
if (NULL == tmp) {
exit(could_not_allocate_memory);
}
memset( tmp, '\0', RENDERSIZE);
*/
char * tmp = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp) {
tmp->buf = malloc( RENDERMINSIZE * sizeof(char));
if (NULL == tmp->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_tmp = RENDERMINSIZE;
tmp->bufpos = tmp->buf;
tmp->pos=0;
tmp->bufsize = RENDERMINSIZE;
memset( tmp->buf, 0, RENDERMINSIZE);
const retmsg_t * startp = ret;
short int rc_is_valid = 1;
while (NULL != startp) {
assert(startp->rm_msg != NULL);
switch (startp->rm_type) {
case rm_rule: tmp=secstrcat(tmp, "\t--> ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_rule: tmp=secstrcat(tmp, "\t--> ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_tag:
case rm_mode: tmp=secstrcat(tmp, "\t", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_mode: tmp=secstrcat(tmp, "\t");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_value: tmp=secstrcat(tmp, "; found: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_value: tmp=secstrcat(tmp, "; found: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_expected: tmp=secstrcat(tmp, "; expected: " , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_expected: tmp=secstrcat(tmp, "; expected: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_hard_error: tmp=secstrcat(tmp, "(HE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_hard_error: tmp=secstrcat(tmp, "(HE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error: tmp=secstrcat(tmp, "(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_error: tmp=secstrcat(tmp, "(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error_description:
tmp=secstrcat(tmp, " ", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, " ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_warning: tmp=secstrcat(tmp, "(WW)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_warning: tmp=secstrcat(tmp, "(WW)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_logicalor_error: tmp=secstrcat(tmp, "(LE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_logicalor_error: tmp=secstrcat(tmp, "(LE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_file: res=secstrcat(res, "file: ", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "\n", & rendersize_res);
case rm_file: res=secstrcat(res, "file: ");
res=secstrcat(res, startp->rm_msg);
res=secstrcat(res, "\n");
break;
case rm_lineno: tmp=secstrcat(tmp, " (lineno: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ")", & rendersize_tmp);
case rm_lineno: tmp=secstrcat(tmp, " (lineno: ");
tmp=secstrcat(tmp, startp->rm_msg);
tmp=secstrcat(tmp, ")");
break;
case rm_endrule:
case rm_endtiff:
tmp=secstrcat(tmp, "\n", & rendersize_tmp);
tmp=secstrcat(tmp, "\n");
/* copy tmp to res, reset tmp */
if ((rc_is_valid == 0) && (is_quiet == 0)) {
} else {
res=secstrcat(res, tmp, & rendersize_res);
res=secstrcat(res, tmp->buf);
}
memset( tmp, '\0', rendersize_tmp);
tmp->bufpos= tmp->buf;
tmp->pos = 0;
rc_is_valid =1;
break;
case rm_is_valid: tmp=secstrcat(tmp, "(./)", & rendersize_tmp);
case rm_is_valid: tmp=secstrcat(tmp, "(./)");
rc_is_valid = 0;
break;
case rm_summary_valid:
tmp=secstrcat(tmp, "\n(./)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(./)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_summary_invalid:
tmp=secstrcat(tmp, "\n(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
default: tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
default: tmp=secstrcat(tmp, startp->rm_msg);
}
startp=startp->next;
}
res=secstrcat(res, "\n", & rendersize_res);
res=secstrcat( res, "\n");
if (NULL != tmp->buf) {
free(tmp->buf);
}
if (NULL != tmp) {
free(tmp);
}
return res;
char * result_string = res->buf;
if (NULL != res) {
free(res);
}
return result_string;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/
Loading…
Cancel
Save