core: Scheduler::cancelEvent allows empty EventId

refs #1176

Change-Id: I80f10ed8026d64b46b4634ced9278f145f54c4a7
diff --git a/daemon/core/scheduler.cpp b/daemon/core/scheduler.cpp
index f9f9996..c72e279 100644
--- a/daemon/core/scheduler.cpp
+++ b/daemon/core/scheduler.cpp
@@ -109,8 +109,8 @@
 void
 Scheduler::cancelEvent(const EventId& eventId)
 {
-  if (!eventId->isValid())
-    return; // event already fired or cancelled
+  if (!static_cast<bool>(eventId) || !eventId->isValid())
+    return; // event empty, already fired, or cancelled
   
   if (static_cast<EventQueue::iterator>(*eventId) != m_scheduledEvent) {
     m_events.erase(*eventId);
diff --git a/tests/core/scheduler.cpp b/tests/core/scheduler.cpp
index 04a9671..593744b 100644
--- a/tests/core/scheduler.cpp
+++ b/tests/core/scheduler.cpp
@@ -80,6 +80,15 @@
   BOOST_CHECK_EQUAL(count4, 4);
 }
 
+BOOST_AUTO_TEST_CASE(CancelEmptyEvent)
+{
+  boost::asio::io_service io; 
+  Scheduler scheduler(io);
+  
+  EventId i;
+  scheduler.cancelEvent(i);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace nfd