严格要求代码,排除编译警告

This commit is contained in:
Stone 2016-06-18 08:12:52 +00:00
parent cb18316376
commit 44e5b22e26
18 changed files with 145 additions and 59 deletions

View File

@ -235,7 +235,7 @@ const void* Config::New(int size) const
// 实在没办法,最后划分一个新的区块。这里判断一下空间是否足够 // 实在没办法,最后划分一个新的区块。这里判断一下空间是否足够
if(Size && (uint)cfg + sizeof(ConfigBlock) + size > Address + Size) if(Size && (uint)cfg + sizeof(ConfigBlock) + size > Address + Size)
{ {
debug_printf("Config::New 0x%08X + %d + %d 配置区0x%08X, %d空间不足\r\n", cfg, sizeof(ConfigBlock), size, Address, Size); debug_printf("Config::New 0x%p + %d + %d 配置区0x%p, %d空间不足\r\n", cfg, sizeof(ConfigBlock), size, (byte*)Address, Size);
return nullptr; return nullptr;
} }
@ -293,7 +293,7 @@ bool Config::RemoveAll() const
}*/ }*/
#if CFG_DEBUG #if CFG_DEBUG
debug_printf("Config::RemoveAll (0x%08X, %d) \r\n", Address, Size); debug_printf("Config::RemoveAll (0x%p, %d) \r\n", (byte*)Address, Size);
#endif #endif
ByteArray bs((byte)0xFF, Size); ByteArray bs((byte)0xFF, Size);
@ -438,7 +438,7 @@ void ConfigBase::Save() const
auto pt = Cfg.Set(_Name, bs); auto pt = Cfg.Set(_Name, bs);
if(pt) if(pt)
debug_printf("成功 0x%08X \r\n", pt); debug_printf("成功 0x%p \r\n", pt);
else else
debug_printf("失败\r\n"); debug_printf("失败\r\n");
} }

View File

@ -119,7 +119,7 @@ int Buffer::Copy(int destIndex, const void* src, int len)
// 不指定长度,又没有剩余量,无法拷贝 // 不指定长度,又没有剩余量,无法拷贝
if(remain <= 0) if(remain <= 0)
{ {
debug_printf("Buffer::Copy (0x%08X, %d) <= (%d, 0x%08X, %d) \r\n", _Arr, _Length, destIndex, src, len); debug_printf("Buffer::Copy (0x%p, %d) <= (%d, 0x%p, %d) \r\n", _Arr, _Length, destIndex, src, len);
assert(false, "Buffer::Copy 未指明要拷贝的长度"); assert(false, "Buffer::Copy 未指明要拷贝的长度");
return 0; return 0;
@ -133,7 +133,7 @@ int Buffer::Copy(int destIndex, const void* src, int len)
// 子类可能在这里扩容 // 子类可能在这里扩容
if(!SetLength(destIndex + len)) if(!SetLength(destIndex + len))
{ {
debug_printf("Buffer::Copy (0x%08X, %d) <= (%d, 0x%08X, %d) \r\n", _Arr, _Length, destIndex, src, len); debug_printf("Buffer::Copy (0x%p, %d) <= (%d, 0x%p, %d) \r\n", _Arr, _Length, destIndex, src, len);
assert(false, "Buffer::Copy 缓冲区太小"); assert(false, "Buffer::Copy 缓冲区太小");
len = remain; len = remain;

View File

@ -39,7 +39,11 @@ void Queue::Clear()
} }
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
void Queue::Push(byte dat) void Queue::Push(byte dat)
@ -79,8 +83,13 @@ byte Queue::Pop()
return dat; return dat;
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
uint Queue::Write(const Buffer& bs) uint Queue::Write(const Buffer& bs)
{ {
/* /*

View File

@ -56,7 +56,7 @@ bool Stream::CheckRemain(uint count)
if(count > remain) if(count > remain)
{ {
if(CanResize) if(CanResize)
debug_printf("数据流 0x%08X 剩余容量 (%d - %d) = %d 不足 %d ,无法扩容!\r\n", this, _Capacity, _Position, remain, count); debug_printf("数据流 0x%p 剩余容量 (%d - %d) = %d 不足 %d ,无法扩容!\r\n", this, _Capacity, _Position, remain, count);
else else
assert(false, "无法扩容"); assert(false, "无法扩容");

View File

@ -38,7 +38,7 @@ void Power::Standby(uint msTime)
auto pwr = (Power*)_powers[i]; auto pwr = (Power*)_powers[i];
if(pwr) if(pwr)
{ {
debug_printf("Power::LowPower 0x%08X\r\n", pwr); debug_printf("Power::LowPower 0x%p\r\n", pwr);
pwr->ChangePower(msTime); pwr->ChangePower(msTime);
} }
} }
@ -52,7 +52,7 @@ void Power::Standby(uint msTime)
// 各模块向系统注册低功耗句柄,供系统进入低功耗前调用 // 各模块向系统注册低功耗句柄,供系统进入低功耗前调用
void Power::AddPower(Power* power) void Power::AddPower(Power* power)
{ {
debug_printf("Power::AddPower 0x%08X\r\n", power); debug_printf("Power::AddPower 0x%p\r\n", power);
_powers.Add(power); _powers.Add(power);
} }

View File

@ -753,7 +753,7 @@ bool Enc28j60::OnWrite(const Buffer& bs)
WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS); WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS);
// 等待发送完成 // 等待发送完成
times = 1000; times = 1000;
while((ReadReg(ECON1) & ECON1_TXRTS) && --times > 0); while(((ReadReg(ECON1) & ECON1_TXRTS) && --times) > 0) { }
/* /*
/ ECON1.TXRTS 7 ETXND + 1 / ECON1.TXRTS 7 ETXND + 1

View File

@ -271,7 +271,7 @@ String Esp8266::Send(const String& cmd, cstring expect, cstring expect2, uint ms
#if NET_DEBUG #if NET_DEBUG
// 只有AT指令显示日志 // 只有AT指令显示日志
if(!cmd.StartsWith("AT") || expect && expect[0] == '>') EnableLog = false; if(!cmd.StartsWith("AT") || (expect && expect[0] == '>')) EnableLog = false;
if(EnableLog) if(EnableLog)
{ {
we.Command = &cmd; we.Command = &cmd;

View File

@ -652,7 +652,7 @@ void W5500::Register(byte Index, HardSocket* handler)
{ {
if(Index >= 8) return; if(Index >= 8) return;
net_printf("W5500::Register %d 0x%08X\r\n", Index, handler); net_printf("W5500::Register %d 0x%p\r\n", Index, handler);
_sockets[Index] = handler; _sockets[Index] = handler;
} }
@ -1126,8 +1126,8 @@ bool HardSocket::OnOpen()
while(!tw.Expired()) while(!tw.Expired())
{ {
sr = ReadStatus(); sr = ReadStatus();
if(Protocol == ProtocolType::Tcp && sr == SOCK_INIT if((Protocol == ProtocolType::Tcp && sr == SOCK_INIT)
|| Protocol == ProtocolType::Udp && sr == SOCK_UDP) || (Protocol == ProtocolType::Udp && sr == SOCK_UDP))
{ {
rs = true; rs = true;
break; break;

View File

@ -40,7 +40,11 @@ bool TInterrupt::Deactivate(short irq)
} }
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
void TInterrupt::Process(uint num) const void TInterrupt::Process(uint num) const
@ -80,7 +84,13 @@ SmartIRQ::~SmartIRQ()
TInterrupt::GlobalEnable(); TInterrupt::GlobalEnable();
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
/*================================ 锁 ================================*/ /*================================ 锁 ================================*/

View File

@ -26,7 +26,11 @@ extern uint __microlib_freelist_initialised;
#endif #endif
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
TSys::TSys() TSys::TSys()
@ -49,7 +53,13 @@ TSys::TSys()
Started = false; Started = false;
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
void ShowTime(void* param) void ShowTime(void* param)
{ {
@ -112,8 +122,12 @@ void TSys::RemoveTask(uint& taskid) const
taskid = 0; taskid = 0;
} }
#if !defined(TINY) && defined(STM32F0) && defined(DEBUG) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
@ -262,7 +276,13 @@ void TSys::Delay(uint us) const
} }
#endif #endif
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
/****************系统跟踪****************/ /****************系统跟踪****************/

View File

@ -35,7 +35,11 @@ Task::~Task()
} }
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
bool Task::Execute(UInt64 now) bool Task::Execute(UInt64 now)
@ -116,7 +120,13 @@ bool Task::CheckTime(UInt64 end, bool isSleep)
return Event || Times > 0; return Event || Times > 0;
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
// 显示状态 // 显示状态
void Task::ShowStatus() void Task::ShowStatus()
@ -137,7 +147,11 @@ void Task::ShowStatus()
} }
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
// 全局任务调度器 // 全局任务调度器
@ -158,7 +172,13 @@ Task& Task::Current()
return *(Scheduler()->Current); return *(Scheduler()->Current);
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
TaskScheduler::TaskScheduler(cstring name) TaskScheduler::TaskScheduler(cstring name)
{ {
@ -216,7 +236,7 @@ uint TaskScheduler::Add(Action func, void* param, int dueTime, int period, cstri
Count++; Count++;
#if DEBUG #if DEBUG
debug_printf("%s::添加%d %s First=%dms Period=%dms 0x%08x\r\n", Name, task->ID, name, dueTime, period, func); debug_printf("%s::添加%d %s First=%dms Period=%dms 0x%p\r\n", Name, task->ID, name, dueTime, period, func);
#endif #endif
return task->ID; return task->ID;
@ -231,7 +251,7 @@ void TaskScheduler::Remove(uint taskid)
auto task = (Task*)_Tasks[i]; auto task = (Task*)_Tasks[i];
if(task->ID == taskid) if(task->ID == taskid)
{ {
debug_printf("%s::删除%d %s 0x%08x\r\n", Name, task->ID, task->Name, task->Callback); debug_printf("%s::删除%d %s 0x%p\r\n", Name, task->ID, task->Name, task->Callback);
// 清零ID实现重用 // 清零ID实现重用
task->ID = 0; task->ID = 0;
@ -328,7 +348,13 @@ void TaskScheduler::Execute(uint msMax, bool& cancel)
} }
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
// 显示状态 // 显示状态
void TaskScheduler::ShowStatus() void TaskScheduler::ShowStatus()
@ -358,7 +384,11 @@ void TaskScheduler::ShowStatus()
} }
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
Task* TaskScheduler::operator[](int taskid) Task* TaskScheduler::operator[](int taskid)
@ -372,4 +402,10 @@ Task* TaskScheduler::operator[](int taskid)
return nullptr; return nullptr;
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif

View File

@ -39,7 +39,7 @@ Thread::Thread(Action callback, void* state, uint stackSize)
ID = ++g_ID; ID = ++g_ID;
if(g_ID >= 0xFFFF) g_ID = 0; if(g_ID >= 0xFFFF) g_ID = 0;
debug_printf("Thread::Create %d 0x%08x StackSize=0x%04x", ID, callback, stackSize); debug_printf("Thread::Create %d 0x%p StackSize=0x%04x", ID, callback, stackSize);
Name = nullptr; Name = nullptr;
@ -54,7 +54,7 @@ Thread::Thread(Action callback, void* state, uint stackSize)
uint* p = new uint[stackSize]; uint* p = new uint[stackSize];
Stack = p; Stack = p;
StackTop = Stack + stackSize; StackTop = Stack + stackSize;
debug_printf(" Stack=(0x%08x, 0x%08x)", Stack, StackTop); debug_printf(" Stack=(0x%p, 0x%p)", Stack, StackTop);
debug_printf("\r\n"); debug_printf("\r\n");
// 默认状态就绪 // 默认状态就绪

View File

@ -51,10 +51,12 @@ void TTime::SetTime(UInt64 seconds)
if(OnSave) OnSave(); if(OnSave) OnSave();
} }
#pragma arm section code
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
void TTime::Sleep(uint ms, bool* running) const void TTime::Sleep(uint ms, bool* running) const
@ -76,7 +78,7 @@ void TTime::Sleep(uint ms, bool* running) const
} }
} }
// 睡眠时间太短 // 睡眠时间太短
if(!ms || running != nullptr && !*running) return; if(!ms || (running && !*running)) return;
uint me = Current() + ms; uint me = Current() + ms;
@ -119,7 +121,13 @@ void TTime::Delay(uint us) const
} }
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
/************************************************ TimeWheel ************************************************/ /************************************************ TimeWheel ************************************************/

View File

@ -17,7 +17,11 @@
#if DEBUG #if DEBUG
#if !defined(TINY) && defined(STM32F0) #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys" #pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif #endif
#if MEM_DEBUG #if MEM_DEBUG
@ -37,7 +41,7 @@ void free_(void* p)
{ {
byte* bs = (byte*)p; byte* bs = (byte*)p;
bs -= 4; bs -= 4;
if(!(bs[0] == 'S' && bs[1] == 'M')) mem_printf("p=0x%08x bs[0]=%c bs[1]=%c\r\n", p, bs[0], bs[1]); if(!(bs[0] == 'S' && bs[1] == 'M')) mem_printf("p=0x%p bs[0]=%c bs[1]=%c\r\n", p, bs[0], bs[1]);
assert(bs[0] == 'S' && bs[1] == 'M', "正在释放不是本系统申请的内存!"); assert(bs[0] == 'S' && bs[1] == 'M', "正在释放不是本系统申请的内存!");
free(bs); free(bs);
@ -67,7 +71,7 @@ void* operator new(uint size)
mem_printf("malloc failed! size=%d ", size); mem_printf("malloc failed! size=%d ", size);
else else
{ {
mem_printf("0x%08x ", p); mem_printf("0x%p ", p);
// 如果堆只剩下64字节则报告失败要求用户扩大堆空间以免不测 // 如果堆只剩下64字节则报告失败要求用户扩大堆空间以免不测
//uint end = (uint)&__heap_limit; //uint end = (uint)&__heap_limit;
//uint end = __get_PSP(); //uint end = __get_PSP();
@ -97,7 +101,7 @@ void* operator new[](uint size)
mem_printf("malloc failed! size=%d ", size); mem_printf("malloc failed! size=%d ", size);
else else
{ {
mem_printf("0x%08x ", p); mem_printf("0x%p ", p);
// 如果堆只剩下64字节则报告失败要求用户扩大堆空间以免不测 // 如果堆只剩下64字节则报告失败要求用户扩大堆空间以免不测
//uint end = (uint)&__heap_limit; //uint end = (uint)&__heap_limit;
//uint end = __get_PSP(); //uint end = __get_PSP();
@ -108,11 +112,11 @@ void* operator new[](uint size)
return p; return p;
} }
void operator delete(void* p) void operator delete(void* p) noexcept
{ {
assert_ptr(p); assert_ptr(p);
mem_printf(" delete 0x%08x ", p); mem_printf(" delete 0x%p ", p);
if(p) if(p)
{ {
SmartIRQ irq; SmartIRQ irq;
@ -120,11 +124,11 @@ void operator delete(void* p)
} }
} }
void operator delete[](void* p) void operator delete[](void* p) noexcept
{ {
assert_ptr(p); assert_ptr(p);
mem_printf(" delete[] 0x%08x ", p); mem_printf(" delete[] 0x%p ", p);
if(p) if(p)
{ {
SmartIRQ irq; SmartIRQ irq;
@ -132,7 +136,13 @@ void operator delete[](void* p)
} }
} }
#pragma arm section code #if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT

View File

@ -177,14 +177,7 @@ typedef struct _TCP_HEADER
void Init(bool recursion = false) void Init(bool recursion = false)
{ {
#if (defined (__GNUC__)) Length = sizeof(this[0]) >> 2;
#pragma GCC diagnostic ignored "-Woverflow"
#endif
Length = (byte)sizeof(this[0]);
//Length = (byte)0x14;
#if (defined (__GNUC__))
#pragma GCC diagnostic warning "-Woverflow"
#endif
reserved_1 = 0; reserved_1 = 0;
reserved_2 = 0; reserved_2 = 0;

View File

@ -64,7 +64,7 @@ IPAddress IPAddress::Parse(const String& ipstr)
// 标准地址第一个不能是0唯一的Any例外已经在前面处理 // 标准地址第一个不能是0唯一的Any例外已经在前面处理
int v = item.ToInt(); int v = item.ToInt();
if(v < 0 || v > 255 || i == 0 && v == 0) break; if(v < 0 || v > 255 || (i == 0 && v == 0)) break;
ip[i] = (byte)v; ip[i] = (byte)v;

View File

@ -278,7 +278,7 @@ bool TinyServer::OnJoin(const TinyMessage& msg)
// 从1开始派ID // 从1开始派ID
id = 1; id = 1;
while(DevMgmt.FindDev(++id) != nullptr && id < 0xFF); while(DevMgmt.FindDev(++id) != nullptr && id < 0xFF) { }
debug_printf("发现节点设备 0x%04X ,为其分配 0x%02X\r\n", dm.Kind, id); debug_printf("发现节点设备 0x%04X ,为其分配 0x%02X\r\n", dm.Kind, id);
if(id == 0xFF) return false; if(id == 0xFF) return false;

View File

@ -63,7 +63,7 @@ void TokenMessage::Write(Stream& ms) const
assert_ptr(this); assert_ptr(this);
byte tmp = Code | (Reply << 7); byte tmp = Code | (Reply << 7);
if(!Reply && OneWay || Reply && Error) tmp |= (1 << 6); if((!Reply && OneWay) || (Reply && Error)) tmp |= (1 << 6);
ms.Write(tmp); ms.Write(tmp);
ms.Write(Seq); ms.Write(Seq);
ms.WriteArray(Buffer(Data, Length)); ms.WriteArray(Buffer(Data, Length));