From d76130b944740e79df6dbfdef97eadbe0373b25f Mon Sep 17 00:00:00 2001 From: sdottaka Date: Sun, 21 Apr 2013 21:53:30 +0900 Subject: [PATCH] Cppcheck: Common realloc mistake: 'ptr' nulled but not freed upon failure --- Src/Common/unicoder.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Common/unicoder.cpp b/Src/Common/unicoder.cpp index 5f2147f89..eb5649477 100644 --- a/Src/Common/unicoder.cpp +++ b/Src/Common/unicoder.cpp @@ -818,7 +818,10 @@ void buffer::resize(size_t newSize) if (capacity < newSize) { capacity = newSize; - ptr = (unsigned char *)realloc(ptr, capacity); + unsigned char *tmp = static_cast(realloc(ptr, capacity)); + if (!tmp) + throw std::bad_alloc(); + ptr = tmp; } } -- 2.11.0