#DRC_DBG = 1
#PCNT = 1
+# Suppress minor warnings for dependencies
+deps/%: CFLAGS += -Wno-unused -Wno-unused-function
+
all: config.mak target_ plugins_
ifndef NO_CONFIG_MAK
#define core_fclose fclose
#endif
+#ifdef __GNUC__
+__attribute__ ((unused))
+#endif
static UINT64 core_fsize(core_file *f)
{
UINT64 rv;
case jit_code_name:
print_chr(' ');
if (node->v.p && _jitc->emit)
- print_str(node->v.n->u.p);
+ print_ptr(node->v.n->u.p);
break;
case jit_code_note:
print_chr(' ');
if (node->v.p && _jitc->emit)
- print_str(node->v.n->u.p);
+ print_ptr(node->v.n->u.p);
if (node->v.p && _jitc->emit && node->w.w)
print_chr(':');
if (node->w.w)
struct lightrec_state *state = block->state;
struct regcache *reg_cache = state->reg_cache;
jit_state_t *_jit = block->_jit;
- jit_node_t *to_not_ram, *to_end;
+ jit_node_t *to_not_ram, *to_end = 0;
u8 tmp, tmp2, tmp3, rs, rt;
jit_note(__FILE__, __LINE__);
struct lightrec_state *state = block->state;
struct regcache *reg_cache = state->reg_cache;
jit_state_t *_jit = block->_jit;
- jit_node_t *to_not_ram, *to_not_bios, *to_end, *to_end2;
+ jit_node_t *to_not_ram, *to_not_bios = 0, *to_end, *to_end2;
u8 tmp, rs, rt, addr_reg;
s16 imm;
for (i = 0; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++)
{
- char disk_name[PATH_MAX];
- char disk_label[PATH_MAX];
- disk_name[0] = '\0';
- disk_label[0] = '\0';
+ char disk_name[PATH_MAX - 16] = { 0 };
+ char disk_label[PATH_MAX] = { 0 };
disks[i].fname = strdup(info->path);
- get_disk_label(disk_name, info->path, PATH_MAX);
+ get_disk_label(disk_name, info->path, sizeof(disk_name));
snprintf(disk_label, sizeof(disk_label), "%s #%u", disk_name, (unsigned)i + 1);
disks[i].flabel = strdup(disk_label);
#ifdef _3DS
vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA) && !defined(__SWITCH__)
- posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
+ if (posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2) != 0)
+ vout_buf = (void *) 0;
#else
vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
#endif
#define ftello rftell
#define fseeko rfseek
#endif
+
#define OFF_T_MSB ((off_t)1 << (sizeof(off_t) * 8 - 1))
unsigned int cdrIsoMultidiskCount;
}
}
// check if it's really a TOC named as a .cue
- fgets(linebuf, sizeof(linebuf), fi);
- token = strtok(linebuf, " ");
- if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
- fclose(fi);
- return -1;
+ if (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
+ token = strtok(linebuf, " ");
+ if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
+ fclose(fi);
+ return -1;
+ }
}
fseek(fi, 0, SEEK_SET);
}
memset(&ti, 0, sizeof(ti));
// check if it's a valid mds file
- fread(&i, 1, sizeof(unsigned int), fi);
+ if (fread(&i, 1, sizeof(i), fi) != sizeof(i))
+ goto fail_io;
i = SWAP32(i);
if (i != 0x4944454D) {
// not an valid mds file
// get offset to session block
fseek(fi, 0x50, SEEK_SET);
- fread(&offset, 1, sizeof(unsigned int), fi);
+ if (fread(&offset, 1, sizeof(offset), fi) != sizeof(offset))
+ goto fail_io;
offset = SWAP32(offset);
// get total number of tracks
offset += 14;
fseek(fi, offset, SEEK_SET);
- fread(&s, 1, sizeof(unsigned short), fi);
+ if (fread(&s, 1, sizeof(s), fi) != sizeof(s))
+ goto fail_io;
s = SWAP16(s);
numtracks = s;
// get offset to track blocks
fseek(fi, 4, SEEK_CUR);
- fread(&offset, 1, sizeof(unsigned int), fi);
+ if (fread(&offset, 1, sizeof(offset), fi) != sizeof(offset))
+ goto fail_io;
offset = SWAP32(offset);
// skip lead-in data
ti[i].start[1] = fgetc(fi);
ti[i].start[2] = fgetc(fi);
- fread(&extra_offset, 1, sizeof(unsigned int), fi);
+ if (fread(&extra_offset, 1, sizeof(extra_offset), fi) != sizeof(extra_offset))
+ goto fail_io;
extra_offset = SWAP32(extra_offset);
// get track start offset (in .mdf)
fseek(fi, offset + 0x28, SEEK_SET);
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
ti[i].start_offset = l;
// get pregap
fseek(fi, extra_offset, SEEK_SET);
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
if (l != 0 && i > 1)
pregapOffset = msf2sec(ti[i].start);
// get the track length
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
sec2msf(l, ti[i].length);
offset += 0x50;
}
-
fclose(fi);
return 0;
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(fi);
+ return -1;
}
static int handlepbp(const char *isofile) {
}
psisoimg_offs = pbp_hdr.psar_offs;
- fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
+ if (fread(psar_sig, 1, sizeof(psar_sig), cdHandle) != sizeof(psar_sig))
+ goto fail_io;
psar_sig[10] = 0;
if (strcmp(psar_sig, "PSTITLEIMG") == 0) {
// multidisk image?
goto fail_io;
}
- fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
+ if (fread(psar_sig, 1, sizeof(psar_sig), cdHandle) != sizeof(psar_sig))
+ goto fail_io;
psar_sig[10] = 0;
}
// first 3 entries are special
fseek(cdHandle, sizeof(toc_entry), SEEK_CUR);
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
numtracks = btoi(toc_entry.index1[0]);
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
cd_length = btoi(toc_entry.index1[0]) * 60 * 75 +
btoi(toc_entry.index1[1]) * 75 + btoi(toc_entry.index1[2]);
for (i = 1; i <= numtracks; i++) {
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
ti[i].type = (toc_entry.type == 1) ? CDDA : DATA;
fail_index:
free(compr_img->index_table);
compr_img->index_table = NULL;
+ goto done;
+
fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+
+done:
if (compr_img != NULL) {
free(compr_img);
compr_img = NULL;
fseek(f, base + sector * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE), SEEK_SET);
ret = fread(dest, 1, CD_FRAMESIZE_RAW, f);
- fread(subbuffer, 1, SUB_FRAMESIZE, f);
+ if (fread(subbuffer, 1, SUB_FRAMESIZE, f) != SUB_FRAMESIZE)
+ goto fail_io;
if (subChanRaw) DecodeRawSubData();
+ goto done;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+done:
return ret;
}
if (ftello(cdHandle) % 2048 == 0) {
unsigned int modeTest = 0;
fseek(cdHandle, 0, SEEK_SET);
- fread(&modeTest, 4, 1, cdHandle);
+ if (fread(&modeTest, sizeof(modeTest), 1, cdHandle) != sizeof(modeTest)) {
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ return -1;
+ }
if (SWAP32(modeTest) != 0xffffff00) {
strcat(image_str, "[2048]");
isMode1ISO = TRUE;
if (subHandle != NULL) {
fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET);
- fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
+ if (fread(subbuffer, 1, SUB_FRAMESIZE, subHandle) != SUB_FRAMESIZE)
+ /* Faulty subchannel data shouldn't cause a read failure */
+ return 0;
if (subChanRaw) DecodeRawSubData();
}
#define _Branch_ (pc + 4 + ((short)_Im_ * 4))
#define _OfB_ _Im_, _nRs_
-#define dName(i) sprintf(ostr, "%s %-7s,", ostr, i)
-#define dGPR(i) sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i])
-#define dCP0(i) sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i])
-#define dHI() sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.n.hi, "hi")
-#define dLO() sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.n.lo, "lo")
-#define dImm() sprintf(ostr, "%s %4.4x (%d),", ostr, _Im_, _Im_)
-#define dTarget() sprintf(ostr, "%s %8.8x,", ostr, _Target_)
-#define dSa() sprintf(ostr, "%s %2.2x (%d),", ostr, _Sa_, _Sa_)
-#define dOfB() sprintf(ostr, "%s %4.4x (%8.8x (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_])
-#define dOffset() sprintf(ostr, "%s %8.8x,", ostr, _Branch_)
-#define dCode() sprintf(ostr, "%s %8.8x,", ostr, (code >> 6) & 0xffffff)
+#define dName(i) snprintf(ostr, sizeof(ostr), "%s %-7s,", ostr, i)
+#define dGPR(i) snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i])
+#define dCP0(i) snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i])
+#define dHI() snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.n.hi, "hi")
+#define dLO() snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.n.lo, "lo")
+#define dImm() snprintf(ostr, sizeof(ostr), "%s %4.4x (%d),", ostr, _Im_, _Im_)
+#define dTarget() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, _Target_)
+#define dSa() snprintf(ostr, sizeof(ostr), "%s %2.2x (%d),", ostr, _Sa_, _Sa_)
+#define dOfB() snprintf(ostr, sizeof(ostr), "%s %4.4x (%8.8x (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_])
+#define dOffset() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, _Branch_)
+#define dCode() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, (code >> 6) & 0xffffff)
/*********************************************************
* Arithmetic with immediate operand *
lightrec_map, ARRAY_SIZE(lightrec_map),
&lightrec_ops);
- fprintf(stderr, "M=0x%lx, P=0x%lx, R=0x%lx, H=0x%lx\n",
- (uintptr_t) psxM,
- (uintptr_t) psxP,
- (uintptr_t) psxR,
- (uintptr_t) psxH);
+ // fprintf(stderr, "M=0x%lx, P=0x%lx, R=0x%lx, H=0x%lx\n",
+ // (uintptr_t) psxM,
+ // (uintptr_t) psxP,
+ // (uintptr_t) psxR,
+ // (uintptr_t) psxH);
#ifndef _WIN32
signal(SIGPIPE, exit);
current = ftell(f);
fseek(f, 0L, SEEK_SET);
- fread(mybuf, 2048, 1, f);
+ if (fread(&mybuf, sizeof(mybuf), 1, f) != sizeof(mybuf))
+ goto io_fail;
+
fseek(f, current, SEEK_SET);
exe_hdr = (EXE_HEADER *)mybuf;
return COFF_EXE;
return INVALID_EXE;
+
+io_fail:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ return INVALID_EXE;
}
// temporary pandora workaround..
type = PSXGetFileType(tmpFile);
switch (type) {
case PSX_EXE:
- fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile);
+ if (fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile) != sizeof(EXE_HEADER))
+ goto fail_io;
section_address = SWAP32(tmpHead.t_addr);
section_size = SWAP32(tmpHead.t_size);
mem = PSXM(section_address);
fread_to_ram(mem, section_size, 1, tmpFile);
psxCpu->Clear(section_address, section_size / 4);
}
- fclose(tmpFile);
psxRegs.pc = SWAP32(tmpHead.pc0);
psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
case CPE_EXE:
fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */
do {
- fread(&opcode, 1, 1, tmpFile);
+ if (fread(&opcode, sizeof(opcode), 1, tmpFile) != sizeof(opcode))
+ goto fail_io;
switch (opcode) {
case 1: /* Section loading */
- fread(§ion_address, 4, 1, tmpFile);
- fread(§ion_size, 4, 1, tmpFile);
+ if (fread(§ion_address, sizeof(section_address), 1, tmpFile) != sizeof(section_address))
+ goto fail_io;
+ if (fread(§ion_size, sizeof(section_size), 1, tmpFile) != sizeof(section_size))
+ goto fail_io;
section_address = SWAPu32(section_address);
section_size = SWAPu32(section_size);
#ifdef EMU_LOG
break;
case 3: /* register loading (PC only?) */
fseek(tmpFile, 2, SEEK_CUR); /* unknown field */
- fread(&psxRegs.pc, 4, 1, tmpFile);
+ if (fread(&psxRegs.pc, sizeof(psxRegs.pc), 1, tmpFile) != sizeof(psxRegs.pc))
+ goto fail_io;
psxRegs.pc = SWAPu32(psxRegs.pc);
break;
case 0: /* End of file */
CdromLabel[0] = '\0';
}
+ fclose(tmpFile);
return retval;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(tmpFile);
+ return -1;
}
// STATES
if (ppffile == NULL) return;
memset(buffer, 0, 5);
- fread(buffer, 3, 1, ppffile);
+ if (fread(buffer, 3, 1, ppffile) != 3)
+ goto fail_io;
if (strcmp(buffer, "PPF") != 0) {
SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF);
fseek(ppffile, -8, SEEK_END);
memset(buffer, 0, 5);
- fread(buffer, 4, 1, ppffile);
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
if (strcmp(".DIZ", buffer) != 0) {
dizyn = 0;
} else {
- fread(&dizlen, 4, 1, ppffile);
+ if (fread(&dizlen, 4, 1, ppffile) != 4)
+ goto fail_io;
dizlen = SWAP32(dizlen);
dizyn = 1;
}
fseek(ppffile, -6, SEEK_END);
memset(buffer, 0, 5);
- fread(buffer, 4, 1, ppffile);
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
dizlen = 0;
if (strcmp(".DIZ", buffer) == 0) {
fseek(ppffile, -2, SEEK_END);
- fread(&dizlen, 2, 1, ppffile);
+ // TODO: Endian/size unsafe?
+ if (fread(&dizlen, 2, 1, ppffile) != 2)
+ goto fail_io;
dizlen = SWAP32(dizlen);
dizlen += 36;
}
// now do the data reading
do {
fseek(ppffile, seekpos, SEEK_SET);
- fread(&pos, 4, 1, ppffile);
+ if (fread(&pos, sizeof(pos), 1, ppffile) != sizeof(pos))
+ goto fail_io;
pos = SWAP32(pos);
- if (method == 2) fread(buffer, 4, 1, ppffile); // skip 4 bytes on ppf3 (no int64 support here)
+ if (method == 2) {
+ // skip 4 bytes on ppf3 (no int64 support here)
+ if (fread(buffer, 4, 1, ppffile) != 4)
+ goto fail_io;
+ }
anz = fgetc(ppffile);
- fread(ppfmem, anz, 1, ppffile);
+ if (fread(ppfmem, anz, 1, ppffile) != anz)
+ goto fail_io;
ladr = pos / CD_FRAMESIZE_RAW;
off = pos % CD_FRAMESIZE_RAW;
FillPPFCache(); // build address array
SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF);
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(ppffile);
}
// redump.org SBI files, slightly different handling from PCSX-Reloaded
}
// 4-byte SBI header
- fread(buffer, 1, 4, sbihandle);
+ if (fread(buffer, 1, 4, sbihandle) != 4)
+ goto fail_io;
+
while (1) {
s = fread(sbitime, 1, 3, sbihandle);
if (s != 3)
- break;
- fread(&t, 1, 1, sbihandle);
+ goto fail_io;
+ if (fread(&t, sizeof(t), 1, sbihandle) != sizeof(t))
+ goto fail_io;
switch (t) {
default:
case 1:
}
fclose(sbihandle);
-
return 0;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(sbihandle);
+ return -1;
}
void UnloadSBI(void) {
#define debugI()
#endif
-#ifdef NDEBUG
+#ifndef NDEBUG
+#include "debug.h"
+#else
void StartDebugger() {}
void ProcessDebug() {}
void StopDebugger() {}
#define MAP_ANONYMOUS MAP_ANON
#endif
-#ifdef NDEBUG
+#ifndef NDEBUG
+#include "debug.h"
+#else
void DebugCheckBP(u32 address, enum breakpoint_types type) {}
#endif
memset(psxM, 0, 0x00200000);
memset(psxP, 0xff, 0x00010000);
+ Config.HLE = TRUE;
+
if (strcmp(Config.Bios, "HLE") != 0) {
sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios);
f = fopen(bios, "rb");
if (f == NULL) {
SysMessage(_("Could not open BIOS:\"%s\". Enabling HLE Bios!\n"), bios);
memset(psxR, 0, 0x80000);
- Config.HLE = TRUE;
} else {
- fread(psxR, 1, 0x80000, f);
+ if (fread(psxR, 1, 0x80000, f) == 0x80000) {
+ Config.HLE = FALSE;
+ } else {
+ SysMessage(_("The selected BIOS:\"%s\" is of wrong size. Enabling HLE Bios!\n"), bios);
+ }
fclose(f);
- Config.HLE = FALSE;
}
- } else Config.HLE = TRUE;
+ }
}
void psxMemShutdown() {
else if(buf.st_size == MCD_SIZE + 3904)
fseek(f, 3904, SEEK_SET);
}
- fread(data, 1, MCD_SIZE, f);
+ if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) {
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ memset(data, 0x00, MCD_SIZE);
+ }
fclose(f);
}
else
else if(buf.st_size == MCD_SIZE + 3904)
fseek(f, 3904, SEEK_SET);
}
- fread(data, 1, MCD_SIZE, f);
+ if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) {
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ memset(data, 0x00, MCD_SIZE);
+ }
fclose(f);
}
}
}
out_current = &out_drivers[i];
- printf("selected sound output driver: %s\n", out_current->name);
+ // printf("selected sound output driver: %s\n", out_current->name);
}