]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_cdsa_utilities/lib/cssmalloc.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_utilities / lib / cssmalloc.cpp
index b2a476722c384a0006d0e59d32a5e346233ffd66..a7bb291ca68f41cda3c9b6c1e3f9964b6078fbca 100644 (file)
@@ -30,6 +30,7 @@
 #include <security_cdsa_utilities/cssmalloc.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <os/overflow.h>
 
 
 
@@ -39,13 +40,13 @@ namespace Security {
 //
 // CssmMemoryFunctionsAllocators
 //
-void *CssmMemoryFunctionsAllocator::malloc(size_t size) throw(std::bad_alloc)
+void *CssmMemoryFunctionsAllocator::malloc(size_t size)
 { return functions.malloc(size); }
 
-void CssmMemoryFunctionsAllocator::free(void *addr) throw()
+void CssmMemoryFunctionsAllocator::free(void *addr) _NOEXCEPT
 { return functions.free(addr); }
 
-void *CssmMemoryFunctionsAllocator::realloc(void *addr, size_t size) throw(std::bad_alloc)
+void *CssmMemoryFunctionsAllocator::realloc(void *addr, size_t size)
 { return functions.realloc(addr, size); }
 
 
@@ -61,20 +62,24 @@ CssmAllocatorMemoryFunctions::CssmAllocatorMemoryFunctions(Allocator &alloc)
        calloc_func = relayCalloc;
 }
 
-void *CssmAllocatorMemoryFunctions::relayMalloc(size_t size, void *ref) throw(std::bad_alloc)
+void *CssmAllocatorMemoryFunctions::relayMalloc(size_t size, void *ref)
 { return allocator(ref).malloc(size); }
 
-void CssmAllocatorMemoryFunctions::relayFree(void *mem, void *ref) throw()
+void CssmAllocatorMemoryFunctions::relayFree(void *mem, void *ref) _NOEXCEPT
 { allocator(ref).free(mem); }
 
-void *CssmAllocatorMemoryFunctions::relayRealloc(void *mem, size_t size, void *ref) throw(std::bad_alloc)
+void *CssmAllocatorMemoryFunctions::relayRealloc(void *mem, size_t size, void *ref)
 { return allocator(ref).realloc(mem, size); }
 
-void *CssmAllocatorMemoryFunctions::relayCalloc(uint32 count, size_t size, void *ref) throw(std::bad_alloc)
+void *CssmAllocatorMemoryFunctions::relayCalloc(uint32 count, size_t size, void *ref)
 {
        // Allocator doesn't have a calloc() method
-       void *mem = allocator(ref).malloc(size * count);
-       memset(mem, 0, size * count);
+       size_t alloc_size = 0;
+       if (os_mul_overflow(count, size, &alloc_size)) {
+               return NULL;
+       }
+       void *mem = allocator(ref).malloc(alloc_size);
+       memset(mem, 0, alloc_size);
        return mem;
 }