From bb84b7ddeb10ed5957f746cf28da606aea4eaa46 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 17 Oct 2020 01:56:06 +0200 Subject: direct_bt::DBTManager, ieee11073::DataTypes: Fix Warnings --- src/direct_bt/DBTManager.cpp | 9 +++++++-- src/ieee11073/DataTypes.cpp | 8 +++++--- test/ieee11073/test_datatypes01.cpp | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 454e6f6f..0778457e 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -612,8 +612,13 @@ ScanType DBTManager::startDiscovery(const int dev_id, const ScanType scanType) n ScanType type = ScanType::NONE; if( nullptr != res && res->getOpcode() == MgmtEvent::Opcode::CMD_COMPLETE ) { const MgmtEvtCmdComplete &res1 = *static_cast(res.get()); - if( MgmtStatus::SUCCESS == res1.getStatus() && 1 == res1.getDataSize() ) { - type = static_cast( *res1.getData() ); + if( MgmtStatus::SUCCESS == res1.getStatus() && 1 <= res1.getDataSize() ) { + const uint8_t *p = res1.getData(); + if( nullptr == p ) { // G++ 10: -Werror=null-dereference + ERR_PRINT("DBTManager::startDiscovery: Impossible MgmtEvtCmdComplete data nullptr: %s - %s", res1.toString().c_str(), req.toString().c_str()); + return type; + } + type = static_cast( p[0] ); } } return type; diff --git a/src/ieee11073/DataTypes.cpp b/src/ieee11073/DataTypes.cpp index 97c53ab5..0cb47265 100644 --- a/src/ieee11073/DataTypes.cpp +++ b/src/ieee11073/DataTypes.cpp @@ -59,9 +59,11 @@ AbsoluteTime::AbsoluteTime(const uint8_t * data_le, const int size) { std::string AbsoluteTime::toString() const { char cbuf[24]; // '2020-04-04 10:58:59' 19 + second_fractions - snprintf(cbuf, sizeof(cbuf), "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", - (int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second); - + const size_t count = snprintf(cbuf, sizeof(cbuf), "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", + (int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second); + if( count >= sizeof(cbuf) ) { // truncated? + throw jau::InternalError("snprintf date-format truncated "+std::to_string(count)+" >= "+std::to_string(sizeof(cbuf)), E_FILE_LINE); + } std::string res(cbuf); if( 0 != second_fractions ) { res += "."+std::to_string(second_fractions); diff --git a/test/ieee11073/test_datatypes01.cpp b/test/ieee11073/test_datatypes01.cpp index 12e0bd3d..10f03027 100644 --- a/test/ieee11073/test_datatypes01.cpp +++ b/test/ieee11073/test_datatypes01.cpp @@ -57,6 +57,8 @@ class Cppunit_tests : public Cppunit { }; int main(int argc, char *argv[]) { + (void) argc; + (void) argv; Cppunit_tests test1; return test1.run(); } -- cgit v1.2.3