Remove incorrect width adjustment that prevented proper padding
with spaces for %g format specifier for the following case:
printf("(%10g)\n", 100000.0f); // --> (100000)
Adds test case t_printf_g_width.
ref: https://github.com/skeeto/w64devkit/issues/269
Signed-off-by: Peter Damianov <[email protected]>
---
mingw-w64-crt/stdio/mingw_pformat.c | 15 ++++-----------
mingw-w64-crt/testcases/Makefile.am | 1 +
mingw-w64-crt/testcases/t_printf_g_width.c | 17 +++++++++++++++++
3 files changed, 22 insertions(+), 11 deletions(-)
create mode 100644 mingw-w64-crt/testcases/t_printf_g_width.c
diff --git a/mingw-w64-crt/stdio/mingw_pformat.c
b/mingw-w64-crt/stdio/mingw_pformat.c
index b7d3bfb41..4683cb5fe 100644
--- a/mingw-w64-crt/stdio/mingw_pformat.c
+++ b/mingw-w64-crt/stdio/mingw_pformat.c
@@ -1877,18 +1877,11 @@ void __pformat_gfloat( long double x, __pformat_t
*stream )
else
/* The `#' flag is not in effect...
- * Here we adjust the precision to accommodate all digits which
- * precede the radix point, but we truncate any balance following
- * it, to suppress output of non-significant trailing zeros...
+ * Calculate precision as the number of fractional digits to display.
+ * This equals total formatted length minus integer part length,
+ * effectively determining digits after the radix point.
*/
- if( ((stream->precision = strlen( value ) - intlen) < 0)
- /*
- * This may require a compensating adjustment to the field
- * width, to accommodate significant trailing zeros, which
- * precede the radix point...
- */
- && (stream->width > 0) )
- stream->width += stream->precision;
+ stream->precision = strlen( value ) - intlen;
/* Now, we format the result as any other fixed point value.
*/
diff --git a/mingw-w64-crt/testcases/Makefile.am
b/mingw-w64-crt/testcases/Makefile.am
index b9184e284..61712229c 100644
--- a/mingw-w64-crt/testcases/Makefile.am
+++ b/mingw-w64-crt/testcases/Makefile.am
@@ -30,6 +30,7 @@ testcase_progs = \
t_mbrtowc \
t_mbsrtowcs \
t_nullptrexception \
+ t_printf_g_width \
t_readdir \
t_snprintf \
t_snprintf0 \
diff --git a/mingw-w64-crt/testcases/t_printf_g_width.c
b/mingw-w64-crt/testcases/t_printf_g_width.c
new file mode 100644
index 000000000..6afba0cb5
--- /dev/null
+++ b/mingw-w64-crt/testcases/t_printf_g_width.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+ char buffer[64];
+
+ // Test the %g width specifier
+ // This should output "( 100000)" with 4 leading spaces
+ int ret = snprintf(buffer, sizeof(buffer), "(%10g)", 100000.0f);
+
+ if (strcmp(buffer, "( 100000)") != 0) {
+ fprintf(stderr, "FAIL: Expected '( 100000)', got '%s'\n", buffer);
+ return 1;
+ }
+
+ return 0;
+}
\ No newline at end of file
--
2.39.5
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public