From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D49C7159C9B for ; Mon, 5 Aug 2024 20:39:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DABF9E2A8E; Mon, 5 Aug 2024 20:39:17 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6A429E2A8E for ; Mon, 5 Aug 2024 20:39:17 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 50A3634133B for ; Mon, 5 Aug 2024 20:39:16 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 612D0E6F for ; Mon, 5 Aug 2024 20:39:14 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1722890336.7d8e163ca6b60c35f8d5baff18a2be781e9a97e5.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh test-functions X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 7d8e163ca6b60c35f8d5baff18a2be781e9a97e5 X-VCS-Branch: master Date: Mon, 5 Aug 2024 20:39:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2b58f2dc-4b9c-46c4-91a9-02f09c90983c X-Archives-Hash: 1f0a19e4d4e01c50193694e608e13637 commit: 7d8e163ca6b60c35f8d5baff18a2be781e9a97e5 Author: Kerin Millar plushkava net> AuthorDate: Mon Aug 5 14:49:51 2024 +0000 Commit: Sam James gentoo 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 bricart.de> Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James 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