修正一个字节对齐的BUG,各个Config尽量用4字节对齐,特别是含有字符串String的类
MDK编译String::copy的时候,使用了 LDR R0, R1, [R5, 0x04]指令,而这个指令要求4字节对齐。
This commit is contained in:
parent
6c7aff547b
commit
86c6535448
6
Config.h
6
Config.h
|
@ -75,9 +75,9 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
||||||
#pragma pack(push) // 保存对齐状态
|
//#pragma pack(push) // 保存对齐状态
|
||||||
// 强制结构体紧凑分配空间
|
// 强制结构体紧凑分配空间
|
||||||
#pragma pack(1)
|
//#pragma pack(1)
|
||||||
|
|
||||||
/******************************** HotConfig ********************************/
|
/******************************** HotConfig ********************************/
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop) // 恢复对齐状态
|
//#pragma pack(pop) // 恢复对齐状态
|
||||||
|
|
||||||
/*
|
/*
|
||||||
配置子系统,链式保存管理多配置段。
|
配置子系统,链式保存管理多配置段。
|
||||||
|
|
|
@ -146,13 +146,13 @@ bool String::CheckCapacity(uint size)
|
||||||
if (_Arr && _Capacity >= size) return true;
|
if (_Arr && _Capacity >= size) return true;
|
||||||
|
|
||||||
// 外部需要放下size个字符,那么需要size+1个字节空间
|
// 外部需要放下size个字符,那么需要size+1个字节空间
|
||||||
int sz = _Capacity;
|
int sz = 0x40;
|
||||||
while(sz <= size) sz <<= 1;
|
while(sz <= size) sz <<= 1;
|
||||||
|
|
||||||
auto p = new char[sz];
|
auto p = new char[sz];
|
||||||
if(!p) return false;
|
if(!p) return false;
|
||||||
|
|
||||||
if(_Length)
|
if(_Arr && _Length)
|
||||||
//strcpy(p, _Arr);
|
//strcpy(p, _Arr);
|
||||||
// 为了安全,按照字节拷贝
|
// 为了安全,按照字节拷贝
|
||||||
Buffer(p, sz).Copy(0, _Arr, _Length);
|
Buffer(p, sz).Copy(0, _Arr, _Length);
|
||||||
|
@ -162,7 +162,7 @@ bool String::CheckCapacity(uint size)
|
||||||
if(_needFree && _Arr != Arr) delete _Arr;
|
if(_needFree && _Arr != Arr) delete _Arr;
|
||||||
|
|
||||||
_Arr = p;
|
_Arr = p;
|
||||||
_Capacity = sz;
|
_Capacity = sz - 1;
|
||||||
_needFree = true;
|
_needFree = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -259,7 +259,7 @@ bool String::Concat(const char* cstr, uint length)
|
||||||
if (!cstr) return false;
|
if (!cstr) return false;
|
||||||
if (length == 0) return true;
|
if (length == 0) return true;
|
||||||
if (!CheckCapacity(newlen)) return false;
|
if (!CheckCapacity(newlen)) return false;
|
||||||
|
|
||||||
//strcpy(_Arr + _Length, cstr);
|
//strcpy(_Arr + _Length, cstr);
|
||||||
Buffer(_Arr, _Capacity).Copy(_Length, cstr, length);
|
Buffer(_Arr, _Capacity).Copy(_Length, cstr, length);
|
||||||
_Length = newlen;
|
_Length = newlen;
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
||||||
#pragma pack(push) // 保存对齐状态
|
//#pragma pack(push) // 保存对齐状态
|
||||||
// 强制结构体紧凑分配空间
|
// 强制结构体紧凑分配空间
|
||||||
#pragma pack(1)
|
//#pragma pack(1)
|
||||||
|
|
||||||
// 配置信息
|
// 配置信息
|
||||||
class TinyConfig : public ConfigBase
|
class TinyConfig : public ConfigBase
|
||||||
|
@ -45,6 +45,6 @@ private:
|
||||||
byte TagEnd; // 数据区结束标识符
|
byte TagEnd; // 数据区结束标识符
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop) // 恢复对齐状态
|
//#pragma pack(pop) // 恢复对齐状态
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,35 +57,21 @@ TokenConfig* TokenConfig::Create(const char* vendor, byte protocol, ushort sport
|
||||||
{
|
{
|
||||||
TokenConfig::Current = &tc;
|
TokenConfig::Current = &tc;
|
||||||
tc.Init();
|
tc.Init();
|
||||||
|
|
||||||
//strcpy(tc.Vendor, vendor);
|
|
||||||
tc.Load();
|
tc.Load();
|
||||||
bool rs = tc.New;
|
|
||||||
|
|
||||||
if(tc.Vendor.Length() == 0)
|
bool rs = tc.New;
|
||||||
|
if(!tc.Vendor)
|
||||||
{
|
{
|
||||||
/*// len 表示字符串真实长度,不包括结束零
|
|
||||||
auto len = strlen(vendor);
|
|
||||||
if(len > ArrayLength(tc.Vendor)) len = ArrayLength(tc.Vendor) - 1;
|
|
||||||
strncpy(tc.Vendor, vendor, len);
|
|
||||||
tc.Vendor[len] = '\0';*/
|
|
||||||
tc.Vendor = vendor;
|
tc.Vendor = vendor;
|
||||||
|
|
||||||
rs = false;
|
rs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tc.Server.Length() == 0)
|
if(!tc.Server)
|
||||||
{
|
{
|
||||||
/*// len 表示字符串真实长度,不包括结束零
|
|
||||||
auto len = strlen(tc.Vendor);
|
|
||||||
if(len > ArrayLength(tc.Server)) len = ArrayLength(tc.Server) - 1;
|
|
||||||
strncpy(tc.Server, tc.Vendor, ArrayLength(tc.Server));
|
|
||||||
tc.Server[len] = '\0';*/
|
|
||||||
tc.Server = tc.Vendor;
|
tc.Server = tc.Vendor;
|
||||||
|
|
||||||
//tc.ServerIP = svr.Value;
|
|
||||||
tc.ServerPort = sport;
|
tc.ServerPort = sport;
|
||||||
tc.Port = port;
|
tc.Port = port;
|
||||||
|
|
||||||
rs = false;
|
rs = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include "Net\Net.h"
|
#include "Net\Net.h"
|
||||||
|
|
||||||
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
||||||
#pragma pack(push) // 保存对齐状态
|
//#pragma pack(push) // 保存对齐状态
|
||||||
// 强制结构体紧凑分配空间
|
// 强制结构体紧凑分配空间
|
||||||
#pragma pack(1)
|
//#pragma pack(1)
|
||||||
|
|
||||||
// 配置信息
|
// 配置信息
|
||||||
class TokenConfig : public ConfigBase
|
class TokenConfig : public ConfigBase
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
char _VisitToken[16]; //访问服务器令牌
|
char _VisitToken[16]; //访问服务器令牌
|
||||||
char _Server[32]; // 服务器域名。出厂为空,从厂商服务器覆盖,恢复出厂设置时清空
|
char _Server[32]; // 服务器域名。出厂为空,从厂商服务器覆盖,恢复出厂设置时清空
|
||||||
char _Vendor[32]; // 厂商服务器域名。原始厂商服务器地址
|
char _Vendor[32]; // 厂商服务器域名。原始厂商服务器地址
|
||||||
|
|
||||||
byte TagEnd; // 数据区结束标识符
|
byte TagEnd; // 数据区结束标识符
|
||||||
|
|
||||||
TokenConfig();
|
TokenConfig();
|
||||||
|
@ -42,13 +42,13 @@ public:
|
||||||
String VisitToken;
|
String VisitToken;
|
||||||
String Server;
|
String Server;
|
||||||
String Vendor;
|
String Vendor;
|
||||||
|
|
||||||
static TokenConfig* Current;
|
static TokenConfig* Current;
|
||||||
static TokenConfig* Create(const char* vendor, byte protocol, ushort sport, ushort port);
|
static TokenConfig* Create(const char* vendor, byte protocol, ushort sport, ushort port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop) // 恢复对齐状态
|
//#pragma pack(pop) // 恢复对齐状态
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue