Fix some possible problems from cppcheck. Everything else looks fine.

This commit is contained in:
Brandon Wright 2016-09-27 15:25:37 -05:00
parent f388facb31
commit 026f9eaa1e
19 changed files with 82 additions and 72 deletions

View File

@ -746,7 +746,6 @@ void S9xAPULoadBlarggState(uint8 *oldblock)
spc::reference_time = SNES::get_le32(ptr);
ptr += sizeof(int32);
spc::remainder = SNES::get_le32(ptr);
ptr += sizeof(int32);
// blargg stores CPUIx in regs_in
memcpy (SNES::cpu.registers, regs_in + 4, 4);
@ -766,8 +765,12 @@ bool8 S9xSPCDump (const char *filename)
SNES::smp.save_spc (buf);
if ((ignore = fwrite(buf, SPC_FILE_SIZE, 1, fs)) <= 0)
ignore = fwrite (buf, SPC_FILE_SIZE, 1, fs);
if (ignore == 0)
{
fprintf (stderr, "Couldn't write file %s.\n", filename);
}
fclose(fs);

View File

@ -33,19 +33,19 @@ class Resampler : public ring_buffer
}
inline int
space_empty (void)
space_empty (void) const
{
return buffer_size - size;
}
inline int
space_filled (void)
space_filled (void) const
{
return size;
}
inline int
max_write (void)
max_write (void) const
{
return space_empty () >> 1;
}

View File

@ -69,13 +69,13 @@ public:
}
inline int
space_empty (void)
space_empty (void) const
{
return buffer_size - size;
}
inline int
space_filled (void)
space_filled (void) const
{
return size;
}
@ -96,7 +96,7 @@ public:
buffer = new unsigned char[buffer_size];
memset (buffer, 0, this->buffer_size);
size = 0;
this->size = 0;
start = 0;
}

View File

@ -358,12 +358,10 @@ static void BSX_Map_MMC (void)
static void BSX_Map_FlashIO (void)
{
int c;
if (BSX.MMC[0x0C] || BSX.MMC[0x0D])
{
// Bank C0:0000, 2AAA, 5555, FF00-FF1F
for (c = 0; c < 16; c++)
for (int c = 0; c < 16; c++)
{
Map[c + 0xC00] = (uint8 *) MAP_BSX;
BlockIsRAM[c + 0xC00] = TRUE;
@ -833,7 +831,7 @@ uint8 S9xGetBSXPPU (uint16 address)
// Data register? (r/w)
case 0x2192:
t = BSX.PPU[0x2192 - BSXPPUBASE];
// t = BSX.PPU[0x2192 - BSXPPUBASE];
// test
t = BSX.test2192[BSX.out_index++];

1
c4.cpp
View File

@ -295,7 +295,6 @@ void C4Op1F (void)
{
tanval = (double) C41FYVal / C41FXVal;
C41FAngleRes = (int16) (atan(tanval) / (C4_PI * 2) * 512);
C41FAngleRes = C41FAngleRes;
if (C41FXVal< 0)
C41FAngleRes += 0x100;
C41FAngleRes &= 0x1FF;

View File

@ -392,7 +392,7 @@ bool ConfigFile::SaveTo(const char *filename){
if(ferror(fp))
{
fp = fp;
printf ("Error writing config file %s\n", filename);
}
fclose(fp);

View File

@ -2051,7 +2051,6 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2)
{
uint16 r, s, t, st;
s = t = st = 0;
r = cmd.button.joypad.buttons;
st = r & joypad[cmd.button.joypad.idx].togglestick & joypad[cmd.button.joypad.idx].toggleturbo;
r ^= st;

View File

@ -1140,7 +1140,7 @@ static void DSP3_OP10 (void)
DSP3_Reset();
else
// absorb 2 bytes
DSP3.DR = DSP3.DR;
DSP3.DR = DSP3.DR; // FIXME?
}
/*

View File

@ -893,7 +893,7 @@ static void fx_plot_2bit (void)
#endif
if (GSU.vPlotOptionReg & 0x02)
c = (x ^ y) & 1 ? (uint8) (GSU.vColorReg >> 4) : (uint8) GSU.vColorReg;
c = ((x ^ y) & 1) ? (uint8) (GSU.vColorReg >> 4) : (uint8) GSU.vColorReg;
else
c = (uint8) GSU.vColorReg;
@ -957,7 +957,7 @@ static void fx_plot_4bit (void)
#endif
if (GSU.vPlotOptionReg & 0x02)
c = (x ^ y) & 1 ? (uint8) (GSU.vColorReg >> 4) : (uint8) GSU.vColorReg;
c = ((x ^ y) & 1) ? (uint8) (GSU.vColorReg >> 4) : (uint8) GSU.vColorReg;
else
c = (uint8) GSU.vColorReg;

View File

@ -873,8 +873,7 @@ inline void S9xSetPCBase (uint32 Address)
Registers.PBPC = Address & 0xffffff;
ICPU.ShiftedPB = Address & 0xff0000;
int block;
uint8 *GetAddress = Memory.Map[block = ((Address & 0xffffff) >> MEMMAP_SHIFT)];
uint8 *GetAddress = Memory.Map[(int)((Address & 0xffffff) >> MEMMAP_SHIFT)];
CPU.MemSpeed = memory_speed(Address);
CPU.MemSpeedx2 = CPU.MemSpeed << 1;

View File

@ -7,7 +7,7 @@ if test -z "$CXXFLAGS"; then
CXXFLAGS="$CFLAGS"
fi
EXTRA_FLAGS="-Wall -W -pedantic -Wno-unused-parameter"
EXTRA_FLAGS="-Wall -W -pedantic -Wno-unused-parameter -Wno-unused-but-set-variable"
CFLAGS="$CFLAGS $EXTRA_FLAGS"
CXXFLAGS="$CXXFLAGS $EXTRA_FLAGS"

View File

@ -154,9 +154,9 @@ Binding::get_axis (void)
GdkModifierType
Binding::get_gdk_modifiers (void)
{
return (GdkModifierType) ((BINDING_CTRL & value ? GDK_CONTROL_MASK : 0) |
(BINDING_ALT & value ? GDK_MOD1_MASK : 0) |
(BINDING_SHIFT & value ? GDK_SHIFT_MASK : 0));
return (GdkModifierType) (((BINDING_CTRL & value) ? GDK_CONTROL_MASK : 0) |
((BINDING_ALT & value) ? GDK_MOD1_MASK : 0) |
((BINDING_SHIFT & value) ? GDK_SHIFT_MASK : 0));
}
bool
@ -192,9 +192,10 @@ Binding::to_string (char *str)
else
{
memset (buf, 0, 256);
strncpy (buf,
keyval_name,
256);
255);
}
while ((c = strstr (buf, "_")))
@ -203,9 +204,9 @@ Binding::to_string (char *str)
}
sprintf (str, _("Keyboard %s%s%s%s"),
value & BINDING_SHIFT ? "Shift+" : "",
value & BINDING_CTRL ? "Ctrl+" : "",
value & BINDING_ALT ? "Alt+" : "",
(value & BINDING_SHIFT) ? "Shift+" : "",
(value & BINDING_CTRL) ? "Ctrl+" : "",
(value & BINDING_ALT) ? "Alt+" : "",
buf);
}
@ -213,14 +214,14 @@ Binding::to_string (char *str)
{
if ((get_key ()) >= 512)
sprintf (buf,
_("Axis #%d %s %d%%"),
_("Axis #%u %s %u%%"),
get_axis (),
is_positive () ? "+" : "-",
get_threshold ());
else
sprintf (buf, _("Button %d"), get_key ());
sprintf (buf, _("Button %u"), get_key ());
sprintf (str, _("Joystick %d %s"), get_device (), buf);
sprintf (str, _("Joystick %u %s"), get_device (), buf);
}
else

View File

@ -314,7 +314,7 @@ S9xXVDisplayDriver::init (void)
{
if (!strcmp (port_attr[i].name, "XV_AUTOPAINT_COLORKEY"))
{
Atom colorkey = None;
Atom colorkey;
colorkey = XInternAtom (display, "XV_AUTOPAINT_COLORKEY", True);
if (colorkey != None)

View File

@ -71,10 +71,12 @@ S9xAlsaSoundDriver::open_device (void)
printf ("ALSA sound driver initializing...\n");
printf (" --> (Device: default)...");
if ((err = snd_pcm_open (&pcm,
"default",
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK) < 0))
err = snd_pcm_open (&pcm,
"default",
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK);
if (err < 0)
{
goto fail;
}

View File

@ -53,5 +53,8 @@ main (int argc,
fprintf (outfile, "\n};\n");
fclose (infile);
fclose (outfile);
return 0;
}

View File

@ -822,7 +822,10 @@ int S9xMovieOpen (const char *filename, bool8 read_only)
}
if (fseek(fd, Movie.ControllerDataOffset, SEEK_SET))
{
fclose(fd);
return (WRONG_FORMAT);
}
Movie.File = fd;
Movie.BytesPerSample = bytes_per_sample();
@ -970,7 +973,10 @@ int S9xMovieGetInfo (const char *filename, struct MovieInfo *info)
result = read_movie_header(fd, &local_movie);
if (result != SUCCESS)
{
fclose(fd);
return (result);
}
info->TimeCreated = (time_t) local_movie.MovieId;
info->Version = local_movie.Version;

View File

@ -386,10 +386,10 @@ on the remote machine on this port?");
{
S9xNPSetError ("Sending 'HELLO' message failed.");
S9xNPDisconnect ();
delete tmp;
delete[] tmp;
return (FALSE);
}
delete tmp;
delete[] tmp;
#ifdef NP_DEBUG
printf ("CLIENT: Waiting for 'WELCOME' reply from server @%ld...\n", S9xGetMilliTime () - START);
@ -420,7 +420,7 @@ on the remote machine on this port?");
if (!S9xNPGetData (NetPlay.Socket, data, len - 7))
{
S9xNPSetError ("Error in 'HELLO' reply packet received from server.");
delete data;
delete[] data;
S9xNPDisconnect ();
return (FALSE);
}
@ -430,7 +430,7 @@ on the remote machine on this port?");
S9xNPSetError ("\
The Snes9X NetPlay server implements a different\n\
version of the protocol. Disconnecting.");
delete data;
delete[] data;
S9xNPDisconnect ();
return (FALSE);
}
@ -442,13 +442,13 @@ version of the protocol. Disconnecting.");
{
if (!S9xNPLoadROMDialog ((char *) data + 4 + 2))
{
delete data;
delete[] data;
S9xNPDisconnect ();
return (FALSE);
}
}
NetPlay.Player = data [1];
delete data;
delete[] data;
NetPlay.PendingWait4Sync = TRUE;
Settings.NetPlay = TRUE;
@ -754,7 +754,7 @@ bool8 S9xNPLoadROM (uint32 len)
if (!S9xNPGetData (NetPlay.Socket, data, len))
{
S9xNPSetError ("Error while receiving ROM name.");
delete data;
delete[] data;
S9xNPDisconnect ();
return (FALSE);
}
@ -763,11 +763,11 @@ bool8 S9xNPLoadROM (uint32 len)
if (!S9xNPLoadROMDialog ((char *) data))
{
S9xNPSetError ("Disconnected from NetPlay server because you are playing a different game!");
delete data;
delete[] data;
S9xNPDisconnect ();
return (FALSE);
}
delete data;
delete[] data;
return (TRUE);
}
@ -878,7 +878,7 @@ void S9xNPGetFreezeFile (uint32 len)
{
S9xNPSetError ("Error while receiving freeze file from server.");
S9xNPDisconnect ();
delete data;
delete[] data;
return;
}
S9xNPSetAction ("", TRUE);
@ -924,7 +924,7 @@ void S9xNPGetFreezeFile (uint32 len)
remove (fname);
} else
S9xNPSetError ("Unable to get name for temporary freeze file.");
delete data;
delete[] data;
}
uint32 S9xNPGetJoypad (int which1)

View File

@ -535,7 +535,7 @@ void S9xNPProcessClient (int c)
len = 7 + 1 + 1 + 4 + strlen (NPServer.ROMName) + 1;
delete data;
delete[] data;
ptr = data = new uint8 [len];
*ptr++ = NP_SERV_MAGIC;
*ptr++ = NPServer.Clients [c].SendSequenceNum++;
@ -563,7 +563,7 @@ void S9xNPProcessClient (int c)
S9xNPShutdownClient (c, TRUE);
return;
}
delete data;
delete[] data;
#ifdef NP_DEBUG
printf ("SERVER: Waiting for a response from the client @%ld...\n", S9xGetMilliTime () - START);
#endif
@ -1306,7 +1306,7 @@ void S9xNPSendROMLoadRequest (const char *filename)
}
}
}
delete data;
delete[] data;
}
void S9xNPSendSRAMToAllClients ()

View File

@ -701,7 +701,7 @@ static bool8 SetupXvideo()
{
if (!strcmp (port_attr[i].name, "XV_AUTOPAINT_COLORKEY"))
{
Atom colorkey = None;
Atom colorkey;
colorkey = XInternAtom (GUI.display, "XV_AUTOPAINT_COLORKEY", True);
if (colorkey != None)