我现在正在学习 KLEE,我写了一个简单的代码:
#include "klee/klee.h"
#include <stdio.h>
#include <stdlib.h>
int test(int *p)
{
int *q = (int *) malloc(sizeof(int));
if ((*p) == (*q)) {
printf("reading uninitialized heap memory");
}
return 0;
}
int main()
{
int *p = (int *) malloc(sizeof(int));
test(p);
return 0;
}
首先,我生成 LLVM 位码,然后对位码执行 KLEE。以下是所有输出:
KLEE: output directory is "/Users/yjy/WorkSpace/Test/klee-out-13"
Using STP solver backend
KLEE: WARNING: undefined reference to function: printf
KLEE: WARNING ONCE: calling external: printf(140351601907424)
reading uninitialized heap memory
KLEE: done: total instructions = 61
KLEE: done: completed paths = 4
KLEE: done: generated tests = 4
我想 KLEE 应该给我一个错误,即 q 指针未初始化,但事实并非如此。为什么 KLEE 没有给我一个错误或警告?KLEE不能检测到这个错误吗?提前致谢!