From bcaf37dcfa27d0620ab1602491768621cb094a1b Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 27 Nov 2019 15:54:09 +0200 Subject: [PATCH] SlicingBlockDevice should assert, if size does not look valid --- features/storage/blockdevice/FlashSimBlockDevice.cpp | 2 ++ features/storage/blockdevice/SlicingBlockDevice.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/features/storage/blockdevice/FlashSimBlockDevice.cpp b/features/storage/blockdevice/FlashSimBlockDevice.cpp index 61591309ed..9a2f901407 100644 --- a/features/storage/blockdevice/FlashSimBlockDevice.cpp +++ b/features/storage/blockdevice/FlashSimBlockDevice.cpp @@ -20,6 +20,7 @@ #include #include #include +#include "mbed_assert.h" namespace mbed { @@ -34,6 +35,7 @@ FlashSimBlockDevice::FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value) : _erase_value(erase_value), _blank_buf_size(0), _blank_buf(0), _bd(bd), _init_ref_count(0), _is_initialized(false) { + MBED_ASSERT(bd); } FlashSimBlockDevice::~FlashSimBlockDevice() diff --git a/features/storage/blockdevice/SlicingBlockDevice.cpp b/features/storage/blockdevice/SlicingBlockDevice.cpp index f204ce5653..994224e524 100644 --- a/features/storage/blockdevice/SlicingBlockDevice.cpp +++ b/features/storage/blockdevice/SlicingBlockDevice.cpp @@ -27,6 +27,11 @@ SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr , _start_from_end(false), _start(start) , _stop_from_end(false), _stop(stop) { + MBED_ASSERT(bd); + // SlicingBlockDevice(bd, 0,0) would use the full block, which does not make sense, it must be a programming eror. + // SlicingBlockDevice(bd, 100,100) would have no size, which is also a programming error. + MBED_ASSERT(start != stop); + if ((int64_t)_start < 0) { _start_from_end = true; _start = -_start;