Check for nullptr return from malloc, calloc, and realloc. (#1023)

These are used in ntcore and cscore.  Add inline null-checking versions
to wpi/memory.h and use them throughout.
This commit is contained in:
Peter Johnson
2018-05-04 17:55:46 -07:00
committed by GitHub
parent e8d5759d95
commit 7a34f5d17d
9 changed files with 148 additions and 68 deletions

View File

@@ -9,6 +9,7 @@
#include <wpi/STLExtras.h>
#include <wpi/TCPConnector.h>
#include <wpi/memory.h>
#include <wpi/timestamp.h>
#include "Handle.h"
@@ -574,7 +575,8 @@ void CS_SetHttpCameraUrls(CS_Source source, const char** urls, int count,
char** CS_GetHttpCameraUrls(CS_Source source, int* count, CS_Status* status) {
auto urls = cs::GetHttpCameraUrls(source, status);
char** out = static_cast<char**>(std::malloc(urls.size() * sizeof(char*)));
char** out =
static_cast<char**>(wpi::CheckedMalloc(urls.size() * sizeof(char*)));
*count = urls.size();
for (size_t i = 0; i < urls.size(); ++i) out[i] = cs::ConvertToC(urls[i]);
return out;