From 9a14430a8839432cbef8dfb575c92ae29686feb1 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Mon, 23 Apr 2018 17:43:04 -0700 Subject: [PATCH] Fixed segmentation fault by clarifying pointer of pointer --- demo/extractmesh.c | 2 +- demo/extracttexture.c | 2 +- include/devil1geo.h | 2 +- include/devil1tex.h | 2 +- src/devil1geo.c | 8 ++++---- src/devil1tex.c | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/demo/extractmesh.c b/demo/extractmesh.c index ba49f9b..d15dde7 100644 --- a/demo/extractmesh.c +++ b/demo/extractmesh.c @@ -60,7 +60,7 @@ void extractmeshes(const char *filedata, const char *filename, unsigned int filesize) { struct Header *h = NULL; - if (!(DEVIL1GEO.getheader(h, filedata))|| filesize <= 0) { + if (!(DEVIL1GEO.getheader(&h, filedata))|| filesize <= 0) { return; } struct MeshHeader *mh = NULL; diff --git a/demo/extracttexture.c b/demo/extracttexture.c index 839ad84..8a187c3 100644 --- a/demo/extracttexture.c +++ b/demo/extracttexture.c @@ -8,7 +8,7 @@ void extracttextures(const char *filedata, struct Texture *t = NULL; struct TextureBatchDescriptor *d = NULL; char * fmt = NULL; - if (!(DEVIL1TEX.getheader(p, filedata)) || filesize == 0) { + if (!(DEVIL1TEX.getheader(&p, filedata)) || filesize == 0) { return; } fmt = (char*)malloc(strlen(filename) + 3 + 4); diff --git a/include/devil1geo.h b/include/devil1geo.h index 6d08f1e..7293041 100644 --- a/include/devil1geo.h +++ b/include/devil1geo.h @@ -86,7 +86,7 @@ typedef struct { void (* const printcoordinate)(struct Coordinate*, unsigned int); // 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 // ** = 'pass by reference' of a pointer to struct diff --git a/include/devil1tex.h b/include/devil1tex.h index b002a0a..f45be35 100644 --- a/include/devil1tex.h +++ b/include/devil1tex.h @@ -46,7 +46,7 @@ typedef struct { void (* const printbatchdesc)(struct TextureBatchDescriptor*); // 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 // ** = 'pass by reference' of a pointer to struct diff --git a/src/devil1geo.c b/src/devil1geo.c index 70f5bd8..72357af 100644 --- a/src/devil1geo.c +++ b/src/devil1geo.c @@ -9,7 +9,7 @@ static void printmeshbatch(struct Batch*); 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); @@ -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) { return false; } - h = (struct Header*)filedata; + (*h) = (struct Header*)filedata; return true; } @@ -89,7 +89,7 @@ static bool getmeshheader(struct MeshHeader **hs, const char * const filedata) { bool done = false; struct Header *h = NULL; - if (hs == NULL || !(getgheader(h, filedata))) { + if (hs == NULL || !(getgheader(&h, filedata))) { return done; } if (h -> numMesh < i) { diff --git a/src/devil1tex.c b/src/devil1tex.c index 92bc717..f284cd8 100644 --- a/src/devil1tex.c +++ b/src/devil1tex.c @@ -9,7 +9,7 @@ static void printtph(struct TexturePack*); static void printtbd(struct TextureBatchDescriptor*); // Get Texture Pack Header -static inline bool getpackheader(struct TexturePack*, const char*); +static inline bool getpackheader(struct TexturePack**, const char*); // Get Texture Batch Descriptor. 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) { return false; } - p = (struct TexturePack*)filedata; + (*p) = (struct TexturePack*)filedata; return true; } @@ -86,7 +86,7 @@ static bool gettexbatch(struct TextureBatch **batch, const char *filedata, unsigned int filesize) { struct TexturePack *p = NULL; - if (!(getpackheader(p, filedata))) { + if (!(getpackheader(&p, filedata))) { return false; } if (i > p -> batchNumber) { // no such batch in texture pack