Fix modification of string literal by swprintf

Thomas Preudhomme
Mon Jun 5 08:59:00 GMT 2017

Don't over-read memory returned by _DTOA_R, and never write to it
since the result might be a string literal.

For example, when doing:
   swprintf(tt, 20, L"%.*f", 6, 0.0);

we will get back "0".

Instead, write the result returned by _DTOA_R to the output buffer.
After this, write the 0 chars directly to the the output buffer
(if there are any). This also has the (marginal) advantage that
we read/write less memory overall.

The patch, contributed by Silviu Baranga was tested against libcxx testsuite and 
showed no regression. Please find the patch in git format-patch format in 

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Don-t-overread-or-write-memory-returned-by-_DTOA_R.patch
Type: text/x-patch
Size: 2768 bytes
Desc: not available
URL: <>

More information about the Newlib mailing list