Fix svace/coverity issues 14/290814/3
authorDariusz Michaluk <d.michaluk@samsung.com>
Mon, 3 Apr 2023 13:01:12 +0000 (15:01 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 3 Apr 2023 17:10:19 +0000 (19:10 +0200)
Change-Id: I61f1c4f3302e741ac1b07aa826a2e8988cb80d9b

tests/api_test.cpp
tests/shared_test.cpp

index 0941fb50d16364af9055dcbf07ba293cd6b7f8c3..3650a7fc42dc93a8d527b7190fd9ca143cc8d3ca 100644 (file)
@@ -80,7 +80,7 @@ class OverrideSmackLabel {
 public:
     explicit OverrideSmackLabel(const char *override_label)
     : fd(open("/proc/thread-self/attr/current", O_RDWR)) {
-        const auto ret = read(fd, old_label, sizeof old_label + 1);
+        const auto ret = read(fd, old_label, sizeof old_label);
         BOOST_REQUIRE_GT(ret, 0);
         BOOST_REQUIRE_LE(ret, sizeof old_label);
         old_label_len = ret;
@@ -123,7 +123,10 @@ std::pair<unsigned char*, size_t> makeMessage(const char* platform,
     const size_t platformSize = strlen(platform) + 1;
     const size_t pkgIdSize = strlen(pkgId) + 1;
     const size_t size = platformSize + pkgIdSize + N;
+
     unsigned char* message = static_cast<unsigned char*>(malloc(size));
+    BOOST_REQUIRE(message != nullptr);
+
     memcpy(message, platform, platformSize);
     memcpy(message + platformSize, pkgId, pkgIdSize);
     memcpy(message + platformSize + pkgIdSize, payload, N);
index 3803042da8dfdfc15407b23b4ef28131f57f48b2..c10cca1a503de30dbd77f9881b484dcbb5563047 100644 (file)
@@ -95,7 +95,8 @@ NEGATIVE_TEST_CASE(invalid_length_message_test) {
     BOOST_REQUIRE(error_code == expected);
 
     protobuf_sync_message_deserialization sync_deserializer(receiver);
-    sender.write_some(boost::asio::buffer(invalid_size), error_code);
+    auto written = sender.write_some(boost::asio::buffer(invalid_size), error_code);
+    BOOST_REQUIRE(written);
     BOOST_REQUIRE(!error_code);
 
     BOOST_REQUIRE_THROW(sync_deserializer.decodeMessage(received_msg), std::length_error);