gpt4 book ai didi

c - 两个警告 : assignment makes integer from pointer without a cast and comparison between pointer and integer

转载 作者:行者123 更新时间:2023-11-30 19:19:50 24 4
gpt4 key购买 nike

如何修复这两个警告。我已经反编译了这段代码并对其进行了一些修复,但我无法摆脱这两个警告。

我想我需要将 int DecryptedPacketa 更改为 char * DecryptedPacketavoid * 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 ...
}
}

最佳答案

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 运算符 &

关于c - 两个警告 : assignment makes integer from pointer without a cast and comparison between pointer and integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23646794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com