Browse Source

- fixed sign-warning in snprintf/printf

development
Andreas Romeyke 8 months ago
parent
commit
4d9d00968b
  1. 24
      src/parser/config_parser.c
  2. 2
      src/tagrules/check_tag_has_valid_asciivalue.c
  3. 5
      src/tagrules/check_tag_has_value_matching_regex.c
  4. 12
      src/tagrules/check_tag_has_valuelist.c
  5. 2
      src/validate_icc/check_icc_header.c

24
src/parser/config_parser.c

@ -51,14 +51,14 @@ void print_plan () {
#define CHECKUNDERFLOW(SPACE_P, NAME) \
if (((SPACE_P)->NAME ## _stackp) >=MAXRESULT) {\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %i results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %u results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
exit(EXIT_FAILURE);\
}
// endmacro CHECKUNDERFLOW
#define CHECKOVERFLOW(SPACE_P, NAME) \
if (((SPACE_P)->NAME ## _stackp) >=MAXRESULT) {\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %i results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %u results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
exit(EXIT_FAILURE);\
}
// endmacro CHECKOVERFLOW
@ -76,13 +76,13 @@ void print_plan () {
#define PRINT(SPACE_P, TYPESIG, NAME) \
CHECKOVERFLOW(SPACE_P, NAME) \
CHECKUNDERFLOW(SPACE_P, NAME) \
for (int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
for (unsigned int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
printf(" " #SPACE_P "->" #NAME "-stack value[ %i ] --> " #TYPESIG "\n", j, (SPACE_P)->NAME ## _stack[j]);\
//endmacro PRINT
#define PRINTV(SPACE_P, VSTRINGARRAY, NAME) \
CHECKOVERFLOW(SPACE_P, NAME) \
CHECKUNDERFLOW(SPACE_P, NAME) \
for (int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
for (unsigned int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
printf(" " #SPACE_P "->" #NAME "-stack value[ %i ] --> %s\n", j, (VSTRINGARRAY)[(SPACE_P)->NAME ## _stack[j]]);\
//endmacro PRINTV
@ -314,12 +314,12 @@ static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t
char * strp = expected_value;
for (unsigned int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
int all_printed = 0;
int printed = snprintf(strp, VALUESTRLEN, "count=%i, values ", count);
int printed = snprintf(strp, VALUESTRLEN, "count=%u, values ", count);
strp+=printed;
all_printed+=printed;
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, (size_t) (VALUESTRLEN - all_printed), " [%i]=%u", j, values[j]);
printed = snprintf(strp, (size_t) (VALUESTRLEN - all_printed), " [%u]=%u", j, values[j]);
strp+=printed;
all_printed+=printed;
}
@ -332,12 +332,12 @@ static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t
char * strp = expected_value;
for (unsigned int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
int all_printed = 0;
int printed = snprintf(expected_value, VALUESTRLEN, "count=%i, values", count);
int printed = snprintf(expected_value, VALUESTRLEN, "count=%u, values", count);
strp+=printed;
all_printed+=printed;
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, VALUESTRLEN, " [%i]=%u",j, values[j]);
printed = snprintf(strp, VALUESTRLEN, " [%u]=%u",j, values[j]);
strp+=printed;
all_printed+=printed;
}
@ -347,19 +347,19 @@ static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t
case fc_tag_has_value_in_range: { unsigned int a = exe_i_pop(&exe);
unsigned int b = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%i -- %i", a, b);
snprintf(expected_value, VALUESTRLEN, "%u -- %u", a, b);
ret = check_tag_has_value_in_range(ctif, exe.tag, a, b);
break;
}
case fc_tag_has_value: { unsigned int a = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%i", a);
snprintf(expected_value, VALUESTRLEN, "%u", a);
ret = check_tag_has_value(ctif, exe.tag, a);
break;
}
case fc_tag_has_value_quiet: { unsigned int a = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%i", a);
snprintf(expected_value, VALUESTRLEN, "%u", a);
ret = check_tag_has_value_quiet(ctif, exe.tag, a);
break;
}
@ -596,7 +596,7 @@ void execute_plan (ctiff_t * ctif) {
ret_t res = check_notag(ctif, (tag_t) i);
if (res.returncode == tag_exist) {
#ifdef EXE_DEBUG
printf("checking %i -> res=%s (%i)\n", i, get_parser_error_description(res.returncode), res.returncode);
printf("checking %u -> res=%s (%i)\n", i, get_parser_error_description(res.returncode), res.returncode);
#endif
full_res_t full;
full.tag = (tag_t) i;

2
src/tagrules/check_tag_has_valid_asciivalue.c

@ -47,7 +47,7 @@ ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag) {
ret.returncode=should_not_occur;
if (0 != r) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "'%s' (\\0 at position %i in %u-len)", string, r, count);
snprintf(array, sizeof(array), "'%s' (\\0 at position %u in %u-len)", string, r, count);
ret = set_value_found_ret(&ret, array);
ret.returncode = tagerror_multiple_zeros_in_asciivalue;
} else {

5
src/tagrules/check_tag_has_value_matching_regex.c

@ -18,10 +18,11 @@ ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char *
case TIFF_ASCII: {
char * val=NULL;
uint32 count=0;
unsigned int r = 0;
ret = TIFFGetFieldASCII(ctif, tag, &val, &count);
if (ret.returncode != is_valid) return ret;
if (0 < count) {
unsigned int r = 0;
for (uint32 i=0; i<count-1; i++) {
if (val[i] == '\0' && val[i+1] =='\0') {
r = i+1;
@ -37,7 +38,7 @@ ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char *
}
if (r != 0) {
char array[VALUESTRLEN];
snprintf(array, sizeof(array), "'%s' (\\0 at position %i in %u-len)", val, r, count);
snprintf(array, sizeof(array), "'%s' (\\0 at position %u in %u-len)", val, r, count);
ret = set_value_found_ret(&ret, array);
ret.returncode = tagerror_multiple_zeros_in_asciivalue;
return ret;

12
src/tagrules/check_tag_has_valuelist.c

@ -39,7 +39,7 @@ ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, unsigned int count, con
if (ifd_entry.value_or_offset == is_value) {
for (unsigned int i=0; i< count; i++) {
if (v[i] != ifd_entry.data32) {
snprintf(value, sizeof(value), "at [%i]=%u", i, ifd_entry.data32);
snprintf(value, sizeof(value), "at [%u]=%u", i, ifd_entry.data32);
ret = set_value_found_ret (&ret, value);
ret.returncode = tagerror_value_differs;
return ret;
@ -57,10 +57,10 @@ ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, unsigned int count, con
for (unsigned int i=0; i< count; i++) {
uint32 pval = *p;
#ifdef DEBUG
printf("OFFSET: v[%i]=%u p[%i]=%u\n", i,v[i],i,pval);
printf("OFFSET: v[%u]=%u p[%u]=%u\n", i,v[i],i,pval);
#endif
if (v[i] != *p) {
snprintf(value, sizeof(value), "at [%i]=%u", i, pval);
snprintf(value, sizeof(value), "at [%u]=%u", i, pval);
ret = set_value_found_ret (&ret, value);
ret.returncode = tagerror_value_differs;
return ret;
@ -76,7 +76,7 @@ ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, unsigned int count, con
for (unsigned int i=0; i< count; i++) {
int c = (v[i]) == (ifd_entry.data16[i]);
if (!c) {
snprintf(value, sizeof(value), "at [%i]=%u", i, ifd_entry.data16[i]);
snprintf(value, sizeof(value), "at [%u]=%u", i, ifd_entry.data16[i]);
ret = set_value_found_ret (&ret, value);
ret.returncode = tagerror_value_differs;
return ret;
@ -94,10 +94,10 @@ ret_t check_tag_has_valuelist(ctiff_t * ctif, tag_t tag, unsigned int count, con
for (unsigned int i=0; i< count; i++) {
uint16 pval = *p;
#ifdef DEBUG
printf("SHORTOFFSET (tag=%i): v[%i]=%u p[%i]=0x%04x\n", tag, i,v[i],i,pval);
printf("SHORTOFFSET (tag=%u): v[%u]=%u p[%u]=0x%04x\n", tag, i,v[i],i,pval);
#endif
if (v[i] != pval) {
snprintf(value, sizeof(value), "at [%i]=%u", i, pval);
snprintf(value, sizeof(value), "at [%u]=%u", i, pval);
ret = set_value_found_ret (&ret, value);
ret.returncode = tagerror_value_differs;
return ret;

2
src/validate_icc/check_icc_header.c

@ -247,7 +247,7 @@ icc_returncode_t parse_icc(unsigned long iccsize, char* iccdata, unsigned long e
unsigned short b = (unsigned short) ((iccdata[9] & 0x00f0) >> 4);
unsigned short c = (unsigned short) (iccdata[9] & 0x000f);
char profileversion[6]=" ";
int snprintf_error = snprintf(profileversion, 6, "%hi.%hi.%hi", a, b, c);
int snprintf_error = snprintf(profileversion, 6, "%hu.%hu.%hu", a, b, c);
if (snprintf_error == 5) {
INFO("ICC: profileversion='%s'\n", profileversion);
if (0==strncmp(profileversion, "5.0.0", 5)) return parse_icc_v500(iccsize, iccdata, errsize, errmessage);

Loading…
Cancel
Save