summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2016-12-15 15:52:55 (GMT)
committerStefan Radomski <github@mintwerk.de>2016-12-15 15:52:55 (GMT)
commit7c7b9653f843588ae60d92c6f7d1477d7bbc5f05 (patch)
tree028227f8bf0f0e7262f1a1d0379549f17686eeb3
parente7747902e509cdbf895af3a7bc2025fe8193e3f7 (diff)
downloaduscxml-7c7b9653f843588ae60d92c6f7d1477d7bbc5f05.zip
uscxml-7c7b9653f843588ae60d92c6f7d1477d7bbc5f05.tar.gz
uscxml-7c7b9653f843588ae60d92c6f7d1477d7bbc5f05.tar.bz2
Prevented overflow with size_t::max for durations
-rw-r--r--src/uscxml/interpreter/BasicEventQueue.cpp20
-rw-r--r--src/uscxml/interpreter/InterpreterImpl.h3
2 files changed, 12 insertions, 11 deletions
diff --git a/src/uscxml/interpreter/BasicEventQueue.cpp b/src/uscxml/interpreter/BasicEventQueue.cpp
index 104c9fa..2f8bd48 100644
--- a/src/uscxml/interpreter/BasicEventQueue.cpp
+++ b/src/uscxml/interpreter/BasicEventQueue.cpp
@@ -22,8 +22,6 @@
#include <event2/thread.h>
#include <assert.h>
-//#include <iostream>
-
#include "uscxml/interpreter/Logging.h"
namespace uscxml {
@@ -37,19 +35,21 @@ Event BasicEventQueue::dequeue(size_t blockMs) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
if (blockMs > 0) {
+ using namespace std::chrono;
- // block for given milliseconds or until queue is non-empty
- auto endTime = std::chrono::system_clock::now() + std::chrono::milliseconds(blockMs);
-// std::time_t ttp = std::chrono::system_clock::to_time_t(endTime);
-// std::cout << "End: " << ttp << std::endl;
-// std::cout << "Now: " << std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) << std::endl;
+ // TODO: do read http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm
+ system_clock::time_point now = system_clock::now();
+ system_clock::time_point endTime = now + milliseconds(blockMs);
+ // now + milliseconds(blockMs) may not have fitted into a duration type - limit to maximum duration
+ if (blockMs > system_clock::duration::max().count() - duration_cast<milliseconds>(now.time_since_epoch()).count()) {
+ endTime = system_clock::time_point::max();
+ }
+
+ // block for given milliseconds or until queue is non-empty
while (endTime > std::chrono::system_clock::now() && _queue.empty()) {
_cond.wait_until(_mutex, endTime);
-// std::cout << "Aft: " << std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) << std::endl;
-// std::cout << blockMs << ".";
}
-
}
if (_queue.size() > 0) {
diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h
index f4fe93e..1243f7c 100644
--- a/src/uscxml/interpreter/InterpreterImpl.h
+++ b/src/uscxml/interpreter/InterpreterImpl.h
@@ -25,6 +25,7 @@
#include <list>
#include <map>
#include <string>
+#include <limits>
#include "uscxml/Common.h"
#include "uscxml/util/URL.h"
@@ -107,7 +108,7 @@ public:
MicrostepCallbacks
*/
virtual Event dequeueInternal() {
- _currEvent = _internalQueue.dequeue(false);
+ _currEvent = _internalQueue.dequeue(0);
if (_currEvent)
_dataModel.setEvent(_currEvent);
return _currEvent;