OSDN Git Service

Cppcheck: Common realloc mistake: 'ptr' nulled but not freed upon failure
authorsdottaka <none@none>
Sun, 21 Apr 2013 12:53:30 +0000 (21:53 +0900)
committersdottaka <none@none>
Sun, 21 Apr 2013 12:53:30 +0000 (21:53 +0900)
Src/Common/unicoder.cpp

index 5f2147f..eb56494 100644 (file)
@@ -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<unsigned char *>(realloc(ptr, capacity));
+               if (!tmp)
+                       throw std::bad_alloc();
+               ptr = tmp;
        }
 }