mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-15 09:24:49 +00:00
Increase buffer construction requirements (#88)
* Fix crash in Buffer with null pointer and non-zero length * Throw inside Buffer constructor instead
This commit is contained in:
committed by
Matias Fontanini
parent
9a20b588c5
commit
b8f4be5e1b
@@ -35,6 +35,7 @@
|
|||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
namespace cppkafka {
|
namespace cppkafka {
|
||||||
|
|
||||||
@@ -75,6 +76,9 @@ public:
|
|||||||
Buffer(const T* data, size_t size)
|
Buffer(const T* data, size_t size)
|
||||||
: data_(reinterpret_cast<const DataType*>(data)), size_(size) {
|
: data_(reinterpret_cast<const DataType*>(data)), size_(size) {
|
||||||
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
|
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
|
||||||
|
if ((data_ == nullptr) && (size_ > 0)) {
|
||||||
|
throw Exception("Invalid buffer configuration");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ TEST_CASE("conversions", "[buffer]") {
|
|||||||
const Buffer buffer(data);
|
const Buffer buffer(data);
|
||||||
const Buffer empty_buffer;
|
const Buffer empty_buffer;
|
||||||
|
|
||||||
|
SECTION("construction") {
|
||||||
|
CHECK_THROWS_AS(Buffer((const char*)nullptr, 5), Exception);
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("bool conversion") {
|
SECTION("bool conversion") {
|
||||||
CHECK(!!buffer == true);
|
CHECK(!!buffer == true);
|
||||||
|
|||||||
Reference in New Issue
Block a user