MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

Unreliable lookup method used within LBLEEventDispatcher class #89

Closed sfyang closed 6 years ago

sfyang commented 6 years ago

In the LBLEEventDispatcher class defined in LBLE.h and implemented in LBLE.cpp, the EventTable type is a std::multimap container, and the implementation of both the dispatch() and the removeObserver() methods uses std::multimap::find() method to lookup the iterator to the first element in the m_table list.

However, according to the C++ standard, the std::multimap::find() method does NOT guarantee to return the iterator of the first element for elements of the same key in the list, so the outcome of the these two methods could be STL-implementation-dependent.

A possible workaround could be replacing the std::multimap::find() method calls with std::multimap::lower_bound(), which returns an iterator pointing to the first element that is not less than the specified key.

pablosun commented 6 years ago

Thanks for report this! We will investigate further into this issue.

pablosun commented 6 years ago

Will use equal_range instead when searching for elements with matching keys.