Fixed segmentation fault by clarifying pointer of pointer

This commit is contained in:
_ 2018-04-23 17:43:04 -07:00
parent 046e1f8617
commit 9a14430a88
6 changed files with 12 additions and 12 deletions

View File

@ -60,7 +60,7 @@ void extractmeshes(const char *filedata,
const char *filename, const char *filename,
unsigned int filesize) { unsigned int filesize) {
struct Header *h = NULL; struct Header *h = NULL;
if (!(DEVIL1GEO.getheader(h, filedata))|| filesize <= 0) { if (!(DEVIL1GEO.getheader(&h, filedata))|| filesize <= 0) {
return; return;
} }
struct MeshHeader *mh = NULL; struct MeshHeader *mh = NULL;

View File

@ -8,7 +8,7 @@ void extracttextures(const char *filedata,
struct Texture *t = NULL; struct Texture *t = NULL;
struct TextureBatchDescriptor *d = NULL; struct TextureBatchDescriptor *d = NULL;
char * fmt = NULL; char * fmt = NULL;
if (!(DEVIL1TEX.getheader(p, filedata)) || filesize == 0) { if (!(DEVIL1TEX.getheader(&p, filedata)) || filesize == 0) {
return; return;
} }
fmt = (char*)malloc(strlen(filename) + 3 + 4); fmt = (char*)malloc(strlen(filename) + 3 + 4);

View File

@ -86,7 +86,7 @@ typedef struct {
void (* const printcoordinate)(struct Coordinate*, unsigned int); void (* const printcoordinate)(struct Coordinate*, unsigned int);
// input: pointer to struct, file data // input: pointer to struct, file data
bool (* const getheader) (struct Header*, const char*); bool (* const getheader) (struct Header**, const char*);
// input: pointer of pointer to struct, order, file data // input: pointer of pointer to struct, order, file data
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct

View File

@ -46,7 +46,7 @@ typedef struct {
void (* const printbatchdesc)(struct TextureBatchDescriptor*); void (* const printbatchdesc)(struct TextureBatchDescriptor*);
// input: pointer to struct, file data // input: pointer to struct, file data
bool (* const getheader) (struct TexturePack*, const char*); bool (* const getheader) (struct TexturePack**, const char*);
// input: pointer of pointer to struct, order, file data, file size // input: pointer of pointer to struct, order, file data, file size
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct

View File

@ -9,7 +9,7 @@ static void printmeshbatch(struct Batch*);
static void printcoordinate(struct Coordinate*, unsigned int); static void printcoordinate(struct Coordinate*, unsigned int);
static bool getgheader(struct Header*, const char*); static bool getgheader(struct Header**, const char*);
static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
@ -76,11 +76,11 @@ static void printcoordinate(struct Coordinate *p, unsigned int count) {
} }
} }
static bool getgheader(struct Header* h, const char* filedata) { static bool getgheader(struct Header** h, const char* filedata) {
if (filedata == NULL) { if (filedata == NULL) {
return false; return false;
} }
h = (struct Header*)filedata; (*h) = (struct Header*)filedata;
return true; return true;
} }
@ -89,7 +89,7 @@ static bool getmeshheader(struct MeshHeader **hs,
const char * const filedata) { const char * const filedata) {
bool done = false; bool done = false;
struct Header *h = NULL; struct Header *h = NULL;
if (hs == NULL || !(getgheader(h, filedata))) { if (hs == NULL || !(getgheader(&h, filedata))) {
return done; return done;
} }
if (h -> numMesh < i) { if (h -> numMesh < i) {

View File

@ -9,7 +9,7 @@ static void printtph(struct TexturePack*);
static void printtbd(struct TextureBatchDescriptor*); static void printtbd(struct TextureBatchDescriptor*);
// Get Texture Pack Header // Get Texture Pack Header
static inline bool getpackheader(struct TexturePack*, const char*); static inline bool getpackheader(struct TexturePack**, const char*);
// Get Texture Batch Descriptor. // Get Texture Batch Descriptor.
static bool gettexdescriptor(struct TextureBatchDescriptor**, static bool gettexdescriptor(struct TextureBatchDescriptor**,
@ -58,11 +58,11 @@ static void printtbd(struct TextureBatchDescriptor *bd) {
} }
} }
inline static bool getpackheader(struct TexturePack* p, const char *filedata) { inline static bool getpackheader(struct TexturePack** p, const char *filedata) {
if (filedata == NULL) { if (filedata == NULL) {
return false; return false;
} }
p = (struct TexturePack*)filedata; (*p) = (struct TexturePack*)filedata;
return true; return true;
} }
@ -86,7 +86,7 @@ static bool gettexbatch(struct TextureBatch **batch,
const char *filedata, const char *filedata,
unsigned int filesize) { unsigned int filesize) {
struct TexturePack *p = NULL; struct TexturePack *p = NULL;
if (!(getpackheader(p, filedata))) { if (!(getpackheader(&p, filedata))) {
return false; return false;
} }
if (i > p -> batchNumber) { // no such batch in texture pack if (i > p -> batchNumber) { // no such batch in texture pack