[PATCH] newlib: fix uninitialized character count being used when printing float without "_printf_float" being linked

Igor Petrov <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Patch fixes wrong number of written characters being returend from 'printf'
family of functionsx when '_printf_float' is not linked (nano.specs). If user
tries to print a floating point number anyway, returned number of written
characters is not correct. For example in
    printf("%d%f", 1, 1.0);
should return 1, but actaully returns 2.

---
 newlib/libc/machine/msp430/tiny-printf.c | 1 +
 newlib/libc/stdio/nano-vfprintf.c        | 1 +
 2 files changed, 2 insertions(+)

diff --git a/newlib/libc/machine/msp430/tiny-printf.c b/newlib/libc/machine/msp430/tiny-printf.c
index f2412a0e6..b5ad5284c 100644
--- a/newlib/libc/machine/msp430/tiny-printf.c
+++ b/newlib/libc/machine/msp430/tiny-printf.c
@@ -237,6 +237,7 @@ __tiny_vfprintf_r (struct _reent *data,
 		GET_ARG (N, ap_copy, _LONG_DOUBLE);
 	      else
 		GET_ARG (N, ap_copy, double);
+	      n = 0;
 	    }
 	  else
             n = _printf_float (data, &prt_data, fp, pfunc, &ap_copy);
diff --git a/newlib/libc/stdio/nano-vfprintf.c b/newlib/libc/stdio/nano-vfprintf.c
index 0d42a940f..bdcc9b218 100644
--- a/newlib/libc/stdio/nano-vfprintf.c
+++ b/newlib/libc/stdio/nano-vfprintf.c
@@ -627,6 +627,7 @@ _VFPRINTF_R (struct _reent *data,
 		GET_ARG (N, ap_copy, _LONG_DOUBLE);
 	      else
 		GET_ARG (N, ap_copy, double);
+	      n = 0;
 	    }
 	  else
             n = _printf_float (data, &prt_data, fp, pfunc, &ap_copy);
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.