commit:     7d8e163ca6b60c35f8d5baff18a2be781e9a97e5
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Aug  5 14:49:51 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  5 20:38:56 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=7d8e163c

Ensure a radix character of U+2E in _update_time()

I overlooked that bash respects the radix character defined by the
locale in the course of synthesizing the value of the EPOCHREALTIME
value. Set LC_NUMERIC as C to guarantee that the radix character is
considered as U+2E (FULL STOP) within the scope of the bash-specific
function. Doing so also addresses a distinct issue whereby the
invocation of printf was sensitive to the implied value of LC_NUMERIC.

Another way to address this would have been to set LC_ALL as C. I
decided not to because it would decrease the likelihood of the relevant
diagnostic messages being rendered in the user's native language.

Additionally, add a test case.

Closes: https://bugs.gentoo.org/937376
Reported-by: Christian Bricart <christian <AT> bricart.de>
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh   |  6 ++++--
 test-functions | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/functions.sh b/functions.sh
index bea948f..561a98f 100644
--- a/functions.sh
+++ b/functions.sh
@@ -761,7 +761,9 @@ _update_time()
                # shellcheck disable=2034,3045
                _update_time()
                {
-                       local cs s timeval
+                       # Setting LC_NUMERIC as C ensures a radix character of
+                       # U+2E, duly affecting both EPOCHREALTIME and printf.
+                       local LC_ALL LC_NUMERIC=C cs s timeval
 
                        timeval=${EPOCHREALTIME}
                        s=${timeval%.*}
@@ -784,7 +786,7 @@ _update_time()
        else
                _update_time()
                {
-                       false
+                       return 2
                }
        fi
 

diff --git a/test-functions b/test-functions
index 561ddc5..14bb49f 100755
--- a/test-functions
+++ b/test-functions
@@ -875,6 +875,27 @@ test_deref() {
        iterate_tests 4 "$@"
 }
 
+test_update_time() {
+       retval=0
+       genfun_time=$(_update_time && printf %s "${genfun_time}")
+       case $? in
+               0)
+                       is_int "${genfun_time}"
+                       ;;
+               2)
+                       # Unsupported for the platform and therefore untestable.
+                       ;;
+               *)
+                       false
+       esac ||
+       {
+               printf 'not '
+               retval=1
+       }
+       printf 'ok %d - _update_time (test %d -eq 0)\n' "$((testnum += 1))" 
"${retval}"
+       return "${retval}"
+}
+
 iterate_tests() {
        slice_width=$1
        shift
@@ -955,6 +976,7 @@ else
        test_quote_args || rc=1
        test_assign || rc=1
        test_deref || rc=1
+       test_update_time || rc=1
 fi
 
 cleanup_tmpdir

Reply via email to