public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-3019] libstdc++: Improve overflow check for file timestamps
Date: Thu, 19 Aug 2021 12:02:52 +0000 (GMT)	[thread overview]
Message-ID: <20210819120252.B5C5039B704D@sourceware.org> (raw)

https://gcc.gnu.org/g:65441d8fc3c132a58c8bef6faefa2bc25e82a913

commit r12-3019-g65441d8fc3c132a58c8bef6faefa2bc25e82a913
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 19 11:03:01 2021 +0100

    libstdc++: Improve overflow check for file timestamps
    
    The current code assumes that system_clock::duration is nanoseconds, and
    also performs a value-changing conversion from nanoseconds::max() to
    double (which doesn't matter after dividing by 1e9, but triggers a
    warning with Clang nonetheless).
    
    A better solution is to use system_clock::duration::max() and perform
    the comparison entirely using the std::chrono types, rather than with
    dimensionless arithmetic types.
    
    This doesn't address the FIXME in the function, so the overflow check
    still rejects some values that could be represented by the file_clock.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * src/filesystem/ops-common.h (filesystem::file_time): Improve
            overflow check by using system_clock::duration::max().

Diff:
---
 libstdc++-v3/src/filesystem/ops-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h
index 304e5b263fb..bf26c06b7b5 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -229,7 +229,7 @@ namespace __gnu_posix
     // (This only applies to the C++17 Filesystem library, because for the
     // Filesystem TS we don't have a distinct __file_clock, we just use the
     // system clock for file timestamps).
-    if (s >= (nanoseconds::max().count() / 1e9))
+    if (seconds{s} >= floor<seconds>(system_clock::duration::max()))
       {
 	ec = std::make_error_code(std::errc::value_too_large); // EOVERFLOW
 	return system_clock::time_point::min();


                 reply	other threads:[~2021-08-19 12:02 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=20210819120252.B5C5039B704D@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).