Fix Integer Overflow

This commit is contained in:
karas 2018-02-22 13:28:31 +09:00 committed by cmorganBE
parent 252a3f9d3b
commit becf6aa58d

View File

@ -260,6 +260,10 @@ static inline float minmea_tocoord(const struct minmea_float *f)
{ {
if (f->scale == 0) if (f->scale == 0)
return NAN; return NAN;
if (f->scale > (INT_LEAST32_MAX / 100))
return NAN;
if (f->scale < (INT_LEAST32_MIN / 100))
return NAN;
int_least32_t degrees = f->value / (f->scale * 100); int_least32_t degrees = f->value / (f->scale * 100);
int_least32_t minutes = f->value % (f->scale * 100); int_least32_t minutes = f->value % (f->scale * 100);
return (float) degrees + (float) minutes / (60 * f->scale); return (float) degrees + (float) minutes / (60 * f->scale);