EVA插件:如何通过temp变量检查“ temp =(volatile unsigned short *)add”中的添加值

时间:2019-02-22 14:21:54

标签: c frama-c

在以下示例中,我试图通过temp变量检查“ temp =(volatile unsigned short *)add”中的加值:

main() {
    unsigned short add = 0x01;
    unsigned short val = 0x00;
    unsigned short *temp;
    temp = (volatile unsigned short*) add;
    *temp = val;
    //@ assert &temp == (unsigned short) 0x01;
}

但是我在“ // @ assert&temp ==(unsigned short)0x01;”行得到了这个错误。

[kernel] user error: incompatible types unsigned short and unsigned short **
[kernel] user error: stopping on file "test_func_call.c" that has errors. Add '-kernel-msg-key pp'for preprocessing command.

我知道可能全部与C有关,但我也使用Frama-C的标签。希望我能收到有关Frama-C检查增加值的答案。

1 个答案:

答案 0 :(得分:1)

关于:

assert &temp == (unsigned short) 0x01;  

这试图将temp(位于堆栈上)的地址与某个地址(堆栈上的该位置除外)进行比较。自然,assert()被触发

访问内存中特定地址内容的正确方法是:

temp =  *(unsigned short *) 0x01;