diff options
author | Matthias Braun <matze@braunis.de> | 2017-07-20 01:30:39 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2017-07-20 01:30:39 +0000 |
commit | c20b3383b78473fdfb958ebfe15227bded79ba78 (patch) | |
tree | fce0056e354337b5855270a434d6dee9b777b3cf /llvm/lib/IR/DataLayout.cpp | |
parent | 36a1c17dffa6f2f2bddf9d7974849e9ecee42916 (diff) | |
download | bcm5719-llvm-c20b3383b78473fdfb958ebfe15227bded79ba78.tar.gz bcm5719-llvm-c20b3383b78473fdfb958ebfe15227bded79ba78.zip |
Support, IR, ADT: Check nullptr after allocation with malloc/realloc or calloc
As a follow up of the bad alloc handler patch, this patch introduces nullptr checks on pointers returned from the
malloc/realloc/calloc functions. In addition some memory size assignments are moved behind the allocation
of the corresponding memory to fulfill exception safe memory management (RAII).
patch by Klaus Kretzschmar
Differential Revision: https://reviews.llvm.org/D35414
llvm-svn: 308576
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 5de281a9523..f4dddeb30d0 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -572,6 +572,8 @@ const StructLayout *DataLayout::getStructLayout(StructType *Ty) const { int NumElts = Ty->getNumElements(); StructLayout *L = (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t)); + if (L == nullptr) + report_bad_alloc_error("Allocation of StructLayout elements failed."); // Set SL before calling StructLayout's ctor. The ctor could cause other // entries to be added to TheMap, invalidating our reference. |