fix minmea_scan("f") overflow
This commit is contained in:
parent
1e802f6d00
commit
3e3420d1ab
13
minmea.c
13
minmea.c
@ -148,9 +148,20 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
} else if (*field == '-' && !sign && value == -1) {
|
} else if (*field == '-' && !sign && value == -1) {
|
||||||
sign = -1;
|
sign = -1;
|
||||||
} else if (isdigit((unsigned char) *field)) {
|
} else if (isdigit((unsigned char) *field)) {
|
||||||
|
int digit = *field - '0';
|
||||||
if (value == -1)
|
if (value == -1)
|
||||||
value = 0;
|
value = 0;
|
||||||
value = (10 * value) + (*field - '0');
|
if (value > (INT_LEAST32_MAX-digit) / 10) {
|
||||||
|
/* we ran out of bits, what do we do? */
|
||||||
|
if (scale) {
|
||||||
|
/* truncate extra precision */
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
/* integer overflow. bail out. */
|
||||||
|
goto parse_error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = (10 * value) + digit;
|
||||||
if (scale)
|
if (scale)
|
||||||
scale *= 10;
|
scale *= 10;
|
||||||
} else if (*field == '.' && scale == 0) {
|
} else if (*field == '.' && scale == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user