简体   繁体   English

线程1:生成EXC_BAD_ACCESS(代码= 1,地址= 0x0)问题

[英]Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x0) issue is generated

I'm using apple LLVM compiler for C++ development in Xcode. 我正在使用Apple LLVM编译器在Xcode中进行C ++开发。 I initialise the char pickbuf variable and allocate the required memory I want to assign value 1 to second code of line there. 我初始化了char pickbuf变量,并分配了所需的内存,我想将值1分配给那里的第二行代码。 But I'm getting a null pointer error: please help me. 但是我收到了空指针错误:请帮助我。

2DCDP4.h 2DCDP4.h

  class CDP : public Const2DCDP{

    struct PICK
        {
            short x;            // Transverse connector
            short y;            // Vertical direction consolidated
            unsigned char x0;   // Transverse reduction limit
            unsigned char y0;   // Longitudinal reduction limit
        } ;

    public:

        char*   pickbuf =new char[1];   // Overlapping buffer allocate some 
        PICK*   pickup =new PICK [1];       // Backtrace buffer

    }
void getProjection(void);
    };

2DCDP4.cpp 2DCDP4.cpp

#include "2DCDP4.h"

void CDP::getProjection(void){
char    *before=pickbuf;
if( before[(j-1)*di + (i-1)] == 1) //**Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x0)**
{
//code 
}
}

You haven't allocated any memory to pickbuf , but try to access the memory at pickbuf on the 2nd line. 您尚未为pickbuf分配任何内存,但尝试在第二行的pickbuf上访问该内存。 To fix this, allocate some memory to pickbuf before the 2nd line: 要解决此问题, pickbuf在第二行之前为pickbuf分配一些内存:

char pickbuf[n];

or 要么

char* pickbuf = new char[n];

Where n is a size large enough for you needs. 其中n是足以满足您需要的大小。

暂无
暂无

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

相关问题 线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)错误 - Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) error 代码错误:线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0) - code error : Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) 线程 1:xcode 中的 EXC_BAD_ACCESS(代码 = 1,地址 = 0x0)错误 - Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) error in xcode Xcode:线程1:制作邻接表时,EXC_BAD_ACCESS(代码= 1,地址= 0x0) - Xcode: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) when making adjacency list 调用 glCreateShader 时出现运行时错误“线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x0)” - Getting runtime error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)" whencalling glCreateShader 线程 1:使用 scanf 时出现 EXC_BAD_ACCESS (code=1, address=0x0) 错误 - Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) error while using scanf 我的动态数组有问题 - 线程 1:EXC_BAD_ACCESS (code=1, address=0x0) - Problem with my dynamic array - Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) C ++节点分配错误:线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0) - C++ node assign error: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) 线程 1:向量插入上的 EXC_BAD_ACCESS(代码=1,地址=0x0) - Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) on vector insert C ++:尝试将新节点添加到链接列表会产生“线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)”错误 - C++: Attempting to add new node to linked list yields “Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM