mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 13:02:13 +01:00
cpp: sbuffer: check initial buffer size != 0
This commit is contained in:
parent
1be1927a1f
commit
e8abcc1765
@ -38,7 +38,7 @@ test -f ChangeLog || touch ChangeLog
|
|||||||
test -f NEWS || touch NEWS
|
test -f NEWS || touch NEWS
|
||||||
test -f README || cp -f README.md README
|
test -f README || cp -f README.md README
|
||||||
|
|
||||||
if ! ./preprocess; then
|
if test ! ./preprocess; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -28,9 +28,13 @@ class sbuffer : public msgpack_sbuffer {
|
|||||||
public:
|
public:
|
||||||
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE)
|
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE)
|
||||||
{
|
{
|
||||||
base::data = (char*)::malloc(initsz);
|
if(initsz == 0) {
|
||||||
if(!base::data) {
|
base::data = NULL;
|
||||||
throw std::bad_alloc();
|
} else {
|
||||||
|
base::data = (char*)::malloc(initsz);
|
||||||
|
if(!base::data) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base::size = 0;
|
base::size = 0;
|
||||||
@ -80,7 +84,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void expand_buffer(size_t len)
|
void expand_buffer(size_t len)
|
||||||
{
|
{
|
||||||
size_t nsize = (base::alloc) ?
|
size_t nsize = (base::alloc > 0) ?
|
||||||
base::alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
base::alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
||||||
|
|
||||||
while(nsize < base::size + len) { nsize *= 2; }
|
while(nsize < base::size + len) { nsize *= 2; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user