From 5feeccd952c572dcd0a81265746975f09eed67ea Mon Sep 17 00:00:00 2001 From: White Dragon <000whitedragon000@gmail.com> Date: Mon, 16 Jul 2018 01:45:35 +0200 Subject: [PATCH] fixed a heavy bug on malloc structure --- engine/psp/menu.c | 6 +++--- engine/sdl/menu.c | 6 +++--- engine/vita/menu.c | 6 +++--- engine/wii/menu.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/engine/psp/menu.c b/engine/psp/menu.c index 875cbb022..c8b5a0aff 100644 --- a/engine/psp/menu.c +++ b/engine/psp/menu.c @@ -246,11 +246,11 @@ static int findPaks(void) if(filelist == NULL) filelist = malloc(sizeof(fileliststruct)); else { - copy = malloc(i * sizeof(fileliststruct)); - memcpy(copy, filelist, i * sizeof(fileliststruct)); + copy = malloc((i + 1) * sizeof(fileliststruct)); + memcpy(copy, filelist, (i + 1) * sizeof(fileliststruct)); free(filelist); filelist = malloc((i + 1) * sizeof(fileliststruct)); - memcpy(filelist, copy, i * sizeof(fileliststruct)); + memcpy(filelist, copy, (i + 1) * sizeof(fileliststruct)); free(copy); copy = NULL; } memset(&filelist[i], 0, sizeof(fileliststruct)); diff --git a/engine/sdl/menu.c b/engine/sdl/menu.c index 6b89ad2d4..8228200c7 100644 --- a/engine/sdl/menu.c +++ b/engine/sdl/menu.c @@ -185,11 +185,11 @@ static int findPaks(void) if(filelist == NULL) filelist = malloc(sizeof(fileliststruct)); else { - copy = malloc(i * sizeof(fileliststruct)); - memcpy(copy, filelist, i * sizeof(fileliststruct)); + copy = malloc((i + 1) * sizeof(fileliststruct)); + memcpy(copy, filelist, (i + 1) * sizeof(fileliststruct)); free(filelist); filelist = malloc((i + 1) * sizeof(fileliststruct)); - memcpy(filelist, copy, i * sizeof(fileliststruct)); + memcpy(filelist, copy, (i + 1) * sizeof(fileliststruct)); free(copy); copy = NULL; } memset(&filelist[i], 0, sizeof(fileliststruct)); diff --git a/engine/vita/menu.c b/engine/vita/menu.c index 3e03d9d53..97a04f078 100644 --- a/engine/vita/menu.c +++ b/engine/vita/menu.c @@ -188,11 +188,11 @@ static int findPaks(void) if (filelist == NULL) filelist = malloc(sizeof(fileliststruct)); else { - copy = malloc(i * sizeof(fileliststruct)); - memcpy(copy, filelist, i * sizeof(fileliststruct)); + copy = malloc((i + 1) * sizeof(fileliststruct)); + memcpy(copy, filelist, (i + 1) * sizeof(fileliststruct)); free(filelist); filelist = malloc((i + 1) * sizeof(fileliststruct)); - memcpy(filelist, copy, i * sizeof(fileliststruct)); + memcpy(filelist, copy, (i + 1) * sizeof(fileliststruct)); free(copy); copy = NULL; } memset(&filelist[i], 0, sizeof(fileliststruct)); diff --git a/engine/wii/menu.c b/engine/wii/menu.c index 6f50bc248..c9f07bb98 100644 --- a/engine/wii/menu.c +++ b/engine/wii/menu.c @@ -317,11 +317,11 @@ static int findPaks(void) if(filelist == NULL) filelist = malloc(sizeof(fileliststruct)); else { - copy = malloc(i * sizeof(fileliststruct)); - memcpy(copy, filelist, i * sizeof(fileliststruct)); + copy = malloc((i + 1) * sizeof(fileliststruct)); + memcpy(copy, filelist, (i + 1) * sizeof(fileliststruct)); free(filelist); filelist = malloc((i + 1) * sizeof(fileliststruct)); - memcpy(filelist, copy, i * sizeof(fileliststruct)); + memcpy(filelist, copy, (i + 1) * sizeof(fileliststruct)); free(copy); copy = NULL; } memset(&filelist[i], 0, sizeof(fileliststruct));