From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Another small adjustment to System.Value_R
Date: Wed, 16 Dec 2020 08:15:34 -0500 [thread overview]
Message-ID: <20201216131534.GA69687@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 232 bytes --]
This makes the code more explicit for the sake of static analyzers.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/s-valuer.adb (Scan_Decimal_Digits): Tweak overflow test.
(Scan_Integral_Digits): Likewise.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1991 bytes --]
diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -236,12 +236,15 @@ package body System.Value_R is
Temp := Value * Uns (Base) + Uns (Digit);
-- Check if Temp is larger than Precision_Limit, taking into
- -- account that Temp may have wrapped around.
+ -- account that Temp may wrap around when Precision_Limit is
+ -- equal to the largest integer.
if Value <= Umax
or else (Value <= UmaxB
- and then Temp <= Precision_Limit
- and then Temp >= Uns (Base))
+ and then ((Precision_Limit < Uns'Last
+ and then Temp <= Precision_Limit)
+ or else (Precision_Limit = Uns'Last
+ and then Temp >= Uns (Base))))
then
Value := Temp;
Scale := Scale - 1;
@@ -386,12 +389,15 @@ package body System.Value_R is
Temp := Value * Uns (Base) + Uns (Digit);
-- Check if Temp is larger than Precision_Limit, taking into
- -- account that Temp may have wrapped around.
+ -- account that Temp may wrap around when Precision_Limit is
+ -- equal to the largest integer.
if Value <= Umax
or else (Value <= UmaxB
- and then Temp <= Precision_Limit
- and then Temp >= Uns (Base))
+ and then ((Precision_Limit < Uns'Last
+ and then Temp <= Precision_Limit)
+ or else (Precision_Limit = Uns'Last
+ and then Temp >= Uns (Base))))
then
Value := Temp;
reply other threads:[~2020-12-16 13:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201216131534.GA69687@adacore.com \
--to=derodat@adacore.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).