Skip to content

Commit a79e260

Browse files
author
Seppo Takalo
committed
SlicingBlockDevice should assert, if size does not look valid
1 parent 83c41e7 commit a79e260

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

features/storage/blockdevice/FlashSimBlockDevice.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <algorithm>
2222
#include <stdlib.h>
2323
#include <string.h>
24+
#include "mbed_assert.h"
2425

2526
namespace mbed {
2627

@@ -30,6 +31,7 @@ FlashSimBlockDevice::FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value) :
3031
_erase_value(erase_value), _blank_buf_size(0),
3132
_blank_buf(0), _bd(bd), _init_ref_count(0), _is_initialized(false)
3233
{
34+
MBED_ASSERT(bd);
3335
}
3436

3537
FlashSimBlockDevice::~FlashSimBlockDevice()

features/storage/blockdevice/SlicingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr
2727
, _start_from_end(false), _start(start)
2828
, _stop_from_end(false), _stop(stop)
2929
{
30+
MBED_ASSERT(bd);
31+
// SlicingBlockDevice(bd, 0,0) would use the full block, which does not make sense, it must be a programming eror.
32+
// SlicingBlockDevice(bd, 100,100) would have no size, which is also a programming error.
33+
MBED_ASSERT(start != stop);
34+
3035
if ((int64_t)_start < 0) {
3136
_start_from_end = true;
3237
_start = -_start;

0 commit comments

Comments
 (0)