diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2018-02-21 02:02:39 +0000 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2018-02-21 02:02:39 +0000 |
commit | 52525730a163c56f82a43584faa8acb8fd45e1da (patch) | |
tree | bd0bbd8442cdba5a7fd40b2555bfa0a7ac1e02ff /clang/lib/Frontend/Rewrite/HTMLPrint.cpp | |
parent | 56492f9177e57b383d54366f93d77595ee80fd78 (diff) | |
download | llvm-52525730a163c56f82a43584faa8acb8fd45e1da.zip llvm-52525730a163c56f82a43584faa8acb8fd45e1da.tar.gz llvm-52525730a163c56f82a43584faa8acb8fd45e1da.tar.bz2 |
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
Diffstat (limited to 'clang/lib/Frontend/Rewrite/HTMLPrint.cpp')
-rw-r--r-- | clang/lib/Frontend/Rewrite/HTMLPrint.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp index 11e431d..34ee967 100644 --- a/clang/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/clang/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -86,8 +86,7 @@ void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) { // Emit the HTML. const RewriteBuffer &RewriteBuf = R.getEditBuffer(FID); - char *Buffer = (char*)malloc(RewriteBuf.size()); - std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer); - Out->write(Buffer, RewriteBuf.size()); - free(Buffer); + std::unique_ptr<char[]> Buffer(new char[RewriteBuf.size()]); + std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer.get()); + Out->write(Buffer.get(), RewriteBuf.size()); } |