File tree 2 files changed +7
-2
lines changed
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change 35
35
#include < iosfwd>
36
36
#include < algorithm>
37
37
#include " macros.h"
38
+ #include " exceptions.h"
38
39
39
40
namespace cppkafka {
40
41
@@ -86,6 +87,10 @@ class CPPKAFKA_API Buffer {
86
87
Buffer (const std::vector<T>& data)
87
88
: data_(data.data()), size_(data.size()) {
88
89
static_assert (sizeof (T) == sizeof (DataType), " sizeof(T) != sizeof(DataType)" );
90
+ if (((data_ == nullptr ) && (size_ > 0 )) ||
91
+ ((data_ != nullptr ) && (size_ == 0 ))) {
92
+ throw Exception (" Invalid buffer configuration" );
93
+ }
89
94
}
90
95
91
96
// Don't allow construction from temporary vectors
Original file line number Diff line number Diff line change @@ -67,11 +67,11 @@ Buffer::const_iterator Buffer::end() const {
67
67
}
68
68
69
69
Buffer::operator bool () const {
70
- return (data_ != nullptr ) && ( size_ != 0 ) ;
70
+ return size_ != 0 ;
71
71
}
72
72
73
73
Buffer::operator string () const {
74
- return ( bool )(* this ) ? string (data_, data_ + size_) : string ( );
74
+ return string (data_, data_ + size_);
75
75
}
76
76
77
77
ostream& operator <<(ostream& output, const Buffer& rhs) {
You can’t perform that action at this time.
0 commit comments