1.越界
void testptr()
{
char str[4]=”abcd”;
printf(“%s”,str);//str[]没有\0
}
2.返回局部变量地址
char* testptr()
{
char str[]=”jsdafj”;
return str;//str在栈区,函数执行完即释放
}
3.同一块内存释放多次
void testptr()
{
char* p=(char*)malloc(10);
if(p!=NULL)
free(p);
free(p);
}
4.操作野指针