void set3(int *tmp)
{
*tmp = 6;
}
{
*tmp = 6;
}
int main(int argc, char* argv[])
{
int a = 0;
char * pcTemp = NULL;
int * piTemp = NULL;
pcTemp = (char*)malloc(3);
if( NULL == pcTemp )
{
return 0;
}
// *(int *)pcTemp = 6;
// *pcTemp = (int)6;
set3((int *)pcTemp);
{
int a = 0;
char * pcTemp = NULL;
int * piTemp = NULL;
pcTemp = (char*)malloc(3);
if( NULL == pcTemp )
{
return 0;
}
// *(int *)pcTemp = 6;
// *pcTemp = (int)6;
set3((int *)pcTemp);
printf("Hello World!/n");
free(pcTemp);
return 0;
}
free(pcTemp);
return 0;
}
// //
pcTemp 只malloc了3个字节,
但是在set3函数中,将其转换成int指针后,int指针所指的 4个字节的内容被赋值了,造成内存越界。