Title: [175299] trunk/Source/WebKit2
Revision
175299
Author
[email protected]
Date
2014-10-28 21:04:19 -0700 (Tue, 28 Oct 2014)

Log Message

Cast std::chrono::duration.count() to int64_t in ArgumentCoder
https://bugs.webkit.org/show_bug.cgi?id=136981

Patch by Ting-Wei Lan <[email protected]> on 2014-10-28
Reviewed by Alexey Proskuryakov.

Explicitly cast the return value of std::chrono::duration.count() to
a fixed-size interger type, which prevents compilation error when
the return value type matches neither int32_t nor int64_t.

* Platform/IPC/ArgumentCoders.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (175298 => 175299)


--- trunk/Source/WebKit2/ChangeLog	2014-10-29 03:39:35 UTC (rev 175298)
+++ trunk/Source/WebKit2/ChangeLog	2014-10-29 04:04:19 UTC (rev 175299)
@@ -1,3 +1,16 @@
+2014-10-28  Ting-Wei Lan  <[email protected]>
+
+        Cast std::chrono::duration.count() to int64_t in ArgumentCoder
+        https://bugs.webkit.org/show_bug.cgi?id=136981
+
+        Reviewed by Alexey Proskuryakov.
+
+        Explicitly cast the return value of std::chrono::duration.count() to
+        a fixed-size interger type, which prevents compilation error when
+        the return value type matches neither int32_t nor int64_t.
+
+        * Platform/IPC/ArgumentCoders.h:
+
 2014-10-28  Jer Noble  <[email protected]>
 
         [EME] Pass location for media key storage through from WebKit/WebKit2.

Modified: trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h (175298 => 175299)


--- trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h	2014-10-29 03:39:35 UTC (rev 175298)
+++ trunk/Source/WebKit2/Platform/IPC/ArgumentCoders.h	2014-10-29 04:04:19 UTC (rev 175299)
@@ -107,15 +107,16 @@
 template<typename Rep, typename Period> struct ArgumentCoder<std::chrono::duration<Rep, Period>> {
     static void encode(ArgumentEncoder& encoder, const std::chrono::duration<Rep, Period>& duration)
     {
-        encoder << duration.count();
+        static_assert(std::is_integral<Rep>::value && std::is_signed<Rep>::value && sizeof(Rep) <= sizeof(int64_t), "Serialization of this Rep type is not supported yet. Only signed integer type which can be fit in an int64_t is currently supported.");
+        encoder << static_cast<int64_t>(duration.count());
     }
 
     static bool decode(ArgumentDecoder& decoder, std::chrono::duration<Rep, Period>& result)
     {
-        Rep count;
+        int64_t count;
         if (!decoder.decode(count))
             return false;
-        result = std::chrono::duration<Rep, Period>(count);
+        result = std::chrono::duration<Rep, Period>(static_cast<Rep>(count));
         return true;
     }
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to