summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-05 15:49:51 +0100
committerSam James <sam@gentoo.org>2024-08-05 21:38:56 +0100
commit7d8e163ca6b60c35f8d5baff18a2be781e9a97e5 (patch)
tree742eb4fffac694bccbfef9b0c2601a131b8bb9ee
parentmeson.build: prepare for gentoo-functions-1.7 (diff)
downloadgentoo-functions-7d8e163ca6b60c35f8d5baff18a2be781e9a97e5.tar.gz
gentoo-functions-7d8e163ca6b60c35f8d5baff18a2be781e9a97e5.tar.bz2
gentoo-functions-7d8e163ca6b60c35f8d5baff18a2be781e9a97e5.zip
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@bricart.de> Signed-off-by: Kerin Millar <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--functions.sh6
-rwxr-xr-xtest-functions22
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