Index: base/message_loop/message_pump_win.cc |
diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc |
index a7a14859280f81d63015ab8bb99f8346551079d3..bfc1d51e59b04cb76ee7d61e6ee541082a810f02 100644 |
--- a/base/message_loop/message_pump_win.cc |
+++ b/base/message_loop/message_pump_win.cc |
@@ -4,6 +4,7 @@ |
#include "base/message_loop/message_pump_win.h" |
+#include <limits> |
#include <math.h> |
#include "base/debug/trace_event.h" |
@@ -70,12 +71,13 @@ int MessagePumpWin::GetCurrentDelay() const { |
double timeout = |
ceil((delayed_work_time_ - TimeTicks::Now()).InMillisecondsF()); |
- // If this value is negative, then we need to run delayed work soon. |
- int delay = static_cast<int>(timeout); |
- if (delay < 0) |
- delay = 0; |
- |
- return delay; |
+ // Range check the |timeout| while converting to an integer. If the |timeout| |
+ // is negative, then we need to run delayed work soon. If the |timeout| is |
+ // "overflowingly" large, that means a delayed task was posted with a |
+ // super-long delay. |
+ return timeout < 0 ? 0 : |
+ (timeout > std::numeric_limits<int>::max() ? |
darin (slow to review)
2015/01/27 07:52:39
you didn't want to use the max_int / 2 comparison
|
+ std::numeric_limits<int>::max() : static_cast<int>(timeout)); |
} |
//----------------------------------------------------------------------------- |