EXC_BAD_ACCESS with memset

EXC_BAD_ACCESS with memset

本文关键字:memset with BAD EXC ACCESS      更新时间:2023-10-16

获取错误Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

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

我将nkey设置为sprintf,然后将其用作参数。

没有编译时错误,但在运行时显示。

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

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