From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Robert Dewar <dewar@adacore.com>
Subject: [Ada] Fix undetected overflow case in Ada.Real_Time."/"
Date: Tue, 12 May 2015 08:11:00 -0000 [thread overview]
Message-ID: <20150512080750.GA19742@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 819 bytes --]
Despite the explicit pragma Unsuppress statements, the case of dividing
Time_Span_First by -1 did not raise an exception. Eventually this should
be corrected at the compiler or runtime level, but for now, we add an
explicit check to ensure that this case is caught.
The following test program:
1. with Ada.Real_Time; use Ada.Real_Time;
2. procedure ReaTimOv is
3. Result : Time_Span;
4. begin
5. Result :=
6. Ada.Real_Time."/"
7. (Left => Ada.Real_Time.Time_Span_First,
8. Right => -1);
9. end;
must yield when executed:
raised CONSTRAINT_ERROR : Ada.Real_Time."/": overflow
Tested on x86_64-pc-linux-gnu, committed on trunk
2015-05-12 Robert Dewar <dewar@adacore.com>
* a-reatim.adb ("/"): Add explicit check for Time_Span_First / -1.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1459 bytes --]
Index: a-reatim.adb
===================================================================
--- a-reatim.adb (revision 223033)
+++ a-reatim.adb (working copy)
@@ -7,7 +7,7 @@
-- B o d y --
-- --
-- Copyright (C) 1991-1994, Florida State University --
--- Copyright (C) 1995-2014, AdaCore --
+-- Copyright (C) 1995-2015, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -123,6 +123,16 @@
pragma Unsuppress (Overflow_Check);
pragma Unsuppress (Division_Check);
begin
+ -- Even though checks are unsuppressed, we need an explicit check for
+ -- the case of largest negative integer divided by minus one, since
+ -- some library routines we use fail to catch this case. This will be
+ -- fixed at the compiler level in the future, at which point this test
+ -- can be removed.
+
+ if Left = Time_Span_First and then Right = -1 then
+ raise Constraint_Error with "overflow";
+ end if;
+
return Time_Span (Duration (Left) / Right);
end "/";
reply other threads:[~2015-05-12 8:07 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=20150512080750.GA19742@adacore.com \
--to=charlet@adacore.com \
--cc=dewar@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).