diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 36dad0de9..2756e9cc8 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -32,7 +32,7 @@ #include "memstreams.h" #define MAX_FILLER 11 -#define FLOAT_PRECISION 5 +#define FLOAT_PRECISION 9 static char *long_to_string_with_divisor(char *p, long num, @@ -73,14 +73,13 @@ static char *ltoa(char *p, long num, unsigned radix) { } #if CHPRINTF_USE_FLOAT -static long pow10[] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, - 100000000, 1000000000, 10000000000, 100000000000, - 1000000000000, 10000000000000}; +static long pow10[FLOAT_PRECISION] = {10, 100, 1000, 10000, 100000, 1000000, + 10000000, 100000000, 1000000000}; static char *ftoa(char *p, double num, unsigned long precision) { long l; - if (precision == 0) + if ((precision == 0) || (precision > FLOAT_PRECISION)) precision = FLOAT_PRECISION; precision = pow10[precision - 1];