SlicingBlockDevice should assert, if size does not look valid

pull/11986/head
Seppo Takalo 2019-11-27 15:54:09 +02:00
parent 92a60c3d80
commit bcaf37dcfa
2 changed files with 7 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#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()

View File

@ -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;