Merge pull request #814 from PCSX2/coverity-qa-high

Fix a bunches of coverity warning/errors.
This commit is contained in:
Gregory Hainaut 2015-09-20 22:18:03 +02:00
commit b60dd9d1fe
25 changed files with 83 additions and 42 deletions

View File

@ -22,6 +22,7 @@ cleanBuild=0
useClang=0 useClang=0
# 0 => no, 1 => yes, 2 => force yes # 0 => no, 1 => yes, 2 => force yes
useCross=2 useCross=2
CoverityBuild=0
for ARG in "$@"; do for ARG in "$@"; do
case "$ARG" in case "$ARG" in
@ -41,6 +42,7 @@ for ARG in "$@"; do
--no-simd ) flags+=(-DDISABLE_ADVANCE_SIMD=TRUE) ;; --no-simd ) flags+=(-DDISABLE_ADVANCE_SIMD=TRUE) ;;
--cross-multilib ) flags+=(-DCMAKE_TOOLCHAIN_FILE=cmake/linux-compiler-i386-multilib.cmake); useCross=1; ;; --cross-multilib ) flags+=(-DCMAKE_TOOLCHAIN_FILE=cmake/linux-compiler-i386-multilib.cmake); useCross=1; ;;
--no-cross-multilib ) useCross=0; ;; --no-cross-multilib ) useCross=0; ;;
--coverity ) CoverityBuild=1; cleanBuild=1; ;;
-D* ) flags+=($ARG) ;; -D* ) flags+=($ARG) ;;
*) *)
@ -66,6 +68,7 @@ for ARG in "$@"; do
echo "--no-cross-multilib: Build a native PCSX2" echo "--no-cross-multilib: Build a native PCSX2"
echo "--clang : Build with Clang/llvm" echo "--clang : Build with Clang/llvm"
echo "--asan : Enable Address sanitizer" echo "--asan : Enable Address sanitizer"
echo "--coverity : Do a build for coverity (require the tool)"
exit 1 exit 1
esac esac
@ -74,6 +77,8 @@ done
root=$PWD/$(dirname "$0") root=$PWD/$(dirname "$0")
log=$root/install_log.txt log=$root/install_log.txt
build=$root/build build=$root/build
coverity_dir=cov-int
coverity_result=pcsx2-coverity.xz
if [[ "$cleanBuild" -eq 1 ]]; then if [[ "$cleanBuild" -eq 1 ]]; then
echo "Doing a clean build." echo "Doing a clean build."
@ -116,7 +121,13 @@ else
ncpu=$(grep -w -c processor /proc/cpuinfo) ncpu=$(grep -w -c processor /proc/cpuinfo)
fi fi
make -j"$ncpu" 2>&1 | tee -a $log if [[ "$CoverityBuild" -eq 1 ]]; then
make install 2>&1 | tee -a $log cov-build --dir $coverity_dir make -j"$ncpu" 2>&1 | tee -a $log
# Warning: $coverity_dir must be the root directory
(cd $build; tar caf $coverity_result $coverity_dir)
else
make -j"$ncpu" 2>&1 | tee -a $log
make install 2>&1 | tee -a $log
fi
exit 0 exit 0

View File

@ -182,7 +182,7 @@ void x86capabilities::CountCores()
static const char* tbl_x86vendors[] = static const char* tbl_x86vendors[] =
{ {
"GenuineIntel", "GenuineIntel",
"AuthenticAMD" "AuthenticAMD",
"Unknown ", "Unknown ",
}; };

View File

@ -1767,7 +1767,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvdGetMechaVer(&cdvd.Result[1]); cdvdGetMechaVer(&cdvd.Result[1]);
cdvdReadRegionParams(&cdvd.Result[3]);//size==8 cdvdReadRegionParams(&cdvd.Result[3]);//size==8
DevCon.WriteLn("REGION PARAMS = %s %s", mg_zones[cdvd.Result[1]], &cdvd.Result[3]); DevCon.WriteLn("REGION PARAMS = %s %s", mg_zones[cdvd.Result[1] & 7], &cdvd.Result[3]);
cdvd.Result[1] = 1 << cdvd.Result[1]; //encryption zone; see offset 0x1C in encrypted headers cdvd.Result[1] = 1 << cdvd.Result[1]; //encryption zone; see offset 0x1C in encrypted headers
////////////////////////////////////////// //////////////////////////////////////////
cdvd.Result[2] = 0; //?? cdvd.Result[2] = 0; //??

View File

@ -244,7 +244,7 @@ int CsoFileReader::ReadFromFrame(u8 *dest, u64 pos, int maxBytes) {
// Calculate where the compressed payload is (if compressed.) // Calculate where the compressed payload is (if compressed.)
const u64 frameRawPos = (u64)index0 << m_indexShift; const u64 frameRawPos = (u64)index0 << m_indexShift;
const u64 frameRawSize = (index1 - index0) << m_indexShift; const u64 frameRawSize = (u64)(index1 - index0) << m_indexShift;
if (!compressed) { if (!compressed) {
// Just read directly, easy. // Just read directly, easy.

View File

@ -63,7 +63,7 @@ static Access* ReadIndexFromFile(const wxString& filename) {
infile.read((char*)index, sizeof(Access)); infile.read((char*)index, sizeof(Access));
s64 datasize = size - GZIP_ID_LEN - sizeof(Access); s64 datasize = size - GZIP_ID_LEN - sizeof(Access);
if (datasize != index->have * sizeof(Point)) { if (datasize != (s64)index->have * sizeof(Point)) {
Console.Error(L"Error: unexpected size of gzip index, please delete it manually: '%s'.", WX_STR(filename)); Console.Error(L"Error: unexpected size of gzip index, please delete it manually: '%s'.", WX_STR(filename));
infile.close(); infile.close();
free(index); free(index);
@ -316,6 +316,7 @@ bool GzippedFileReader::OkIndex() {
WriteIndexToFile((Access*)m_pIndex, indexfile); WriteIndexToFile((Access*)m_pIndex, indexfile);
} else { } else {
Console.Error(L"ERROR (%d): index could not be generated for file '%s'", len, WX_STR(m_filename)); Console.Error(L"ERROR (%d): index could not be generated for file '%s'", len, WX_STR(m_filename));
free_index(index);
InitZstates(); InitZstates();
return false; return false;
} }

View File

@ -90,7 +90,8 @@ void InputIsoFile::BeginRead2(uint lsn)
int InputIsoFile::FinishRead3(u8* dst, uint mode) int InputIsoFile::FinishRead3(u8* dst, uint mode)
{ {
int _offset, length; int _offset = 0;
int length = 0;
int ret = 0; int ret = 0;
if(m_current_lsn < 0) if(m_current_lsn < 0)

View File

@ -209,9 +209,10 @@ u32 IsoDirectory::GetFileSize( const wxString& filePath ) const
IsoFileDescriptor::IsoFileDescriptor() IsoFileDescriptor::IsoFileDescriptor()
{ {
lba = 0; lba = 0;
size = 0; size = 0;
flags = 0; flags = 0;
memset(&date, 0, sizeof(date));
} }
IsoFileDescriptor::IsoFileDescriptor(const u8* data, int length) IsoFileDescriptor::IsoFileDescriptor(const u8* data, int length)

View File

@ -303,6 +303,11 @@ local int build_index(FILE *in, PX_off_t span, struct access **built)
} }
} while (ret != Z_STREAM_END); } while (ret != Z_STREAM_END);
if (index == NULL) {
// Could happen if the start of the stream in Z_STREAM_END
return 0;
}
/* clean up and return index (release unused entries in list) */ /* clean up and return index (release unused entries in list) */
(void)inflateEnd(&strm); (void)inflateEnd(&strm);
index->list = (Point*)realloc(index->list, sizeof(struct point) * index->have); index->list = (Point*)realloc(index->list, sizeof(struct point) * index->have);

View File

@ -509,7 +509,7 @@ void MTC0()
} }
int CPCOND0() { int CPCOND0() {
return ((dmacRegs.stat.CIS | ~dmacRegs.pcr.CPC) == 0x3ff); return (((dmacRegs.stat.CIS | ~dmacRegs.pcr.CPC) & 0x3FF) == 0x3ff);
} }
//#define CPCOND0 1 //#define CPCOND0 1

View File

@ -28,7 +28,8 @@ namespace R3000A
"r0", "at", "v0", "v1", "a0", "a1","a2", "a3", "r0", "at", "v0", "v1", "a0", "a1","a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5","t6", "t7", "t0", "t1", "t2", "t3", "t4", "t5","t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5","s6", "s7", "s0", "s1", "s2", "s3", "s4", "s5","s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp","fp", "ra"}; "t8", "t9", "k0", "k1", "gp", "sp","fp", "ra"
"HI", "LO" };
const char * const disRNameCP0[] = { const char * const disRNameCP0[] = {
"Index" , "Random" , "EntryLo0", "EntryLo1", "Context" , "PageMask" , "Wired" , "*Check me*", "Index" , "Random" , "EntryLo0", "EntryLo1", "Context" , "PageMask" , "Wired" , "*Check me*",

View File

@ -869,6 +869,9 @@ void disMemAccess( std::string& output, const char* name, int cop = 0)
case 2: case 2:
rt = COP2_REG_FP[DECODE_FT]; rt = COP2_REG_FP[DECODE_FT];
break; break;
default:
rt = "???";
break;
} }
const char* rs = GPR_REG[DECODE_RS]; const char* rs = GPR_REG[DECODE_RS];

View File

@ -444,8 +444,10 @@ void DisassemblyFunction::generateBranchLines()
}; };
LaneInfo lanes[NUM_LANES]; LaneInfo lanes[NUM_LANES];
for (int i = 0; i < NUM_LANES; i++) for (int i = 0; i < NUM_LANES; i++) {
lanes[i].used = false; lanes[i].used = false;
lanes[i].end = 0;
}
u32 end = address+size; u32 end = address+size;
@ -643,6 +645,7 @@ void DisassemblyFunction::load()
macro = new DisassemblyMacro(cpu,opAddress); macro = new DisassemblyMacro(cpu,opAddress);
macro->setMacroMemory("sh",immediate,rt,2); macro->setMacroMemory("sh",immediate,rt,2);
funcPos += 4; funcPos += 4;
break;
case 0x2B: // sw case 0x2B: // sw
macro = new DisassemblyMacro(cpu,opAddress); macro = new DisassemblyMacro(cpu,opAddress);
macro->setMacroMemory("sw",immediate,rt,4); macro->setMacroMemory("sw",immediate,rt,4);
@ -989,6 +992,8 @@ void DisassemblyData::createLines()
} }
break; break;
default: default:
// Avoid a call to strlen with random data
buffer[0] = 0;
break; break;
} }

View File

@ -413,8 +413,8 @@ bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs,
size_t num = 0; size_t num = 0;
u64 opcode; u64 opcode;
std::vector<u64> valueStack; std::vector<u64> valueStack;
u64 arg[5]; u64 arg[5] = {0};
float fArg[5]; float fArg[5] = {0};
bool useFloat = false; bool useFloat = false;
while (num < exp.size()) while (num < exp.size())

View File

@ -241,6 +241,7 @@ void SymbolMap::AddModule(const char *name, u32 address, u32 size) {
ModuleEntry mod; ModuleEntry mod;
strncpy(mod.name, name, ARRAY_SIZE(mod.name)); strncpy(mod.name, name, ARRAY_SIZE(mod.name));
mod.name[ARRAY_SIZE(mod.name) - 1] = 0;
mod.start = address; mod.start = address;
mod.size = size; mod.size = size;
mod.index = (int)modules.size() + 1; mod.index = (int)modules.size() + 1;

View File

@ -156,7 +156,7 @@ void sio2_serialIn(u8 value){
if (sio2.cmdlength) sio2.cmdlength--; if (sio2.cmdlength) sio2.cmdlength--;
sioWrite8(value); sioWrite8(value);
if (sio2.packet.sendSize > BUFSIZE) {//asadr if (sio2.packet.sendSize >= BUFSIZE) {//asadr
Console.Warning("*PCSX2*: sendSize >= %d", BUFSIZE); Console.Warning("*PCSX2*: sendSize >= %d", BUFSIZE);
} else { } else {
sio2.buf[sio2.packet.sendSize] = sioRead8(); sio2.buf[sio2.packet.sendSize] = sioRead8();
@ -183,7 +183,7 @@ void sio2_fifoIn(u8 value){
if (sio2.cmdlength) sio2.cmdlength--; if (sio2.cmdlength) sio2.cmdlength--;
SIODMAWrite(value); SIODMAWrite(value);
if (sio2.packet.sendSize > BUFSIZE) {//asadr if (sio2.packet.sendSize >= BUFSIZE) {//asadr
Console.WriteLn("*PCSX2*: sendSize >= %d", BUFSIZE); Console.WriteLn("*PCSX2*: sendSize >= %d", BUFSIZE);
} else { } else {
sio2.buf[sio2.packet.sendSize] = sioRead8(); sio2.buf[sio2.packet.sendSize] = sioRead8();

View File

@ -298,7 +298,8 @@ protected:
volatile u32 m_mcdOpen; volatile u32 m_mcdOpen;
public: // hack until we unsuck plugins... public: // hack until we unsuck plugins...
ScopedPtr<PluginStatus_t> m_info[PluginId_Count]; // +1 to avoid out-of-bounds due to PluginId_Mcd which is above PluginId_Count
ScopedPtr<PluginStatus_t> m_info[PluginId_Count + 1];
public: public:
SysCorePlugins(); SysCorePlugins();

View File

@ -176,19 +176,21 @@ static __ri void __fastcall _vuFMACAdd(VURegs * VU, int reg, int xyzw) {
if (VU->fmac[i].enable == 1) continue; if (VU->fmac[i].enable == 1) continue;
break; break;
} }
//if (i==8) Console.Error("*PCSX2*: error , out of fmacs %d", VU->cycle);
if (i < 8) {
VUM_LOG("adding FMAC pipe[%d]; xyzw=%x", i, xyzw);
VUM_LOG("adding FMAC pipe[%d]; xyzw=%x", i, xyzw); VU->fmac[i].enable = 1;
VU->fmac[i].sCycle = VU->cycle;
VU->fmac[i].enable = 1; VU->fmac[i].Cycle = 3;
VU->fmac[i].sCycle = VU->cycle; VU->fmac[i].reg = reg;
VU->fmac[i].Cycle = 3; VU->fmac[i].xyzw = xyzw;
VU->fmac[i].reg = reg; VU->fmac[i].macflag = VU->macflag;
VU->fmac[i].xyzw = xyzw; VU->fmac[i].statusflag = VU->statusflag;
VU->fmac[i].macflag = VU->macflag; VU->fmac[i].clipflag = VU->clipflag;
VU->fmac[i].statusflag = VU->statusflag; } else {
VU->fmac[i].clipflag = VU->clipflag; //Console.Error("*PCSX2*: error , out of fmacs %d", VU->cycle);
}
} }
static __ri void __fastcall _vuFDIVAdd(VURegs * VU, int cycles) { static __ri void __fastcall _vuFDIVAdd(VURegs * VU, int cycles) {

View File

@ -948,7 +948,10 @@ void ConsoleLogFrame::DoFlushEvent( bool isPending )
} while( --m_WaitingThreadsForFlush > 0 ); } while( --m_WaitingThreadsForFlush > 0 );
int count = m_sem_QueueFlushed.Count(); int count = m_sem_QueueFlushed.Count();
while( count < 0 ) m_sem_QueueFlushed.Post(); while( count < 0 ) {
m_sem_QueueFlushed.Post();
count = m_sem_QueueFlushed.Count();
}
} }
m_pendingFlushMsg = isPending; m_pendingFlushMsg = isPending;

View File

@ -73,7 +73,7 @@ public:
} }
BaseBlockArray (s32 size) : _Reserved(0), BaseBlockArray (s32 size) : _Reserved(0),
_Size(0) _Size(0), blocks(NULL)
{ {
if(size > 0) { if(size > 0) {
resize(size); resize(size);

View File

@ -710,7 +710,7 @@ static void recResetRaw()
maxrecmem = 0; maxrecmem = 0;
memset(recConstBuf, 0, RECCONSTBUF_SIZE * sizeof(recConstBuf)); memset(recConstBuf, 0, RECCONSTBUF_SIZE * sizeof(*recConstBuf));
if( s_pInstCache ) if( s_pInstCache )
memset( s_pInstCache, 0, sizeof(EEINST)*s_nInstCacheSize ); memset( s_pInstCache, 0, sizeof(EEINST)*s_nInstCacheSize );

View File

@ -1670,6 +1670,8 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
sleep(1); sleep(1);
} else { } else {
unsigned long end = timeGetTime(); unsigned long end = timeGetTime();
frame_number = std::max(1ul, frame_number); // avoid a potential division by 0
fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start); fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start);
fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number); fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number);

View File

@ -81,7 +81,8 @@ void GSRendererHW::SetScaling() {
} }
printf("Frame buffer size set to %dx%d (%dx%d)\n", (m_width / m_upscale_multiplier), (m_height / m_upscale_multiplier), m_width, m_height); if (m_upscale_multiplier)
printf("Frame buffer size set to %dx%d (%dx%d)\n", (m_width / m_upscale_multiplier), (m_height / m_upscale_multiplier), m_width, m_height);
} }
GSRendererHW::~GSRendererHW() GSRendererHW::~GSRendererHW()
@ -464,7 +465,8 @@ void GSRendererHW::Draw()
{ {
s = format("%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM); s = format("%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM);
ds_tex->Save(root_hw+s); if (ds_tex)
ds_tex->Save(root_hw+s);
} }
s_n++; s_n++;

View File

@ -5250,7 +5250,7 @@ bool GSC_UrbanReign(const GSFrameInfo& fi, int& skip)
{ {
if(skip == 0) if(skip == 0)
{ {
if(fi.TME && fi.FBP==0x0000 && fi.TBP0==0x3980 && fi.FPSM==fi.TPSM && fi.TPSM == PSM_PSMCT32 && fi.TPSM ==0 && fi.FBMSK == 0x0) if(fi.TME && fi.FBP==0x0000 && fi.TBP0==0x3980 && fi.FPSM==fi.TPSM && fi.TPSM == PSM_PSMCT32 && fi.FBMSK == 0x0)
{ {
skip = 1; skip = 1;
} }

View File

@ -74,7 +74,7 @@ static inline int wcsicmp(const wchar_t* w1, const wchar_t* w2) {
static inline unsigned int timeGetTime() { static inline unsigned int timeGetTime() {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
uint64_t ms = (now.tv_usec/1000) + (now.tv_sec * 1000); uint64_t ms = (now.tv_usec/1000) + ((uint64_t)now.tv_sec * 1000);
return (ms & 0xFFFFFFFF); // MS code is u32 ... return (ms & 0xFFFFFFFF); // MS code is u32 ...
} }

View File

@ -171,15 +171,15 @@ void LoadConfig()
} }
u32 value; u32 value;
if (fscanf(f, "log = %d\n", &value) == 0) return; if (fscanf(f, "log = %d\n", &value) == 0) goto error;
conf->log = value; conf->log = value;
if (fscanf(f, "options = %d\n", &value) == 0) return; if (fscanf(f, "options = %d\n", &value) == 0) goto error;
conf->options = value; conf->options = value;
if (fscanf(f, "mouse_sensibility = %d\n", &value) == 0) return; if (fscanf(f, "mouse_sensibility = %d\n", &value) == 0) goto error;
conf->sensibility = value; conf->sensibility = value;
if (fscanf(f, "joy_pad_map = %d\n", &value) == 0) return; if (fscanf(f, "joy_pad_map = %d\n", &value) == 0) goto error;
conf->joyid_map = value; conf->joyid_map = value;
if (fscanf(f, "ff_intensity = %d\n", &value) == 0) return; if (fscanf(f, "ff_intensity = %d\n", &value) == 0) goto error;
conf->ff_intensity = value; conf->ff_intensity = value;
for (int pad = 0; pad < 2; pad++) for (int pad = 0; pad < 2; pad++)
@ -199,11 +199,13 @@ void LoadConfig()
u32 keysym; u32 keysym;
u32 index; u32 index;
while( fscanf(f, "PAD %d:KEYSYM 0x%x = %d\n", &pad, &keysym, &index) != EOF ) { while( fscanf(f, "PAD %d:KEYSYM 0x%x = %d\n", &pad, &keysym, &index) != EOF ) {
set_keyboad_key(pad, keysym, index); set_keyboad_key(pad & 1, keysym, index);
if(pad == 0) have_user_setting = true; if(pad == 0) have_user_setting = true;
} }
if (!have_user_setting) DefaultKeyboardValues();
error:
fclose(f); fclose(f);
if (!have_user_setting) DefaultKeyboardValues();
} }