-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Consider the code:
Poco::Buffer<char> buffer(200);
assert(buffer.empty());
This fails the assertion - because Buffer::Buffer(std::size_t capacity) at include/Poco/Buffer.h:41 sets _used to the passed capacity. Any following append would increase the buffer size; and any read from begin() to end() would give leading garbage.
The same happens in the Buffer::Buffer(T* pMem, std::size_t length) telling "Supplied pointer is considered blank".
Additionally, calling buffer.assign(nullptr, 0) would not reset _used to 0 (but likely should) - it would be just a noop. buffer.resize(0), however, would do that luckily; that's a workaround for now calling it after creation - but not a workaround for the case of Buffer::Buffer(T* pMem, std::size_t length), where buffer doesn't own the buffer, and would throw. So following code would always throw:
char buf[200];
Poco::Buffer<char> buffer(buf, 200);
buffer.append("abcde", 5);