简体   繁体   English

具有内存集的EXC_BAD_ACCESS

[英]EXC_BAD_ACCESS with memset

Getting error Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) 收到错误Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

unsigned char *nkey;

memset(nkey, 0x00, 256); // error is here

I am setting nkey with a sprintf then after I use it as a parameter. 我将sprintf设置为nkey ,然后将其用作参数。

There are no compile time errors, but when running it shows that. 没有编译时错误,但是在运行时显示该错误。 I am using Xcode. 我正在使用Xcode。

首先,您需要为nkey分配内存,例如

unsigned char *nkey = new unsigned char[256]; // block of 256 uchars

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM