From e8abcc1765da98885d03cb0ca0784cf332bf0ee0 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sun, 26 Sep 2010 11:36:57 +0900 Subject: [PATCH] cpp: sbuffer: check initial buffer size != 0 --- cpp/bootstrap | 2 +- cpp/src/msgpack/sbuffer.hpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cpp/bootstrap b/cpp/bootstrap index a95c3044..7f3a182a 100755 --- a/cpp/bootstrap +++ b/cpp/bootstrap @@ -38,7 +38,7 @@ test -f ChangeLog || touch ChangeLog test -f NEWS || touch NEWS test -f README || cp -f README.md README -if ! ./preprocess; then +if test ! ./preprocess; then exit 1 fi diff --git a/cpp/src/msgpack/sbuffer.hpp b/cpp/src/msgpack/sbuffer.hpp index a9efc6db..14c5d2a2 100644 --- a/cpp/src/msgpack/sbuffer.hpp +++ b/cpp/src/msgpack/sbuffer.hpp @@ -28,9 +28,13 @@ class sbuffer : public msgpack_sbuffer { public: sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE) { - base::data = (char*)::malloc(initsz); - if(!base::data) { - throw std::bad_alloc(); + if(initsz == 0) { + base::data = NULL; + } else { + base::data = (char*)::malloc(initsz); + if(!base::data) { + throw std::bad_alloc(); + } } base::size = 0; @@ -80,7 +84,7 @@ public: private: void expand_buffer(size_t len) { - size_t nsize = (base::alloc) ? + size_t nsize = (base::alloc > 0) ? base::alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE; while(nsize < base::size + len) { nsize *= 2; }