X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fppf.c;h=edebdd03768638be3d2fe15a3f179347349d87cb;hb=HEAD;hp=454290d0d204ba462b0409b4e94e6e72789b0499;hpb=4904809d2ed121844ea23cf0ea580785d3da1f0b;p=pcsx_rearmed.git diff --git a/libpcsxcore/ppf.c b/libpcsxcore/ppf.c index 454290d0..f37687cc 100644 --- a/libpcsxcore/ppf.c +++ b/libpcsxcore/ppf.c @@ -21,6 +21,7 @@ #include "psxcommon.h" #include "ppf.h" +#include "misc.h" #include "cdrom.h" typedef struct tagPPF_DATA { @@ -58,6 +59,7 @@ static void FillPPFCache() { if (iPPFNum <= 0) return; pc = ppfCache = (PPF_CACHE *)malloc(iPPFNum * sizeof(PPF_CACHE)); + if (pc == NULL) return; iPPFNum--; p = ppfHead; @@ -133,6 +135,7 @@ void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { if (ppfHead == NULL) { ppfHead = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + if (ppfHead == NULL) return; ppfHead->addr = ladr; ppfHead->pNext = NULL; ppfHead->pos = pos; @@ -164,6 +167,7 @@ static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { } padd = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + if (padd == NULL) return; padd->addr = ladr; padd->pNext = p; padd->pos = pos; @@ -353,6 +357,7 @@ fail_io: // redump.org SBI files, slightly different handling from PCSX-Reloaded unsigned char *sbi_sectors; +int sbi_len; int LoadSBI(const char *fname, int sector_count) { int good_sectors = 0; @@ -366,7 +371,8 @@ int LoadSBI(const char *fname, int sector_count) { if (sbihandle == NULL) return -1; - sbi_sectors = calloc(1, sector_count / 8); + sbi_len = (sector_count + 7) / 8; + sbi_sectors = calloc(1, sbi_len); if (sbi_sectors == NULL) goto end; @@ -410,15 +416,13 @@ int LoadSBI(const char *fname, int sector_count) { break; } - fclose(sbihandle); - return 0; - end: if (!clean_eof) SysPrintf(_("SBI: parse failure at 0x%lx\n"), ftell(sbihandle)); if (!good_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } fclose(sbihandle); return sbi_sectors ? 0 : -1; @@ -428,5 +432,6 @@ void UnloadSBI(void) { if (sbi_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } }