From b338db70ee7bae633e2341469906d187ca59f958 Mon Sep 17 00:00:00 2001 From: Ferry Huberts Date: Sun, 4 Feb 2024 21:24:35 +0100 Subject: [PATCH] Fix a potential crash, indicated by a compiler warning (#894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At this point in the code it == m_statCollectors.end() and therefore it->first has no meaning and can not be used. Building CXX object lib/oatpp/src/CMakeFiles/oatpp.dir/oatpp/web/protocol/CommunicationError.cpp.o In file included from /usr/include/c++/13/bits/shared_ptr.h:53, from /usr/include/c++/13/memory:80, from oatpp/src/oatpp/core/base/Countable.hpp:28, from oatpp/src/oatpp/core/data/mapping/type/./Type.hpp:28, from oatpp/src/oatpp/core/data/mapping/type/Object.hpp:28, from oatpp/src/oatpp/core/Types.hpp:28, from oatpp/src/oatpp/network/monitor/StatCollector.hpp:28, from oatpp/src/oatpp/network/monitor/MetricsChecker.hpp:28, from oatpp/src/oatpp/network/monitor/ConnectionMonitor.hpp:28, from oatpp/src/oatpp/network/monitor/ConnectionMonitor.cpp:25: In member function ‘std::__shared_ptr<_Tp, _Lp>::element_type* std::__shared_ptr<_Tp, _Lp>::get() const [with _Tp = std::__cxx11::basic_string; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’, inlined from ‘std::__shared_ptr_access<_Tp, _Lp, , >::element_type* std::__shared_ptr_access<_Tp, _Lp, , >::_M_get() const [with _Tp = std::__cxx11::basic_string; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic; bool = false; bool = false]’ at /usr/include/c++/13/bits/shared_ptr_base.h:1363:69, inlined from ‘std::__shared_ptr_access<_Tp, _Lp, , >::element_type* std::__shared_ptr_access<_Tp, _Lp, , >::operator->() const [with _Tp = std::__cxx11::basic_string; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic; bool = false; bool = false]’ at /usr/include/c++/13/bits/shared_ptr_base.h:1357:15, inlined from ‘T* oatpp::data::mapping::type::ObjectWrapper::operator->() const [with T = std::__cxx11::basic_string; Clazz = oatpp::data::mapping::type::__class::String]’ at oatpp/src/oatpp/core/data/mapping/type/./Type.hpp:223:28, inlined from ‘void oatpp::network::monitor::ConnectionMonitor::Monitor::freeConnectionStats(oatpp::network::monitor::ConnectionStats&)’ at oatpp/src/oatpp/network/monitor/ConnectionMonitor.cpp:189:7: /usr/include/c++/13/bits/shared_ptr_base.h:1666:16: warning: array subscript 0 is outside array bounds of ‘std::aligned_storage<40, 8>::type [0]’ [-Warray-bounds=] 1666 | { return _M_ptr; } | ^~~~~~ In member function ‘void oatpp::network::monitor::ConnectionMonitor::Monitor::freeConnectionStats(oatpp::network::monitor::ConnectionStats&)’: cc1plus: note: source object is likely at address zero Signed-off-by: Ferry Huberts --- src/oatpp/network/monitor/ConnectionMonitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oatpp/network/monitor/ConnectionMonitor.cpp b/src/oatpp/network/monitor/ConnectionMonitor.cpp index 6201e7ea..fd8b1f6b 100644 --- a/src/oatpp/network/monitor/ConnectionMonitor.cpp +++ b/src/oatpp/network/monitor/ConnectionMonitor.cpp @@ -187,7 +187,7 @@ void ConnectionMonitor::Monitor::freeConnectionStats(ConnectionStats& stats) { it->second->deleteMetricData(metric.second); } else { OATPP_LOGE("[oatpp::network::ConnectionMonitor::Monitor::freeConnectionStats]", - "Error. Can't free Metric data. Unknown Metric: name - '%s'", it->first->c_str()) + "Error. Can't free Metric data. Unknown Metric: name - '%s'", metric.first->c_str()) } }