1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

codership/wsrep-lib#117 Fixed empty vector access.

Access to empty vector by using operator[] may cause stdlib++
assertions to fail. Replaced the vector data access to use data()
method which is valid operation even if the vector is empty.

Added unit test to reproduce assertion with empty mutable_buffer access.

Added -D_GLIBCXX_ASSERTIONS preprocessor option to debug builds
to catch standard library misuse.

Added gcc 8 and gcc9 into travis build matrix.
This commit is contained in:
Teemu Ollakka
2019-12-05 13:29:42 +02:00
parent c9513bd2e4
commit 9b25cebdf1
6 changed files with 111 additions and 3 deletions

View File

@ -85,8 +85,26 @@ namespace wsrep
}
size_t size() const { return buffer_.size(); }
char* data() { return &buffer_[0]; }
const char* data() const { return &buffer_[0]; }
/**
* Return pointer to underlying data array. The returned pointer
* may or may not be null in case of empty buffer, it is up to
* user to check the size of the array before dereferencing the
* pointer.
*
* @return Pointer to underlying data array.
*/
char* data() { return buffer_.data(); }
/**
* Return const pointer to underlying data array. The returned pointer
* may or may not be null in case of empty buffer, it is up to
* user to check the size of the array before dereferencing the
* pointer.
*
* @return Const pointer to underlying data array.
*/
const char* data() const { return buffer_.data(); }
mutable_buffer& operator= (const mutable_buffer& other)
{