diff --git a/Common/ChunkFile.h b/Common/ChunkFile.h index d9866e3f8..261ac3796 100644 --- a/Common/ChunkFile.h +++ b/Common/ChunkFile.h @@ -261,7 +261,7 @@ public: case MODE_READ: x = (wchar_t*)*ptr; break; case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break; case MODE_MEASURE: break; - case MODE_VERIFY: _dbg_assert_msg_(COMMON, x == (wchar_t*)*ptr, "Savestate verification failure: \"%s\" != \"%s\" (at %p).\n", x.c_str(), (wchar_t*)*ptr, ptr); break; + case MODE_VERIFY: _dbg_assert_msg_(COMMON, x == (wchar_t*)*ptr, "Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n", x.c_str(), (wchar_t*)*ptr, ptr); break; } (*ptr) += stringLen; } diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index f4ff4da1a..0fd109331 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -143,7 +143,8 @@ void* AllocateAlignedMemory(size_t size,size_t alignment) // On Symbian, we will want to create an RChunk. ptr = malloc(size); #else - posix_memalign(&ptr, alignment, size); + if(posix_memalign(&ptr, alignment, size) != 0) + ptr = NULL; #endif #endif diff --git a/Common/StringUtil.cpp b/Common/StringUtil.cpp index ae0a09b0c..189b82e15 100644 --- a/Common/StringUtil.cpp +++ b/Common/StringUtil.cpp @@ -55,25 +55,30 @@ std::string StringFromFormat(const char* format, ...) { va_list args; char *buf = NULL; + std::string temp = ""; #ifdef _WIN32 int required = 0; va_start(args, format); required = _vscprintf(format, args); buf = new char[required + 1]; - vsnprintf(buf, required, format, args); + if(vsnprintf(buf, required, format, args) < 0) + buf[0] = '\0'; va_end(args); buf[required] = '\0'; - std::string temp = buf; + temp = buf; delete[] buf; #else va_start(args, format); - vasprintf(&buf, format, args); + if(vasprintf(&buf, format, args) < 0) + buf = NULL; va_end(args); - std::string temp = buf; - free(buf); + if(buf != NULL) { + temp = buf; + free(buf); + } #endif return temp; } diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index c2481ec71..a78049620 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -143,7 +143,10 @@ bool SymbolMap::LoadSymbolMap(const char *filename) while (!feof(f)) { char line[512],temp[256]; - fgets(line,511,f); + char *p = fgets(line,512,f); + if(p == NULL) + break; + if (strlen(line) < 4 || sscanf(line, "%s", temp) != 1) continue; diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index 00b539fc4..44ba6a200 100644 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -123,7 +123,7 @@ void PSPOskDialog::RenderKeyboard() else temp[0] = '_'; - PPGeDrawText(temp, previewLeftSide + (i * 16.0f), 40.0f, NULL, 0.5f, color); + PPGeDrawText(temp, previewLeftSide + (i * 16.0f), 40.0f, 0, 0.5f, color); } for (int row = 0; row < NUMKEYROWS; ++row) { @@ -134,10 +134,10 @@ void PSPOskDialog::RenderKeyboard() color = 0xFF7f7f7f; temp[0] = oskKeys[row][col]; - PPGeDrawText(temp, keyboardLeftSide + (25.0f * col), 70.0f + (25.0f * row), NULL, 0.6f, color); + PPGeDrawText(temp, keyboardLeftSide + (25.0f * col), 70.0f + (25.0f * row), 0, 0.6f, color); if (selectedRow == row && col == selectedExtra) - PPGeDrawText("_", keyboardLeftSide + (25.0f * col), 70.0f + (25.0f * row), NULL, 0.6f, 0xFFFFFFFF); + PPGeDrawText("_", keyboardLeftSide + (25.0f * col), 70.0f + (25.0f * row), 0, 0.6f, 0xFFFFFFFF); } } diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index 025e3427e..2af43646f 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -41,7 +41,9 @@ FileBlockDevice::~FileBlockDevice() bool FileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr) { fseek(f, blockNumber * GetBlockSize(), SEEK_SET); - fread(outPtr, 2048, 1, f); + if(fread(outPtr, 1, 2048, f) != 2048) + DEBUG_LOG(LOADER, "Could not read 2048 bytes from block"); + return true; } @@ -80,10 +82,10 @@ CISOFileBlockDevice::CISOFileBlockDevice(std::string _filename) f = fopen(_filename.c_str(), "rb"); CISO_H hdr; - fread(&hdr, 1, sizeof(CISO_H), f); - if (memcmp(hdr.magic, "CISO", 4) != 0) + size_t readSize = fread(&hdr, sizeof(CISO_H), 1, f); + if (readSize != 1 || memcmp(hdr.magic, "CISO", 4) != 0) { - //ARGH! + WARN_LOG(LOADER, "Invalid CSO!"); } else { @@ -109,7 +111,8 @@ CISOFileBlockDevice::CISOFileBlockDevice(std::string _filename) int indexSize = numBlocks + 1; index = new u32[indexSize]; - fread(index, 4, indexSize, f); + if(fread(index, sizeof(u32), indexSize, f) != indexSize) + memset(index, 0, indexSize * sizeof(u32)); } CISOFileBlockDevice::~CISOFileBlockDevice() @@ -134,12 +137,12 @@ bool CISOFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr) u32 compressedReadSize = idx2 - idx; fseek(f, compressedReadPos, SEEK_SET); - fread(inbuffer, compressedReadSize, 1, f); + size_t readSize = fread(inbuffer, 1, compressedReadSize, f); if (plain) { memset(outPtr, 0, 2048); - memcpy(outPtr, inbuffer, compressedReadSize); + memcpy(outPtr, inbuffer, readSize); } else { @@ -152,7 +155,7 @@ bool CISOFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr) ERROR_LOG(LOADER, "deflateInit ERROR : %s\n", (z.msg) ? z.msg : "???"); return 1; } - z.avail_in = compressedReadSize; + z.avail_in = readSize; z.next_out = outPtr; z.avail_out = blockSize; z.next_in = inbuffer; diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index ec6e7241d..8084bec4f 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -313,7 +313,7 @@ u32 scePsmfGetNumberOfStreams(u32 psmfStruct) ERROR_LOG(HLE, "scePsmfGetNumberOfStreams - invalid psmf"); return ERROR_PSMF_NOT_FOUND; } - INFO_LOG(HLE, "%i=scePsmfGetNumberOfStreams(%08x)", psmf->getNumStreams(), psmf); + INFO_LOG(HLE, "%i=scePsmfGetNumberOfStreams(%p)", psmf->getNumStreams(), psmf); return psmf->getNumStreams(); } diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 684890226..c51da638a 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -38,8 +38,12 @@ EmuFileType Identify_File(const char *filename) return FILETYPE_ERROR; } u32 id; - fread(&id,4,1,f); + size_t readSize = fread(&id,4,1,f); fclose(f); + + if(readSize != 1) + return FILETYPE_ERROR; + if (id == 'FLE\x7F') { if (strstr(filename,".plf") || strstr(filename,"BOOT.BIN") || strstr(filename,".elf") || strstr(filename,".prx") ) diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index b05f70ed8..50889b99d 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -351,7 +351,8 @@ namespace MIPSAnalyst { FILE *file = fopen(filename,"wb"); u32 num = 0; - fwrite(&num,4,1,file); //fill in later + if(fwrite(&num,4,1,file) != 1) //fill in later + WARN_LOG(CPU, "Could not store hash map %s", filename); for (vector::iterator iter = functions.begin(); iter!=functions.end(); iter++) { @@ -363,12 +364,16 @@ namespace MIPSAnalyst strcpy(temp.name, f.name); temp.hash=f.hash; temp.size=f.size; - fwrite((char*)&temp,sizeof(temp),1,file); + if(fwrite((char*)&temp,sizeof(temp),1,file) != 1) { + WARN_LOG(CPU, "Could not store hash map %s", filename); + break; + } num++; } } fseek(file,0,SEEK_SET); - fwrite(&num,4,1,file); //fill in later + if(fwrite(&num,4,1,file) != 1) //fill in later + WARN_LOG(CPU, "Could not store hash map %s", filename); fclose(file); } @@ -380,25 +385,26 @@ namespace MIPSAnalyst FILE *file = fopen(filename, "rb"); int num; - fread(&num,4,1,file); - for (int i=0; i::iterator iter = hashToFunction.find(temp.hash); - if (iter != hashToFunction.end()) + if(fread(&num,4,1,file) == 1) { + for (int i=0; isecond); - if (f.size==temp.size) - { - strcpy(f.name, temp.name); - f.hash=temp.hash; - f.size=temp.size; + HashMapFunc temp; + if(fread(&temp,sizeof(temp),1,file) == 1) { + map::iterator iter = hashToFunction.find(temp.hash); + if (iter != hashToFunction.end()) + { + //yay, found a function! + Function &f = *(iter->second); + if (f.size==temp.size) + { + strcpy(f.name, temp.name); + f.hash=temp.hash; + f.size=temp.size; + } + } } } } - fclose(file); } void CompileLeafs() diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index f6b4bdc3e..5f25caaca 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -925,7 +925,7 @@ void MIPSInterpret(u32 op) //only for those rare ones // Try to disassemble it char disasm[256]; MIPSDisAsm(op, currentMIPS->pc, disasm); - _dbg_assert_msg_(CPU, 0, disasm); + _dbg_assert_msg_(CPU, 0, "%s", disasm); currentMIPS->pc += 4; } }