X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fmware%2Fformatwr.c;h=996f8df04c5e7562d100f5760a86765cb8c15eb5;hb=6b98b0991528daa601e3b732b92c343d2752749f;hp=cbea0612db029878b7ed6902f227bba44db25610;hpb=6eb6ebb5ae5953a27977f0ef66a36344462b949a;p=bertos.git diff --git a/bertos/mware/formatwr.c b/bertos/mware/formatwr.c index cbea0612..996f8df0 100644 --- a/bertos/mware/formatwr.c +++ b/bertos/mware/formatwr.c @@ -46,21 +46,21 @@ * -D CONFIG_PRINTF=PRINTF_FULL Full ANSI printf formatter, with some C99 extensions * -D CONFIG_PRINTF=PRINTF_NOFLOAT Exclude support for floats * -D CONFIG_PRINTF=PRINTF_REDUCED Simplified formatter (see below) - * -D CONFIG_PRINTF=PRINTF_NOMODIFIERS Exclude 'l', 'z' and 'h' modifiers in reduced version + * -D CONFIG_PRINTF=PRINTF_NOMODIFIERS Exclude "l", "z" and "h" modifiers in reduced version * -D CONFIG_PRINTF=PRINTF_DISABLED No formatter at all * \endcode * * Code size on AVR4 with GCC 3.4.1 (-O2): - * PRINTF_FULL 2912byte (0xB60) - * PRINTF_NOFLOAT 1684byte (0x694) - * PRINTF_REDUCED 924byte (0x39C) - * PRINTF_NOMODIFIERS 416byte (0x1A0) + * \li PRINTF_FULL 2912byte (0xB60) + * \li PRINTF_NOFLOAT 1684byte (0x694) + * \li PRINTF_REDUCED 924byte (0x39C) + * \li PRINTF_NOMODIFIERS 416byte (0x1A0) * * Code/data size in words on DSP56K with CodeWarrior 6.0: - * PRINTF_FULL 1493/45 - * PRINTF_NOFLOAT 795/45 - * PRINTF_REDUCED 482/0 - * PRINTF_NOMODIFIERS 301/0 + * \li PRINTF_FULL 1493/45 + * \li PRINTF_NOFLOAT 795/45 + * \li PRINTF_REDUCED 482/0 + * \li PRINTF_NOMODIFIERS 301/0 * * The reduced version of formatter is suitable when program size is critical * rather than formatting power. This routine uses less than 20 bytes of @@ -106,15 +106,25 @@ /* Maximum precision for floating point values */ typedef long double max_float_t; - /*bernie: save some memory, who cares about floats with lots of decimals? */ - #define FRMWRI_BUFSIZE 134 - #warning 134 is too much, the code must be fixed to have a lower precision limit + #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) + * Use a high value to avoid unexpected buffer overflows. + */ + #define FRMWRI_BUFSIZE 134 + #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. */