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));