NewLib nano fprintf_float uppercase format

Bug #1470494 reported by Anfrid
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Invalid
Undecided
Unassigned

Bug Description

Hi, I try to format double value with useing linker key :
--specs=nano.specs -u _printf_float

If I use like this:

snprintf(buf, bufLen, fullLen, "%s%.*F", p, accuracy, value)

or that

snprintf(buf, bufLen, fullLen, "%s%.4F", p, value)

the snpintf function behaves incorrectly but if I use

snprintf(buf, bufLen, fullLen, "%s%F", p, value)

or

snprintf(buf, bufLen, fullLen, "%s%.4f", p, value)

it`s ok.

This bug I found in gcc version 4.9.3 20150303 (release) [ARM/embedded-4_9-branch revision 221220]
GNU Tools for ARM Embedded Processors)

I looked in file nano-vfpintf_float.c in newlib nano and for specificator 'g' and 'G' code
in line number 239 looks like this

if (code == 'g' || code == 'G')
{
      if (expt <= -4 || expt > pdata->prec)
 /* 'e' or 'E'. */
 code -= 2;
      else
 code = 'g';
}
...

but in line number 258 compare is present only for small 'f' char

if (code == 'f')
{
   /* 'f' fmt. */
   if (expt > 0)
     {
       pdata->size = expt;
       if (pdata->prec || pdata->flags & ALT)
  pdata->size += pdata->prec + 1;
     }
   else
     /* "0.X". */
     pdata->size = (pdata->prec || pdata->flags & ALT)
       ? pdata->prec + 2 : 1;
}

Anfrid (dessel-k)
description: updated
Anfrid (dessel-k)
description: updated
Anfrid (dessel-k)
description: updated
description: updated
description: updated
description: updated
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

Hi Anfrid,

the 'F' specifier was introduced as part of C99 and nano targets C89 printf in order to save space. If you need the F specifier you will have to use newlib.

Best regards.

Changed in gcc-arm-embedded:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.