c - GCC 是否具有检测 use-after-free 错误的功能?
问题描述
这是我的代码片段:
#include <stdlib.h>
#include <stdio.h>
typedef struct node
{
char key; // value
struct node *next; // pointer to the next element
} Node;
int main(void)
{
Node *n = malloc(sizeof(Node));
n->key = 'K';
n->next = NULL;
free(n);
printf("%c\n", n->key);
}
当上面的代码片段被编译并运行时......
ganningxu@Gannings-Computer:~/test$ gcc test_faults.c -o test_faults; ./test_faults
K
ganningxu@Gannings-Computer:~/test$ clang test_faults.c -o test_faults; ./test_faults
K
访问释放的内存时没有编译器警告或错误。有没有办法强制编译器显示此类错误?
解决方案
推荐阅读
- swift - 我正在 SpriteKit 中开发俄罗斯方块并得到一个奇怪的错误
- jupyter-notebook - 在 nbconvert 中更改 URL 的格式设置行为
- selenium - 在 IE webddriver 上查找元素定位器(实际上是任何驱动程序)
- python - 试图包装类方法,但 __init__() 被包装了
- html - 当屏幕分辨率改变时如何调整我的导航栏的内容
- reactjs - TypeError:无法读取未定义的属性“警报”
- .net - 强制 Visual Studio 在路径中使用引用
- javascript - 如何从 jquery 中的表中获取多个单选按钮值到另一个表中
- design-patterns - 无法将消息推送到客户端(仅拉取)的可扩展、多登录服务器/客户端架构
- angular - PUT 请求失败,出现“错误代码 0”和 net::ERR_METHOD_NOT_SUPPORTED(仅限 chrome)