bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf inconsistent results for %.0f


From: Stephane Chazelas
Subject: Re: printf inconsistent results for %.0f
Date: Thu, 19 Sep 2024 06:39:36 +0100

2024-08-14 09:11:05 -0400, Chet Ramey:
> On 8/13/24 7:05 PM, Grisha Levit wrote:
> > On Mon, Aug 12, 2024, 11:04 Chet Ramey <chet.ramey@case.edu
> > <mailto:chet.ramey@case.edu>> wrote:
> > 
> >     My question is why the (admittedly old) gnulib replacement 
> > strtod/strtold
> >     is messing things up.
> > 
> > 
> > Looks like printf(3) gets called with a `Lf' conversation specifier and
> > a double argument.
> 
> Yes, I came to the same conclusion with an essentially identical fix.
[...]

Would it be possible to have a 5.2 patch released with the
backport of those two fixes?

At the moment, all systems where bash is built with gcc 14 (such
as Debian trixie
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1078556) where
-Werror=incompatible-pointer-type is now the default
(https://gcc.gnu.org/gcc-14/porting_to.html#incompatible-pointer-types)
have a broken bash printf builtin.

Extracted from the "devel" branch on the git repo:

commit 55a224da44768bdcb57603a135657919cf08c2f7
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Fri Nov 24 12:39:17 2023 -0500

    fix for fdflags loadable builtin; new strptime loadable builtin; enable -f 
doesn't fall back to current directory if using BASH_LOADABLES_PATH; new 
operator for rl_complete_internal that just dumps possible completions

diff --git a/configure.ac b/configure.ac
index fa5f5747..c25a8088 100644
--- a/configure.ac
+++ b/configure.ac
@@ -898,7 +899,7 @@ AC_CHECK_DECLS([strtold], [
        [AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM(
                [[#include <stdlib.h>]],
-               [[long double r; char *foo, bar; r = strtold(foo, &bar);]]
+               [[long double r; char *foo, *bar; r = strtold(foo, &bar);]]
        )],
        [bash_cv_strtold_broken=no],[bash_cv_strtold_broken=yes])
         ]

commit e327891b52513bef0b34aac625c44f8fa6811f53
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Wed Aug 21 16:11:01 2024 -0400

    fix for printf with broken strtold; fix readline reading specified number 
of multibyte characters; fix read builtin to deal with invalid utf-8 
continuation character as delimiter; turn off -n if supplied at interactive 
shell invocation

diff --git a/builtins/printf.def b/builtins/printf.def
index 6549e718..18f3f659 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -209,11 +209,13 @@ static uintmax_t getuintmax (void);
 typedef long double floatmax_t;
 #  define USE_LONG_DOUBLE 1
 #  define FLOATMAX_CONV        "L"
+#  define FLOATMAX_CONVLEN 1
 #  define strtofltmax  strtold
 #else
 typedef double floatmax_t;
 #  define USE_LONG_DOUBLE 0
 #  define FLOATMAX_CONV        ""
+#  define FLOATMAX_CONVLEN 0
 #  define strtofltmax  strtod
 #endif
 static double getdouble (void);
@@ -782,7 +784,7 @@ printf_builtin (WORD_LIST *list)
                    floatmax_t p;
 
                    p = getfloatmax ();
-                   f = mklong (start, "L", 1);
+                   f = mklong (start, FLOATMAX_CONV, FLOATMAX_CONVLEN);
                    PF (f, p);
                  }
                else            /* posixly_correct */


Thanks,
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]