Browse Source

- added macro SAVE_int2uint() and corresponding function

- fixed signedness
development
Andreas Romeyke 10 months ago
parent
commit
48bc97e48e
  1. 23
      src/parser/config_parser.c

23
src/parser/config_parser.c

@ -301,6 +301,17 @@ char * __ch_malloc(char * msg) {
return msg;
}
unsigned int save_int2int(int i, const char* file, int line ) {
if (i < 0) {
fprintf(stderr, "code error, using integer %i but unsigned value was expected, code=%s, line=%i\n", \
i, file, line);
exit(EXIT_FAILURE);
}
return (unsigned int) i;
}
#define SAVE_int2uint( i) save_int2int((i), __FILE__, __LINE__)
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep) {
ret_t ret = *retp;
internal_entry_t exe = *exep;
@ -308,16 +319,16 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
switch (exe.function) {
case fc_true: { ret.returncode=is_valid; break;}
case fc_false: { ret.returncode=is_error; break; }
case fc_tag_has_some_of_these_values: { int count = exe_i_pop(&exe);
case fc_tag_has_some_of_these_values: { unsigned int count = SAVE_int2uint(exe_i_pop(&exe));
unsigned int values[count];
expected_value = __ch_malloc(expected_value);
char * strp = expected_value;
for (int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
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);
strp+=printed;
all_printed+=printed;
for (int j=0; j<count; j++) {
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, VALUESTRLEN-all_printed, " [%i]=%u",j, values[j]);
strp+=printed;
@ -326,16 +337,16 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
ret = check_tag_has_some_of_these_values(ctif, exe.tag, count, values);
break;
}
case fc_tag_has_valuelist: { int count = exe_i_pop(&exe);
case fc_tag_has_valuelist: { unsigned int count = SAVE_int2uint(exe_i_pop(&exe));
unsigned int values[count];
expected_value = __ch_malloc(expected_value);
char * strp = expected_value;
for (int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
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);
strp+=printed;
all_printed+=printed;
for (int j=0; j<count; j++) {
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, VALUESTRLEN, " [%i]=%u",j, values[j]);
strp+=printed;

Loading…
Cancel
Save