On 19/11/2024 04:38, Grisha Levit wrote:
See the following two chunks from the test suite log on macOS 15:

+ printf_check '   0 1  ' '%100$*d %s %s %s\n' 4 1
+ cat
+ shift
+ env printf '%100$*d %s %s %s\n' 4 1
printf: '': Invalid argument
+ fail=1

+ printf_check_err 'printf: '\''A'\'': expected a numeric value' '%0x2$s 
%2$s\n' A B
+ cat
+ shift
+ returns_ 1 env printf '%0x2$s %2$s\n' A B
02$s B
+ compare exp out
+ compare_dev_null_ exp out
+ test 2 = 2
+ test xexp = x/dev/null
+ test xout = x/dev/null
+ return 2
+ case $? in
+ compare_ exp out
+ LC_ALL=C
+ diff -u exp out
--- exp 2024-11-18 23:32:01.486843241 -0500
+++ out 2024-11-18 23:32:01.492438694 -0500
@@ -1 +1 @@
-printf: 'A': expected a numeric value
+printf: 'A': Invalid argument
+ fail=1

This is due to inconsistency in how strtol and strtoimax operate on macos.
The man page for those on macos states:

  "If no conversion could be performed, 0 is returned and the global variable errno  
 is set to EINVAL (the last feature is not portable across all platforms)."

So in particular, we'll have to handle the NUL string in code,
to ensure it returns 0, and adjust the test to treat EINVAL
like "expected a numeric value".

I've not got access to a macos system to test currently,
but the attached should address this.

Marking this as done.

thanks,
Pádraig
From d89825c315cbf5399d6bab5667b4e65e3ad84883 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Tue, 19 Nov 2024 15:02:03 +0000
Subject: [PATCH] printf: ensure empty strings correspond to 0

* src/printf.c (STRTOX): Ensure we print 0 for empty strings.
This avoids EINVAL on macos at least.
* tests/printf/printf-indexed.sh: Adjust EINVAL error,
returned on macos for non empty invalid numeric strings,
to the corresponding internal error used on systems
that don't set errno in this case.
Fixes https://bugs.gnu.org/74427
---
 src/printf.c                   | 4 ++--
 tests/printf/printf-indexed.sh | 7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/printf.c b/src/printf.c
index fb11f84a9..c2fad733e 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -124,7 +124,7 @@ static TYPE								 \
 FUNC_NAME (char const *s)						 \
 {									 \
   char *end;								 \
-  TYPE val;								 \
+  TYPE val = 0;								 \
                                                                          \
   if ((*s == '\"' || *s == '\'') && *(s + 1))				 \
     {									 \
@@ -153,7 +153,7 @@ FUNC_NAME (char const *s)						 \
       if (*++s != 0 && !posixly_correct)				 \
         error (0, 0, _(cfcc_msg), s);					 \
     }									 \
-  else									 \
+  else if (*s)								 \
     {									 \
       errno = 0;							 \
       val = (LIB_FUNC_EXPR);						 \
diff --git a/tests/printf/printf-indexed.sh b/tests/printf/printf-indexed.sh
index 7a7744436..aa4e340b6 100755
--- a/tests/printf/printf-indexed.sh
+++ b/tests/printf/printf-indexed.sh
@@ -18,7 +18,7 @@
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ printf
-i
+
 getlimits_
 
 prog='env printf'
@@ -41,7 +41,10 @@ EOF
 
   shift
 
-  returns_ 1 $prog "$@" 2> out || fail=1
+  returns_ 1 $prog "$@" 2> out.t || fail=1
+  # Map EINVAL from systems like macos to internal error
+  sed -e 's/Invalid argument/expected a numeric value/' \
+    < out.t > out || framework_failure_
   compare exp out || fail=1
 }
 
-- 
2.47.0

Reply via email to