#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char** thingSize;
} Thing;
typedef struct {
Thing* thing;
} Game;
void load_array(Thing* thing) {
int i, j;
char **emptyThing = malloc(sizeof(char**));
emptyThing = malloc(sizeof(char*)*9);
for(i=0; i<9; i++) {
emptyThing[i] = malloc(sizeof(char)*9);
}
thing -> thingSize = emptyThing;
free(emptyThing);
}
int main(int argc, char* argv[]) {
Game* game;
load_array(game -> thing);
printf("HI");
}
분할 오류가 발생하고 문제 라인이 있음을 발견했습니다. thing -> thingSize = emptyThing;
thingSize를 emptyThing과 같은 2d 배열로 설정하려고합니다.
Fredrik이 말했듯이 게임 포인터는 아무것도 초기화되지 않습니다. 가비지 값을 보유하고 있으며 참조를 해제하면 segfault가 발생합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다