From 52525730a163c56f82a43584faa8acb8fd45e1da Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Wed, 21 Feb 2018 02:02:39 +0000 Subject: Clean up use of C allocation functions If the value returned by `malloc`, `calloc` or `realloc` is not checked for null pointer, this change replaces them for `safe_malloc`, `safe_calloc` or `safe_realloc`, which are defined in the namespace `llvm`. These function report fatal error on out of memory. In the plain C files, assertion statements are added to ensure that memory is successfully allocated. The aim of this change is to get better diagnostics of OOM on Windows. Differential Revision: https://reviews.llvm.org/D43017 llvm-svn: 325661 --- clang/lib/Frontend/CacheTokens.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'clang/lib/Frontend/CacheTokens.cpp') diff --git a/clang/lib/Frontend/CacheTokens.cpp b/clang/lib/Frontend/CacheTokens.cpp index 72e8f68dc05..851ea25e9b1 100644 --- a/clang/lib/Frontend/CacheTokens.cpp +++ b/clang/lib/Frontend/CacheTokens.cpp @@ -662,7 +662,8 @@ std::pair PTHWriter::EmitIdentifierTable() { // (2) a map from (IdentifierInfo*, Offset)* -> persistent IDs // Note that we use 'calloc', so all the bytes are 0. - PTHIdKey *IIDMap = (PTHIdKey*)calloc(idcount, sizeof(PTHIdKey)); + PTHIdKey *IIDMap = static_cast( + llvm::safe_calloc(idcount, sizeof(PTHIdKey))); // Create the hashtable. llvm::OnDiskChainedHashTableGenerator IIOffMap; -- cgit v1.2.3