aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-17 01:56:06 +0200
committerSven Gothel <[email protected]>2020-10-17 01:56:06 +0200
commitbb84b7ddeb10ed5957f746cf28da606aea4eaa46 (patch)
tree80c4318843e8fba4a4a7b23b4f70c69594b635fb
parent2b848e814f624d306980e7cfa9a133541bdf5cb2 (diff)
direct_bt::DBTManager, ieee11073::DataTypes: Fix Warnings
-rw-r--r--src/direct_bt/DBTManager.cpp9
-rw-r--r--src/ieee11073/DataTypes.cpp8
-rw-r--r--test/ieee11073/test_datatypes01.cpp2
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<const MgmtEvtCmdComplete *>(res.get());
- if( MgmtStatus::SUCCESS == res1.getStatus() && 1 == res1.getDataSize() ) {
- type = static_cast<ScanType>( *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<ScanType>( 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();
}