Fix parsing of time specification with trailing spaces ()

This commit is contained in:
Nick Black 2019-08-02 10:33:07 -04:00 committed by Christian W. Zuckschwerdt
parent 9d32825cd9
commit b32ffeec35
3 changed files with 11 additions and 3 deletions

View file

@ -75,7 +75,7 @@ void am_analyze(am_analyze_t *a, int16_t *am_buf, unsigned n_samples, int debug_
a->signal_pulse_counter++;
if (a->signal_pulse_counter >= PULSE_DATA_SIZE) {
a->signal_pulse_counter = 0;
fprintf(stderr, "To many pulses detected, probably bad input data or input parameters\n");
fprintf(stderr, "Too many pulses detected, probably bad input data or input parameters\n");
return;
}
}

View file

@ -160,7 +160,7 @@ int atoi_time(const char *str, const char *error_hint)
double val = 0.0;
unsigned colons = 0;
while (*endptr) {
do {
double num = strtod(str, &endptr);
if (str == endptr) {
@ -179,6 +179,7 @@ int atoi_time(const char *str, const char *error_hint)
val += num;
break;
}
// intentional fallthrough
case ':':
++colons;
if (colons == 1)
@ -218,8 +219,13 @@ int atoi_time(const char *str, const char *error_hint)
fprintf(stderr, "%sunknown time suffix (%s)\n", error_hint, endptr);
exit(1);
}
// chew up any remaining whitespace
while (*endptr == ' ' || *endptr == '\t')
++endptr;
str = endptr;
}
} while (*endptr);
if (val > INT_MAX || val < INT_MIN) {
fprintf(stderr, "%stime argument too big (%f)\n", error_hint, val);

View file

@ -26,6 +26,8 @@ static int style_check(char *path)
{
FILE *fp = fopen(path, "r");
assert(fp);
if(!fp)
exit(EXIT_FAILURE);
int read_errors = 0;
int long_errors = 0;