From af16c8193a0455e19b6dac47192d90c3077217c6 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 22 Sep 2017 21:12:26 -0400 Subject: It's easier to use calloc here Assumption is calloc checks for overflow (!) so if it returns a pointer that means no overflow occurred. --- src/lib/compression/compress_utils.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/compression/compress_utils.cpp b/src/lib/compression/compress_utils.cpp index 6edc22292..f4b41fd5b 100644 --- a/src/lib/compression/compress_utils.cpp +++ b/src/lib/compression/compress_utils.cpp @@ -13,13 +13,8 @@ namespace Botan { void* Compression_Alloc_Info::do_malloc(size_t n, size_t size) { - const size_t total_size = n * size; - - BOTAN_ASSERT_EQUAL(total_size / size, n, "Overflow check"); - // TODO maximum length check here? - - void* ptr = std::malloc(total_size); + void* ptr = std::calloc(n, size); /* * Return null rather than throwing here as we are being called by a @@ -31,8 +26,7 @@ void* Compression_Alloc_Info::do_malloc(size_t n, size_t size) if(ptr) { - std::memset(ptr, 0, total_size); - m_current_allocs[ptr] = total_size; + m_current_allocs[ptr] = n * size; } return ptr; -- cgit v1.2.3