gpt4 book ai didi

c - 使用 sscanf_s 时变量周围的堆栈已损坏

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:07 26 4
gpt4 key购买 nike

我不明白为什么我会收到错误消息“变量“tmp”周围的堆栈已损坏”。

我在不同的函数中使用相同的代码并且运行良好,但现在当函数“返回”时它会抛出上述错误。

struct frame {
uint8_t dst[6];
uint8_t src[6];
};

//fill frame.dst || src exactly same way as code below without any errors or warnings

bool fcn() {

uint8_t tmp[6];

sscanf_s("00-00-00-00-00-00", "%x-%x-%x-%x-%x-%x", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
//here I compare tmp[0] == frame.mac[0]...
return true;
} //here pops the error while debugging

我在程序的不同部分使用了完全相同的代码,但从来没有出现任何错误。

最佳答案

引用 C-Standard 确认系统:

要在 32 位机器上扫描 8 位值,需要使用 "hh" 长度修饰符。 32的一半是8


对于 VC,需要使用一种变通方法扫描到 unsigned int

关于c - 使用 sscanf_s 时变量周围的堆栈已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594313/

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