取消Array构造函数里面的默认参数,挖出来一堆隐式转换的BUG

This commit is contained in:
nnhy 2015-11-13 14:13:33 +00:00
parent 900bc5549c
commit 5bb431c6e6
8 changed files with 16 additions and 16 deletions

View File

@ -24,7 +24,7 @@ struct ConfigBlock
ushort ConfigBlock::GetHash() const
{
// 计算头部 CRC。从数据CRC开始包括大小和名称
return Crc::Hash16(&Size, sizeof(*this) - offsetof(ConfigBlock, Size));
return Crc::Hash16(Array(&Size, sizeof(*this) - offsetof(ConfigBlock, Size)));
}
bool ConfigBlock::Valid() const

View File

@ -23,5 +23,5 @@ void MessageBase::WriteMessage(Message& msg)
Write(ms);
//msg.Length = ms.Position();
msg.SetData(ms.GetBuffer(), ms.Position());
msg.SetData(Array(ms.GetBuffer(), ms.Position()));
}

View File

@ -77,7 +77,7 @@ bool TinyMessage::Read(Stream& ms)
f->TTL = 0;
f->Retry = 0;
// 连续的可以直接计算Crc16
Crc = Crc::Hash16(p, HeaderSize + Length);
Crc = Crc::Hash16(Array(p, HeaderSize + Length));
// 还原数据
p[3] = fs;
return true;
@ -108,7 +108,7 @@ void TinyMessage::Write(Stream& ms) const
f->TTL = 0;
f->Retry = 0;
p->Checksum = p->Crc = Crc::Hash16(buf, HeaderSize + Length);
p->Checksum = p->Crc = Crc::Hash16(Array(buf, HeaderSize + Length));
// 还原数据
buf[3] = fs;
@ -125,7 +125,7 @@ void TinyMessage::ComputeCrc()
Write(ms);
// 扣除不计算校验码的部分
Checksum = Crc = Crc::Hash16(ms.GetBuffer(), HeaderSize + Length);
Checksum = Crc = Crc::Hash16(Array(ms.GetBuffer(), HeaderSize + Length));
}
// 验证消息校验码是否有效
@ -421,11 +421,11 @@ void TinyController::AckResponse(const TinyMessage& msg)
msg_printf(" 失败!\r\n");
}
uint TinyController::Post(byte dest, byte code, byte* buf, uint len)
uint TinyController::Post(byte dest, byte code, const Array& arr)
{
TinyMessage msg(code);
msg.Dest = dest;
msg.SetData(buf, len);
msg.SetData(arr);
return Send(msg);
}

View File

@ -148,7 +148,7 @@ public:
virtual bool Send(Message& msg);
// 发送消息,传输口参数为空时向所有传输口发送消息
uint Post(byte dest, byte code, byte* buf = NULL, uint len = 0);
uint Post(byte dest, byte code, const Array& arr);
// 把消息放入发送队列usTimeout微秒超时时间内如果对方没有响应会重复发送
bool Post(TinyMessage& msg, int usTimeout = -1);
// 回复对方的请求消息

View File

@ -335,7 +335,7 @@ bool TinyServer::OnPing(const TinyMessage& msg)
ms.ReadByte();
ushort crc = ms.ReadUInt16();
ushort crc1 = Crc::Hash16(dv->HardID.GetBuffer(), 12);
ushort crc1 = Crc::Hash16(dv->HardID);
if(crc ==crc1) ver = 2;
else
@ -367,7 +367,7 @@ bool TinyServer::OnPing(const TinyMessage& msg)
Stream ms(msg.Data, msg.Length);
ms.ReadByte();
ushort crc = ms.ReadUInt16();
ushort crc1 = Crc::Hash16(dv->HardID.GetBuffer(), 12);
ushort crc1 = Crc::Hash16(dv->HardID);
if(crc !=crc1)
{

View File

@ -206,11 +206,11 @@ void TokenController::Close()
}
// 发送消息,传输口参数为空时向所有传输口发送消息
bool TokenController::Send(byte code, byte* buf, uint len)
bool TokenController::Send(byte code, const Array& arr)
{
TokenMessage msg;
msg.Code = code;
msg.SetData(buf, len);
msg.SetData(arr);
return Send(msg);
}
@ -292,7 +292,7 @@ bool TokenController::OnReceive(Message& msg)
// 如果有等待响应,则交给它
if(msg.Reply && _Response && (msg.Code == _Response->Code || msg.Code == 0x08 && msg.Data[0] == _Response->Code))
{
_Response->SetData(msg.Data, msg.Length);
_Response->SetData(Array(msg.Data, msg.Length));
_Response->Reply = true;
// 加解密。握手不加密,登录响应不加密

View File

@ -76,7 +76,7 @@ public:
// 发送消息,传输口参数为空时向所有传输口发送消息
virtual bool Send(Message& msg);
// 发送消息,传输口参数为空时向所有传输口发送消息
virtual bool Send(byte code, byte* buf = NULL, uint len = 0);
virtual bool Send(byte code, const Array& arr);
// 响应消息
private:

4
Type.h
View File

@ -102,8 +102,8 @@ public:
// 缓冲区。按字节指针返回
byte* GetBuffer() const;
Array(void* data, int len = 0);
Array(const void* data, int len = 0);
Array(void* data, int len);
Array(const void* data, int len);
// 重载等号运算符,使用另一个固定数组来初始化
Array& operator=(const Array& arr);
virtual ~Array();