配置区名称使用0结尾字符串,也就是最大智能7个字符

This commit is contained in:
nnhy 2016-03-17 06:14:58 +00:00
parent 0794facec5
commit fcfe40aa09
3 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ struct ConfigBlock
{
ushort Hash;
ushort Size;
char Name[8];
char Name[8]; // 零结尾字符串
ushort GetHash() const;
bool Valid() const;
@ -76,11 +76,10 @@ uint ConfigBlock::CopyTo(Buffer& bs) const
bool ConfigBlock::Init(const String& name, const Buffer& bs)
{
if(!name) return false;
if(name.Length() >= sizeof(Name)) return false;
TS("ConfigBlock::Init");
if(name.Length() > sizeof(Name)) return false;
// 配置块的大小,只有第一次能够修改,以后即使废弃也不能修改,仅仅清空名称
if(bs.Length() > 0)
{
@ -165,14 +164,13 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const String& name)
TS("Config::Find");
if(!name) return nullptr;
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
if(!CheckSignature(st, addr, false)) return nullptr;
// 第一个配置块
auto cfg = (const ConfigBlock*)addr;
if(name.Length() > sizeof(cfg->Name)) return nullptr;
// 遍历链表,找到同名块
while(cfg->Valid())
{
@ -252,6 +250,8 @@ const void* Config::Set(const String& name, const Buffer& bs) const
if(!name) return nullptr;
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
auto cfg = FindBlock(Device, Address, name);
if(!cfg) cfg = NewBlock(Device, Address, bs.Length());
if(!cfg) return nullptr;

View File

@ -5,7 +5,7 @@ TinyConfig* TinyConfig::Current = nullptr;
TinyConfig::TinyConfig() : ConfigBase()
{
_Name = "TinyConf";
_Name = "TinyCfg";
_Start = &Length;
_End = &TagEnd;

View File

@ -11,7 +11,7 @@ TokenConfig::TokenConfig() : ConfigBase(),
Server(_Server, ArrayLength(_Server)),
Vendor(_Vendor, ArrayLength(_Vendor))
{
_Name = "TokenCfg";
_Name = "TokenCf";
_Start = &Length;
_End = &TagEnd;
Init();