Skip to content

Commit bcaf37d

Browse files
author
Seppo Takalo
committed
SlicingBlockDevice should assert, if size does not look valid
1 parent 92a60c3 commit bcaf37d

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
@@ -20,6 +20,7 @@
2020
#include <algorithm>
2121
#include <stdlib.h>
2222
#include <string.h>
23+
#include "mbed_assert.h"
2324

2425
namespace mbed {
2526

@@ -34,6 +35,7 @@ FlashSimBlockDevice::FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value) :
3435
_erase_value(erase_value), _blank_buf_size(0),
3536
_blank_buf(0), _bd(bd), _init_ref_count(0), _is_initialized(false)
3637
{
38+
MBED_ASSERT(bd);
3739
}
3840

3941
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)