Browse Source

- enhanced __add_to_render_pipeline_via_strncpy() signature by strlen

development
Andreas Romeyke 2 years ago
parent
commit
d782ad71f5
4 changed files with 36 additions and 27 deletions
  1. +4
    -4
      src/checkit_tiff.c
  2. +2
    -1
      src/headers/check_helper.h
  3. +11
    -3
      src/helper/check_print.c
  4. +19
    -19
      src/parser/config_parser.c

+ 4
- 4
src/checkit_tiff.c View File

@ -71,8 +71,8 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
res = parse_header_and_endianess( ctif );
if (res.returncode != is_valid) {
assert(NULL != res.value_found);
__add_to_render_pipeline_via_strncpy(&actual_render, res.value_found, rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(res.value_found), rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endtiff);
//printf("res.val='%s'\n", res.value_found);
goto renderer_exit;
}
@ -80,8 +80,8 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
res=get_first_IFD(ctif, &offset);
if (res.returncode != is_valid) {
assert(NULL != res.value_found);
__add_to_render_pipeline_via_strncpy(&actual_render, res.value_found, rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endtiff);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(res.value_found), rm_hard_error);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endtiff);
goto renderer_exit;
}
execute_plan(ctif);


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

@ -43,7 +43,8 @@ uint16 get_ifd0_count( 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);
#define STRING_AND_LEN(str) str, strlen( str )
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, size_t src_len, rm_type_t src_type);
void __clean_render_pipeline( retmsg_t ** pointer );
#define GET_EMPTY_RET(ret) \


+ 11
- 3
src/helper/check_print.c View File

@ -13,7 +13,12 @@
#include "check.h"
#include "check_helper.h"
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, rm_type_t src_type) {
/** adds a message to render pipeline
* @pointer to render pipeline
* @src message
* @src_type message rm_type
*/
returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const char * src, size_t src_len, rm_type_t src_type) {
assert(pointer != NULL);
retmsg_t * actual_render = NULL;
actual_render = *pointer;
@ -34,12 +39,15 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
}
memset( actual_render->next->rm_msg, '\0', VALUESTRLEN);
*/
char * msg = calloc (VALUESTRLEN, sizeof(char) );
char * msg = calloc (src_len+1, sizeof(char) );
if (NULL == msg) {
exit (could_not_allocate_memory);
// return could_not_allocate_memory;
}
strncpy(msg, src, VALUESTRLEN-1 );
strncpy(msg, src, src_len );
actual_render->next = next;
actual_render->next->rm_msg = msg;
actual_render->next->rm_type = src_type;


+ 19
- 19
src/parser/config_parser.c View File

@ -1105,7 +1105,7 @@ void set_mode(modes_t mode) {
e.function = fc_all_geotiff_tags_have_same_count_of_values;
exe_push(e);
break;
}
}
case mode_enable_type_checks: { /* nothing, because we must enable it only in rule_addtag_config */
}
}
@ -1299,40 +1299,40 @@ ret_t print_plan_results(retmsg_t * actual_render) {
type = rm_hard_error; break;
default: type = rm_error; break;
}
__add_to_render_pipeline_via_strncpy(&actual_render, "", type);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), type);
/* fill with tag infos */
if (tag > 0) {
char tagstr [VALUESTRLEN];
snprintf(tagstr, VALUESTRLEN, "tag %i (%s)", tag, TIFFTagName(tag));
__add_to_render_pipeline_via_strncpy(&actual_render, tagstr, rm_tag);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN( tagstr), rm_tag);
} else {
__add_to_render_pipeline_via_strncpy(&actual_render, "general", rm_mode);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN("general"), rm_mode);
}
/* fill with rule infos */
__add_to_render_pipeline_via_strncpy(&actual_render, get_parser_function_description(parser_result.function), rm_rule);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN( get_parser_function_description(parser_result.function)), rm_rule);
if (parser_result.expected_value != NULL) {
__add_to_render_pipeline_via_strncpy(&actual_render, parser_result.expected_value, rm_expected);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN( parser_result.expected_value), rm_expected);
} else {
// __add_to_render_pipeline_via_strncpy(&actual_render, "nothing", rm_expected);
}
/* fill with value found */
if (returncode != is_valid) {
__add_to_render_pipeline_via_strncpy(&actual_render, get_parser_error_description(returncode), rm_error_description);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN( get_parser_error_description(returncode)), rm_error_description);
if (parser_result.found_value != NULL) {
__add_to_render_pipeline_via_strncpy(&actual_render, parser_result.found_value, rm_value);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(parser_result.found_value), rm_value);
} else {
//__add_to_render_pipeline_via_strncpy(&actual_render, "nothing", rm_value);
}
}
/* fill with lineno */
char msg[VALUESTRLEN];
snprintf(msg, VALUESTRLEN, "%i", parser_result.lineno);
__add_to_render_pipeline_via_strncpy(&actual_render, msg, rm_lineno);
char msg[5];
snprintf(msg, 5, "%i", parser_result.lineno);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(msg), rm_lineno);
/* fill with newline */
__add_to_render_pipeline_via_strncpy(&actual_render, "", rm_endrule);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endrule);
if (type == rm_hard_error) { goto harderrors; }
/* printf( "%s", renderer( parser_state.result_stack[i].result)); */
@ -1340,19 +1340,19 @@ ret_t print_plan_results(retmsg_t * actual_render) {
harderrors:
{
int errors = (parser_state.result_stackp -count_of_valid_results );
char msg[VALUESTRLEN];
snprintf(msg, VALUESTRLEN, "Found %i errors", errors) ;
char msg[20];
snprintf(msg, 20, "Found %i errors", errors) ;
if (errors > 0) {
res.returncode = is_error;
__add_to_render_pipeline_via_strncpy(&actual_render, msg, rm_error);
__add_to_render_pipeline_via_strncpy(&actual_render, "No, the given tif is not valid :(", rm_summary_invalid);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(msg), rm_error);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN("No, the given tif is not valid :("), rm_summary_invalid);
} else {
res.returncode = is_valid;
__add_to_render_pipeline_via_strncpy(&actual_render, msg, rm_is_valid);
__add_to_render_pipeline_via_strncpy(&actual_render, "Yes, the given tif is valid :)", rm_summary_valid);
__add_to_render_pipeline_via_strncpy(&actual_render, msg, 19, rm_is_valid);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN("Yes, the given tif is valid :)"), rm_summary_valid);
}
}
__add_to_render_pipeline_via_strncpy(&actual_render, " ", rm_endtiff);
__add_to_render_pipeline_via_strncpy(&actual_render, STRING_AND_LEN(""), rm_endtiff);
clean_plan_results();
return res;
}


Loading…
Cancel
Save