use*_*513 1 c constructor pointers segmentation-fault
我有以下代码段segfaults,我完全不知道为什么.任何帮助将非常感谢.
我执行此操作时会发生段错误(检查是否所有内容都已正确初始化).没有打印任何内容,因此它在第一行上出现了段错误.不幸的是我不能使用valgrind,因为这个代码位于我无法访问的沙箱中,因此无法检查那里的问题.
for (i = 0 ; i<nb_read ; i++) {
 fprintf(stdout, "Read Lock i %d  %p \n ",i, nap->read_buffer[i]->sem_handle); 
 fprintf(stdout, "Write Lock i %d  %p \n ",i, nap->write_buffer[i]->sem_handle);  
 fprintf(stdout, "Read Buffer i %d  %p \n ",i, nap->read_buffer[i]->buffer); 
 fprintf(stdout, "Write Buffer i %d  %p \n ",i, nap->write_buffer[i]->buffer); 
}
其中SharedStruct是一个带有char*缓冲区成员和int sem_handle的结构
SharedStruct** create_buffer(int nb, int size) {
SharedStruct** result = malloc(nb * sizeof(SharedStruct*));
int i = 0 ;
for (i = 0 ; i<nb ; i++) {
        SharedStruct* res= malloc(nb *sizeof(SharedStruct));
        res->buffer = malloc(size * sizeof(char)); 
        int lock = initialise_protection();
        fprintf(stdout, "\n Semaphore initialised to %d \n ", lock);
        res->sem_handle = lock ;
    }
    return result ;
 }