如果大小超标,并且下一块有效,那么这是非法操作
This commit is contained in:
parent
b0b844ec14
commit
7704197ae6
|
@ -78,8 +78,12 @@ bool ConfigBlock::Write(Storage* storage, uint addr, const ByteArray& bs)
|
|||
{
|
||||
assert_ptr(storage);
|
||||
|
||||
// 如果大小超标,那么需要下一块无效,否则会出现配置覆盖
|
||||
if(bs.Length() <= Size || Next()->Valid() == false) return false;
|
||||
// 如果大小超标,并且下一块有效,那么这是非法操作
|
||||
if(bs.Length() > Size && Next()->Valid())
|
||||
{
|
||||
debug_printf("ConfigBlock::Write 配置块 %s 大小 %d 小于要写入的数据库大小 %d,并且下一块是有效配置块,不能覆盖! \r\n", Name, Size, bs.Length());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rs = true;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ bool BlockStorage::Read(uint address, ByteArray& bs)
|
|||
|
||||
bool BlockStorage::Write(uint address, const ByteArray& bs)
|
||||
{
|
||||
assert_param2(address & 0x01 == 0x00, "Write起始地址必须是2字节对齐");
|
||||
assert_param2((address & 0x01) == 0x00, "Write起始地址必须是2字节对齐");
|
||||
|
||||
byte* buf = bs.GetBuffer();
|
||||
uint len = bs.Length();
|
||||
|
@ -136,7 +136,7 @@ bool BlockStorage::Write(uint address, const ByteArray& bs)
|
|||
|
||||
bool BlockStorage::Memset(uint address, byte data, uint len)
|
||||
{
|
||||
assert_param2(address & 0x01 == 0x00, "Memset起始地址必须是2字节对齐");
|
||||
assert_param2((address & 0x01) == 0x00, "Memset起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
@ -151,7 +151,7 @@ bool BlockStorage::Memset(uint address, byte data, uint len)
|
|||
// 擦除块。起始地址,字节数量默认0表示擦除全部
|
||||
bool BlockStorage::Erase(uint address, uint len)
|
||||
{
|
||||
assert_param2(address & 0x01 == 0x00, "Erase起始地址必须是2字节对齐");
|
||||
assert_param2((address & 0x01) == 0x00, "Erase起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
@ -186,7 +186,7 @@ bool BlockStorage::Erase(uint address, uint len)
|
|||
/* 指定块是否被擦除 */
|
||||
bool BlockStorage::IsErased(uint address, uint len)
|
||||
{
|
||||
assert_param2(address & 0x01 == 0x00, "IsErased起始地址必须是2字节对齐");
|
||||
assert_param2((address & 0x01) == 0x00, "IsErased起始地址必须是2字节对齐");
|
||||
|
||||
if(address < Start || address + len > Start + Size) return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue