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:
Alex Damian
2018-06-18 12:09:48 -04:00
committed by Matias Fontanini
parent 9a20b588c5
commit b8f4be5e1b
2 changed files with 7 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
#include <iosfwd>
#include <algorithm>
#include "macros.h"
#include "exceptions.h"
namespace cppkafka {
@@ -75,6 +76,9 @@ public:
Buffer(const T* data, size_t size)
: data_(reinterpret_cast<const DataType*>(data)), size_(size) {
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
if ((data_ == nullptr) && (size_ > 0)) {
throw Exception("Invalid buffer configuration");
}
}
/**