有没有熟悉Android NDK的高手指导一下,为什么用malloc分配一块内存,只要对这块内存进行操作就报错呢?
[1] + Stopped (signal)或Segmentation fault !
本人的实验代码如下:
void main()
{
uint8_t arry[20] = “hello world\n”;
uint8_t*buffer= (uint8_t *) malloc(sizeof(uint8_t) * 100);
if(buffer = NULL){
printf(“buffer malloc erro!\n”);
return;
}
size_t len = strlen(arry) + 1;
memcpy(buffer,arry,len);
printf(“memcopy end\n”);
free(buffer);
}
[1] + Stopped (signal)或Segmentation fault !
本人的实验代码如下:
void main()
{
uint8_t arry[20] = “hello world\n”;
uint8_t*buffer= (uint8_t *) malloc(sizeof(uint8_t) * 100);
if(buffer = NULL){
printf(“buffer malloc erro!\n”);
return;
}
size_t len = strlen(arry) + 1;
memcpy(buffer,arry,len);
printf(“memcopy end\n”);
free(buffer);
}
解决方案