From 34b2a78c7c59a3357d05dfff157908d5d9b98501 Mon Sep 17 00:00:00 2001 From: lottaviano Date: Thu, 17 Sep 2009 10:29:29 +0000 Subject: [PATCH] Use configuration value for formatter bufsize. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2962 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/cfg_formatwr.h | 10 ++++++++++ bertos/mware/formatwr.c | 27 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bertos/cfg/cfg_formatwr.h b/bertos/cfg/cfg_formatwr.h index bafad70b..ba08654c 100644 --- a/bertos/cfg/cfg_formatwr.h +++ b/bertos/cfg/cfg_formatwr.h @@ -52,6 +52,16 @@ */ #define CONFIG_PRINTF PRINTF_FULL +/** + * Size of buffer to format "%" sequences in printf. + * + * Warning: no check on buffer size is done when formatting, be careful especially + * with big numbers and %f formatting. + * + * $WIZ$ type = "int" + * $WIZ$ min = 4 + */ +#define CONFIG_FRMWRI_BUFSIZE 20 #endif /* CFG_FORMATWR_H */ diff --git a/bertos/mware/formatwr.c b/bertos/mware/formatwr.c index bf2672e9..afc4976e 100644 --- a/bertos/mware/formatwr.c +++ b/bertos/mware/formatwr.c @@ -106,16 +106,25 @@ /* Maximum precision for floating point values */ typedef long double max_float_t; - /*luca: FIXME: this should be enough to print floating point values, must be investigated - * further. - */ - #define FRMWRI_BUFSIZE 20 + #warning FIXME: be sure to fix buffer size below + #if CONFIG_FRMWRI_BUFSIZE + #define FRMWRI_BUFSIZE CONFIG_FRMWRI_BUFSIZE + #else + /* Conservative estimate. Max float is 3.40282e+038, so %f (but not %e or %g) must have + * space for: sign + all 38 digits + '.' + 6 decimal digits (default) + */ + #define FRMWRI_BUFSIZE 50 + #endif #else - /* - * Conservative estimate. Should be (probably) 12 (which is the size necessary - * to represent (2^32-1) in octal plus the sign bit. - */ - #define FRMWRI_BUFSIZE 16 + #if CONFIG_FRMWRI_BUFSIZE + #define FRMWRI_BUFSIZE CONFIG_FRMWRI_BUFSIZE + #else + /* + * Conservative estimate. Should be (probably) 12 (which is the size necessary + * to represent (2^32-1) in octal plus the sign bit. + */ + #define FRMWRI_BUFSIZE 16 + #endif #endif /* Probably useful for fancy microcontrollers such as the PIC, nobody knows. */ -- 2.25.1