While compiling loads of C sources, I noticed some inappropriate warnings which I isolated into small examples for easy reproduction.
All examples are compiled with "pocc.exe /O2 /W2 source.c".
I marked the warned line with // <--.
Example 1:
#include <string.h>
char * buf;
void Function(char * result)
{
memcpy(result, buf, 4); // <--
}
// POCCWarn1.c(5): warning #2118: Parameter 'result' is not referenced.
Intrinsic functions don't reference parameters.
Example 2:
extern void WriteByte(void * pDst, unsigned char cVal);
void Function(int iKey, unsigned int uiCount, void * pSrc, void * pDst)
{
switch(iKey) {
case 0:
while (1) {
WriteByte(pDst, *(unsigned char *) pSrc);
if (--uiCount == 0) break;
pSrc = ((unsigned char *) pSrc) + 1;
pDst = ((unsigned char *) pDst) + 1;
}
break; // <--
default:
WriteByte(pDst, 4u);
break;
}
}
// POCCWarn2.c(13): warning #2209: Unreachable code removed.
Ok, there's that while(1) endless loop, but there's a break inside the loop so the outer break _is_ reached!
Example 3:
extern unsigned short Func2(void);
void Func1(void)
{
Func2(); // <--
}
// POCCWarn3.c(5): warning #2046: Expression with no effect removed.
Making Func2 to a function returning void makes the warning go away. I hope it's only the result of Func2 that is removed, not the call to Func2 itself!
Example 4:
void Func(unsigned char ucType);
void Func(unsigned char ucType)
{
if (ucType == 0)
{
_asm {int 3} //<--
};
if (ucType & 0x2000)
{
//_asm {int 3}
};
}
// POCCWarn4.c(7): warning #3039: [asm] 'byte' value exceeds bounds.
This one caused me some headaches. The "[asm]" did lead me in a completely wrong direction. Actually, the warning is caused by line #9: an unsigned char cannot have bit mask 0x2000 set. But in my source code, this warning appeared hundreds of lines of code apart from that location. That was very difficult to find!