*unsaved_files
= (struct CXUnsavedFile *)malloc(sizeof(struct CXUnsavedFile) *
*num_unsaved_files);
+ assert(*unsaved_files);
for (i = 0; i != *num_unsaved_files; ++i) {
struct CXUnsavedFile *unsaved = *unsaved_files + i;
const char *arg_string = argv[arg_indices[i]] + prefix_len;
/* Read the contents of the file we're remapping to. */
contents = (char *)malloc(unsaved->Length + 1);
+ assert(contents);
if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) {
fprintf(stderr, "error: unexpected %s reading 'to' file %s\n",
(feof(to_file) ? "EOF" : "error"), sep + 1);
/* Copy the file name that we're remapping from. */
filename_len = sep - arg_string;
filename = (char *)malloc(filename_len + 1);
+ assert(filename);
memcpy(filename, arg_string, filename_len);
filename[filename_len] = 0;
unsaved->Filename = filename;
= (struct CXUnsavedFile *)realloc(unsaved_files_no_try_idx,
sizeof(struct CXUnsavedFile) *
*num_unsaved_files);
+ assert(*unsaved_files);
memcpy(*unsaved_files + num_unsaved_files_no_try_idx,
unsaved_files_try_idx, sizeof(struct CXUnsavedFile) *
num_unsaved_files_try_idx);
/* Copy the file name. */
*filename = (char*)malloc(last_colon - input + 1);
+ assert(*filename);
memcpy(*filename, input, last_colon - input);
(*filename)[last_colon - input] = 0;
return 0;
assert(NumLocations > 0 && "Unable to count locations?");
Locations = (CursorSourceLocation *)malloc(
NumLocations * sizeof(CursorSourceLocation));
+ assert(Locations);
for (Loc = 0; Loc < NumLocations; ++Loc) {
const char *input = argv[Loc + 1] + strlen(locations_flag);
if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
assert(NumLocations > 0 && "Unable to count locations?");
Locations = (CursorSourceLocation *)malloc(
NumLocations * sizeof(CursorSourceLocation));
+ assert(Locations);
for (Loc = 0; Loc < NumLocations; ++Loc) {
const char *input = argv[Loc + 1] + strlen("-file-refs-at=");
if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
/* Parse the locations. */
assert(NumFilenames > 0 && "Unable to count filenames?");
Filenames = (const char **)malloc(NumFilenames * sizeof(const char *));
+ assert(Filenames);
for (I = 0; I < NumFilenames; ++I) {
const char *input = argv[I + 1] + strlen("-file-includes-in=");
/* Copy the file name. */
static ImportedASTFilesData *importedASTs_create() {
ImportedASTFilesData *p;
p = malloc(sizeof(ImportedASTFilesData));
+ assert(p);
p->filenames = malloc(MAX_IMPORTED_ASTFILES * sizeof(const char *));
+ assert(p->filenames);
p->num_files = 0;
return p;
}
node =
(IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
digitCount(line) + digitCount(column) + 2);
+ assert(node);
newStr = node->data;
sprintf(newStr, "%s:%d:%d", name, line, column);
len = strlen(database);
tmp = (char *) malloc(len+1);
+ assert(tmp);
memcpy(tmp, database, len+1);
buildDir = dirname(tmp);
}
cursors = (CXCursor *)malloc(num_tokens * sizeof(CXCursor));
+ assert(cursors);
clang_annotateTokens(TU, tokens, num_tokens, cursors);
if (checkForErrors(TU) != 0) {
len = strlen(database);
tmp = (char *) malloc(len+1);
+ assert(tmp);
memcpy(tmp, database, len+1);
buildDir = dirname(tmp);
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Chrono.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
unwrap(VFO)->write(OS);
StringRef Data = OS.str();
- *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_ptr = static_cast<char*>(llvm::safe_malloc(Data.size()));
*out_buffer_size = Data.size();
memcpy(*out_buffer_ptr, Data.data(), Data.size());
return CXError_Success;
OS << "}\n";
StringRef Data = OS.str();
- *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_ptr = static_cast<char*>(llvm::safe_malloc(Data.size()));
*out_buffer_size = Data.size();
memcpy(*out_buffer_ptr, Data.data(), Data.size());
return CXError_Success;