From a188a19d771bb51d79a69a0bd820532325a591fa Mon Sep 17 00:00:00 2001 From: _ <_> Date: Mon, 2 Apr 2018 01:55:07 -0700 Subject: [PATCH] Minor tweak to parameters in splitpld() --- test/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/main.c b/test/main.c index bc7a68b..e5879e6 100644 --- a/test/main.c +++ b/test/main.c @@ -21,10 +21,10 @@ bool writedata(const char *basename, return status; } -void splitpld(const char *buffer, - const struct PldHeader *ph, - const char *name, - unsigned int s) { +void splitpld(const char *filedata, + unsigned int filesize, + const struct PldHeader *ph, + const char *name) { char *wbuffer = NULL; // write buffer that will change. unsigned int wsize = 0; // size of wbuffer. unsigned int i; @@ -33,15 +33,16 @@ void splitpld(const char *buffer, for (i = 0; (i + 1) < (ph -> numOffset) + 1; i++) { start = ph -> offsets[i]; // the last offset still has some data until the end of file - end = (i == (ph -> numOffset) - 1) ? s : ph -> offsets[i + 1]; + end = (i == (ph -> numOffset) - 1) ? + filesize : ph -> offsets[i + 1]; // copy sector to write buffer wsize = end - start; wbuffer = (char*)malloc(sizeof(char) * wsize); - memcpy(wbuffer, buffer + start, wsize); + memcpy(wbuffer, filedata + start, wsize); // create a file. writedata(name, i, wbuffer, wsize); + free(wbuffer); } - free(wbuffer); } char *loadfile(const char *fname, unsigned int *s) { @@ -80,7 +81,7 @@ bool unpackpld (const char *filedata, printf("fsize is %i\n", filesize); if (filedata != NULL && filesize != 0) { struct PldHeader *pldh = getpldh(filedata); - splitpld(filedata, pldh, filename, filesize); + splitpld(filedata, filesize, pldh, filename); destroypldh(pldh); status = true; }