如何修复这两个警告。我已经反编译了这段代码并修改了一些但我无法摆脱这两个警告。
我想我需要将int DecryptedPacketa
更改为char * DecryptedPacketa
或void * DecryptedPacketa
类似的内容?或者什么?
encryption.c:26: warning: assignment makes integer from pointer without a cast
encryption.c:27: warning: comparison between pointer and integer
void EncryptPacket(unsigned char *DecryptedPacket)
{
int DecryptedPacketa;
char *addressEncryptedPacket;
const int packetSize = *(unsigned short *)DecryptedPacket+77;
unsigned char EncryptedPacket[packetSize];
*(unsigned short *)(EncryptedPacket+77) = packetSize;
addressEncryptedPacket = EncryptedPacket + 2;
//Skips first 2 bytes of DecryptedPacket before looping to end of DecryptedPacket Buffer.
//Process Byte by Byte for transformations.
for ( DecryptedPacketa = &DecryptedPacket + 3; //<- Warning 1
DecryptedPacketa < &DecryptedPacket + packetSize; //<- Warning 2
++DecryptedPacketa )
{
//... Lots of code (fake example below)...
*addressEncryptedPacket = 123 + *(unsigned char *)DecryptedPacketa; //does encryption here
//... Lots of code ...
}
}
答案 0 :(得分:1)
DecryptedPacketa
的类型为int
,如语句
int DecryptedPacketa;
但你正在为它指定一个指针。再次,您将它与循环条件中的指针进行比较。这就是你收到这些警告的原因。
您需要做的是将DecryptedPacketa
定义为unsigned char *
类型并将for
循环更改为
unsigned char *DecryptedPacketa;
for (DecryptedPacketa = DecryptedPacket + 2;
DecryptedPacketa < DecryptedPacket + packetSize;
++DecryptedPacketa)
{
// loop body
}
您需要在开头跳过两个字节。因此,您应该从DecryptedPacket + 2
开始循环。另请注意,函数参数DecryptedPacket
已经是指针。您无需向其应用address-of
运算符&
。