Skip to content

Commit 2581254

Browse files
committed
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.
1 parent 7a8ff5f commit 2581254

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

storage/blockdevice/source/SFDP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp
256256
* - regions in each configuration
257257
* is variable -> the size of this table is variable
258258
*/
259-
auto smptbl_buff = std::make_unique<uint8_t[]>(sfdp_info.smptbl.size);
259+
auto smptbl_buff = std::unique_ptr<uint8_t[]>(new (std::nothrow) uint8_t[sfdp_info.smptbl.size]);
260260
if (!smptbl_buff) {
261261
tr_error("Failed to allocate memory");
262262
return -1;

0 commit comments

Comments
 (0)