From 258125449270af8124fb9b05a303eb2e6d63e907 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Wed, 8 Sep 2021 17:36:57 +0100 Subject: [PATCH] SFDP: Fix sector map table allocation check When passing an allocation size directly to `std::make_unique`, `std::nothrow` is unavailable, so any failed allocation results in an exception which we cannot catch because Mbed OS is compiled with `-fno-exceptions`. To fix this, chain `std::make_unique` with `new (std::nothrow)`, and the allocated `unique_ptr` retains the `nullptr` property. --- storage/blockdevice/source/SFDP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/blockdevice/source/SFDP.cpp b/storage/blockdevice/source/SFDP.cpp index 3b5ac248f9..5f28738695 100644 --- a/storage/blockdevice/source/SFDP.cpp +++ b/storage/blockdevice/source/SFDP.cpp @@ -256,7 +256,7 @@ int sfdp_parse_sector_map_table(Callback sfdp * - regions in each configuration * is variable -> the size of this table is variable */ - auto smptbl_buff = std::make_unique(sfdp_info.smptbl.size); + auto smptbl_buff = std::unique_ptr(new (std::nothrow) uint8_t[sfdp_info.smptbl.size]); if (!smptbl_buff) { tr_error("Failed to allocate memory"); return -1;