From a42498b161c073203917e159d7800a3d4cb7820a Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 13 May 2018 20:17:02 -0500 Subject: [PATCH] Fix a bunch of warnings. --- controls.cpp | 6 +++--- dsp1.cpp | 6 +++--- filter/2xsai.cpp | 6 +----- gfx.cpp | 3 --- gtk/configure.ac | 2 +- gtk/src/gtk_control.cpp | 12 +++-------- gtk/src/gtk_display_driver_xv.h | 1 - gtk/src/gtk_file.cpp | 14 ++++++------- gtk/src/gtk_preferences.cpp | 11 ++++++---- gtk/src/gtk_s9xwindow.cpp | 6 +++--- jma/jma.cpp | 36 +++++++-------------------------- server.cpp | 8 +++++--- shaders/glsl.cpp | 8 +++++--- snapshot.cpp | 2 +- 14 files changed, 46 insertions(+), 75 deletions(-) diff --git a/controls.cpp b/controls.cpp index f61f970d..125416cd 100644 --- a/controls.cpp +++ b/controls.cpp @@ -2346,7 +2346,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2) if (S9xUnfreezeGame(filename)) { - sprintf(buf, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops"); + snprintf(buf, 256, "%s.%.*s loaded", def, _MAX_EXT - 1, "oops"); S9xSetInfoString (buf); } else @@ -2383,7 +2383,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2) if (S9xUnfreezeGame(filename)) { - sprintf(buf, "%s.%03d loaded", def, i - QuickLoad000); + snprintf(buf, 256, "%s.%03d loaded", def, i - QuickLoad000); S9xSetInfoString(buf); } else @@ -2410,7 +2410,7 @@ void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2) _splitpath(Memory.ROMFilename, drive, dir, def, ext); snprintf(filename, PATH_MAX + 1, "%s%s%s.%03d", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, i - QuickSave000); - sprintf(buf, "%s.%03d saved", def, i - QuickSave000); + snprintf(buf, 256, "%s.%03d saved", def, i - QuickSave000); S9xSetInfoString(buf); S9xFreezeGame(filename); diff --git a/dsp1.cpp b/dsp1.cpp index b9cb2e62..972523da 100644 --- a/dsp1.cpp +++ b/dsp1.cpp @@ -896,9 +896,9 @@ static void DSP1_Project (int16 X, int16 Y, int16 Z, int16 *H, int16 *V, int16 * Py = DSP1_ShiftR(Py, E - refE); Pz = DSP1_ShiftR(Pz, E3 - refE); - C11 =- (Px * DSP1.Nx >> 15); - C8 =- (Py * DSP1.Ny >> 15); - C9 =- (Pz * DSP1.Nz >> 15); + C11 = -(Px * DSP1.Nx >> 15); + C8 = -(Py * DSP1.Ny >> 15); + C9 = -(Pz * DSP1.Nz >> 15); C12 = C11 + C8 + C9; // this cannot overflow! aux4 = C12; // de-normalization with 32-bits arithmetic diff --git a/filter/2xsai.cpp b/filter/2xsai.cpp index 5b342148..d41b6cdf 100644 --- a/filter/2xsai.cpp +++ b/filter/2xsai.cpp @@ -293,13 +293,11 @@ void SuperEagle (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, for (int i = 0; i < width; i++) { uint32 color1, color2, color3, color4, color5, color6; - uint32 colorA0, colorA1, colorA2, colorA3, colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; + uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; uint32 product1a, product1b, product2a, product2b; - colorB0 = *(bP - nextline - 1); colorB1 = *(bP - nextline ); colorB2 = *(bP - nextline + 1); - colorB3 = *(bP - nextline + 2); color4 = *(bP - 1); color5 = *(bP ); @@ -311,10 +309,8 @@ void SuperEagle (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, color3 = *(bP + nextline + 1); colorS1 = *(bP + nextline + 2); - colorA0 = *(bP + nextline + nextline - 1); colorA1 = *(bP + nextline + nextline ); colorA2 = *(bP + nextline + nextline + 1); - colorA3 = *(bP + nextline + nextline + 2); if (color2 == color6 && color5 != color3) { diff --git a/gfx.cpp b/gfx.cpp index af563ce2..20564251 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -1511,7 +1511,6 @@ static void DrawBackgroundOffset (int bg, uint8 Zh, uint8 Zl, int VOffOff) int PixWidth = IPPU.DoubleWidthPixels ? 2 : 1; bool8 HiresInterlace = IPPU.Interlace && IPPU.DoubleWidthPixels; - void (*DrawTile) (uint32, uint32, uint32, uint32); void (*DrawClippedTile) (uint32, uint32, uint32, uint32, uint32, uint32); for (int clip = 0; clip < GFX.Clip[bg].Count; clip++) @@ -1520,12 +1519,10 @@ static void DrawBackgroundOffset (int bg, uint8 Zh, uint8 Zl, int VOffOff) if (BG.EnableMath && (GFX.Clip[bg].DrawMode[clip] & 2)) { - DrawTile = GFX.DrawTileMath; DrawClippedTile = GFX.DrawClippedTileMath; } else { - DrawTile = GFX.DrawTileNomath; DrawClippedTile = GFX.DrawClippedTileNomath; } diff --git a/gtk/configure.ac b/gtk/configure.ac index d9ee98af..d39f8bac 100644 --- a/gtk/configure.ac +++ b/gtk/configure.ac @@ -9,7 +9,7 @@ if test -z "$CXXFLAGS"; then CXXFLAGS="$CFLAGS" fi -EXTRA_FLAGS="-Wall -W -pedantic -Wno-unused-parameter" +EXTRA_FLAGS="-Wall -W -Wno-unused-parameter" CFLAGS="$CFLAGS $EXTRA_FLAGS" CXXFLAGS="$CXXFLAGS $EXTRA_FLAGS" diff --git a/gtk/src/gtk_control.cpp b/gtk/src/gtk_control.cpp index f9867261..f2a81065 100644 --- a/gtk/src/gtk_control.cpp +++ b/gtk/src/gtk_control.cpp @@ -172,15 +172,9 @@ swap_controllers_1_2 (void) { JoypadBinding interrim; - memcpy (&interrim, - &gui_config->pad[0], - sizeof (JoypadBinding)); - memcpy (&gui_config->pad[0], - &gui_config->pad[1], - sizeof (JoypadBinding)); - memcpy (&gui_config->pad[1], - &interrim, - sizeof (JoypadBinding)); + interrim = gui_config->pad[0]; + gui_config->pad[0] = gui_config->pad[1]; + gui_config->pad[1] = interrim; gui_config->rebind_keys (); diff --git a/gtk/src/gtk_display_driver_xv.h b/gtk/src/gtk_display_driver_xv.h index e2f4a8d7..0d7c47c0 100644 --- a/gtk/src/gtk_display_driver_xv.h +++ b/gtk/src/gtk_display_driver_xv.h @@ -36,7 +36,6 @@ class S9xXVDisplayDriver : public S9xDisplayDriver Display *display; Window xwindow; - GC xgc; Colormap xcolormap; XVisualInfo *vi; GdkWindow *gdk_window; diff --git a/gtk/src/gtk_file.cpp b/gtk/src/gtk_file.cpp index 78d0726a..d8c04ad4 100644 --- a/gtk/src/gtk_file.cpp +++ b/gtk/src/gtk_file.cpp @@ -4,7 +4,7 @@ #include "gtk_s9x.h" -static char buf[256]; +static char buf[PATH_MAX]; const char * S9xChooseMovieFilename (bool8 read_only) @@ -499,13 +499,13 @@ S9xQuickSaveSlot (int slot) _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (filename, "%s%s%s.%03d", + snprintf (filename, PATH_MAX, "%s%s%s.%03d", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, slot); if (S9xFreezeGame (filename)) { - sprintf (buf, "%s.%03d saved", def, slot); + snprintf (buf, PATH_MAX, "%s.%03d saved", def, slot); S9xSetInfoString (buf); } @@ -524,13 +524,13 @@ S9xQuickLoadSlot (int slot) _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (filename, "%s%s%s.%03d", + snprintf (filename, PATH_MAX, "%s%s%s.%03d", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, slot); if (S9xUnfreezeGame (filename)) { - sprintf (buf, "%s.%03d loaded", def, slot); + snprintf (buf, PATH_MAX, "%s.%03d loaded", def, slot); S9xSetInfoString (buf); } else @@ -539,13 +539,13 @@ S9xQuickLoadSlot (int slot) _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (filename, "%s%s%s.zs%c", + snprintf (filename, PATH_MAX, "%s%s%s.zs%c", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, digits[slot]); if (S9xUnfreezeGame (filename)) { - sprintf (buf, + snprintf (buf, PATH_MAX, "Loaded ZSNES freeze file %s.zs%c", def, digits [slot]); S9xSetInfoString (buf); diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index ea11827e..bf1557a7 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -1263,9 +1263,9 @@ Snes9xPreferences::swap_with (void) int source_joypad = get_combo ("control_combo"); int dest_joypad = get_combo ("joypad_to_swap_with"); - memcpy (&mediator, &pad[source_joypad], sizeof (JoypadBinding)); - memcpy (&pad[source_joypad], &pad[dest_joypad], sizeof (JoypadBinding)); - memcpy (&pad[dest_joypad], &mediator, sizeof (JoypadBinding)); + mediator = pad[source_joypad]; + pad[source_joypad] = pad[dest_joypad]; + pad[dest_joypad] = mediator; bindings_to_dialog (source_joypad); @@ -1277,7 +1277,10 @@ Snes9xPreferences::reset_current_joypad (void) { int joypad = get_combo ("control_combo"); - memset (&pad[joypad], 0, sizeof (JoypadBinding)); + for (unsigned int i = 0; i < NUM_JOYPAD_LINKS; i++) + { + pad[joypad].data[i].clear(); + } bindings_to_dialog (joypad); diff --git a/gtk/src/gtk_s9xwindow.cpp b/gtk/src/gtk_s9xwindow.cpp index ff7c5109..eb6d47d6 100644 --- a/gtk/src/gtk_s9xwindow.cpp +++ b/gtk/src/gtk_s9xwindow.cpp @@ -850,7 +850,7 @@ Snes9xWindow::open_movie_dialog (bool readonly) _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (default_name, "%s.smv", def); + snprintf (default_name, PATH_MAX, "%s.smv", def); dialog = gtk_file_chooser_dialog_new (_("New SNES Movie"), GTK_WINDOW (this->window), @@ -1116,7 +1116,7 @@ Snes9xWindow::save_state_dialog () _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (default_name, "%s.sst", def); + snprintf (default_name, PATH_MAX, "%s.sst", def); dialog = gtk_file_chooser_dialog_new (_("Save State"), GTK_WINDOW (this->window), @@ -1194,7 +1194,7 @@ Snes9xWindow::save_spc_dialog () _splitpath (Memory.ROMFilename, drive, dir, def, ext); - sprintf (default_name, "%s.spc", def); + snprintf (default_name, PATH_MAX, "%s.spc", def); dialog = gtk_file_chooser_dialog_new (_("Save SPC file..."), GTK_WINDOW (this->window), diff --git a/jma/jma.cpp b/jma/jma.cpp index e7ed9f21..9696be2a 100644 --- a/jma/jma.cpp +++ b/jma/jma.cpp @@ -284,16 +284,7 @@ namespace JMA stream.read((char *)int4_buffer, UINT_SIZE); size_t compressed_size = charp_to_uint(int4_buffer); - //Allocate memory of the correct size to hold the compressed data in the JMA - //Throw error on failure as that is unrecoverable from - try - { - compressed_buffer = new unsigned char[compressed_size]; - } - catch (bad_alloc xa) - { - throw(JMA_NO_MEM_ALLOC); - } + compressed_buffer = new unsigned char[compressed_size]; //Read all the compressed data in stream.read((char *)compressed_buffer, compressed_size); @@ -441,17 +432,11 @@ namespace JMA //Allocate memory for compressed and decompressed data unsigned char *comp_buffer = 0, *decomp_buffer = 0; - try - { - //Compressed data size is <= non compressed size - unsigned char *combined_buffer = new unsigned char[chunk_size*2]; - comp_buffer = combined_buffer; - decomp_buffer = combined_buffer+chunk_size; - } - catch (bad_alloc xa) - { - throw(JMA_NO_MEM_ALLOC); - } + + //Compressed data size is <= non compressed size + unsigned char *combined_buffer = new unsigned char[chunk_size*2]; + comp_buffer = combined_buffer; + decomp_buffer = combined_buffer+chunk_size; size_t first_chunk_offset = size_to_skip % chunk_size; unsigned char int4_buffer[UINT_SIZE]; @@ -492,14 +477,7 @@ namespace JMA else //Solid JMA { unsigned char *decomp_buffer = 0; - try - { - decomp_buffer = new unsigned char[get_total_size(files)]; - } - catch (bad_alloc xa) - { - throw(JMA_NO_MEM_ALLOC); - } + decomp_buffer = new unsigned char[get_total_size(files)]; get_all_files(decomp_buffer); diff --git a/server.cpp b/server.cpp index 9e336367..652d948e 100644 --- a/server.cpp +++ b/server.cpp @@ -360,7 +360,6 @@ static bool8 S9xNPSGetData (int socket, uint8 *data, int length) static bool8 S9xNPSSendData (int fd, const uint8 *data, int length) { - int Percent = 0; int len = length; int chunk = length / 50; @@ -404,8 +403,8 @@ static bool8 S9xNPSSendData (int fd, const uint8 *data, int length) data += sent; if (length > 1024) { - Percent = (uint8) (((length - len) * 100) / length); #ifdef __WIN32__ + int Percent = (uint8) (((length - len) * 100) / length); PostMessage (GUI.hWnd, WM_USER, Percent, Percent); Sleep (0); #endif @@ -1057,12 +1056,15 @@ void S9xNPServerLoop (void *) bool8 S9xNPStartServer (int port) { +#ifdef __WIN32__ static int p; + p = port; +#endif #ifdef NP_DEBUG printf ("SERVER: Starting server on port %d @%ld\n", port, S9xGetMilliTime () - START); #endif - p = port; + server_continue = TRUE; if (S9xNPServerInit (port)) #ifdef __WIN32__ diff --git a/shaders/glsl.cpp b/shaders/glsl.cpp index 94d69636..51becd3c 100644 --- a/shaders/glsl.cpp +++ b/shaders/glsl.cpp @@ -321,8 +321,9 @@ GLuint GLSLShader::compile_shader(char *program, glCompileShader (shader); glGetShaderiv (shader, GL_COMPILE_STATUS, &status); + info_log[0] = '\0'; glGetShaderInfoLog (shader, 1024, NULL, info_log); - if (info_log && *info_log) + if (*info_log) printf ("%s\n", info_log); *out = shader; @@ -408,8 +409,9 @@ bool GLSLShader::load_shader (char *filename) glLinkProgram (p->program); glGetProgramiv (p->program, GL_LINK_STATUS, &status); + log[0] = '\0'; glGetProgramInfoLog(p->program, 1024, NULL, log); - if (log && *log) + if (*log) printf ("%s\n", log); glDeleteShader (vertex_shader); @@ -833,7 +835,7 @@ void GLSLShader::set_shader_vars (unsigned int p) if (attr > -1) \ { \ glEnableVertexAttribArray(attr); \ - glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, ((float *) NULL) + offset); \ + glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, (void *)(sizeof (float) * offset)); \ vaos.push_back (attr); \ } #define setTexCoordsNoOffset(attr) \ diff --git a/snapshot.cpp b/snapshot.cpp index 216ae43a..2aee63a9 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -1192,7 +1192,7 @@ void S9xResetSaveTimer (bool8 dontsave) char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], def[_MAX_FNAME + 1], ext[_MAX_EXT + 1]; _splitpath(Memory.ROMFilename, drive, dir, def, ext); - sprintf(filename, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops"); + snprintf(filename, PATH_MAX + 1, "%s%s%s.%.*s", S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT - 1, "oops"); S9xMessage(S9X_INFO, S9X_FREEZE_FILE_INFO, SAVE_INFO_OOPS); S9xFreezeGame(filename); }