[libcxx] r282660 - Partially revert overflow checking in last_write_time

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 18:01:26 PDT 2016


Author: ericwf
Date: Wed Sep 28 20:01:26 2016
New Revision: 282660

URL: http://llvm.org/viewvc/llvm-project?rev=282660&view=rev
Log:
Partially revert overflow checking in last_write_time

Modified:
    libcxx/trunk/src/experimental/filesystem/operations.cpp

Modified: libcxx/trunk/src/experimental/filesystem/operations.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=282660&r1=282659&r2=282660&view=diff
==============================================================================
--- libcxx/trunk/src/experimental/filesystem/operations.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/operations.cpp Wed Sep 28 20:01:26 2016
@@ -544,16 +544,14 @@ file_time_type __last_write_time(const p
         set_or_throw(m_ec, ec, "last_write_time", p);
         return file_time_type::min();
     }
+    if (ec) ec->clear();
+    auto ts = detail::extract_mtime(st);
 #ifndef _LIBCPP_HAS_NO_INT128
     using IntMax = __int128_t;
-#else
-    using IntMax = intmax_t;
-#endif
     // FIXME: The value may not be representable as file_time_type. Fix
     // file_time_type so it can represent all possible values returned by the
     // filesystem. For now we do the calculation with the largest possible types
     // and then truncate, this prevents signed integer overflow bugs.
-    auto ts = detail::extract_mtime(st);
     const auto NsDur = duration<IntMax, nano>(ts.tv_nsec) + seconds(ts.tv_sec);
     if (NsDur > file_time_type::max().time_since_epoch() ||
         NsDur < file_time_type::min().time_since_epoch()) {
@@ -561,8 +559,12 @@ file_time_type __last_write_time(const p
                      "last_write_time", p);
         return file_time_type::min();
     }
-     if (ec) ec->clear();
     return file_time_type(duration_cast<file_time_type::duration>(NsDur));
+#else
+    // FIXME the under/overflow check done above overflows if we don't have
+    // a 128 bit integer type.
+    return file_time_type::clock::from_time_t(ts.tv_sec);
+#endif
 }
 
 void __last_write_time(const path& p, file_time_type new_time,




More information about the cfe-commits mailing list