1From f4bc74ac4954328b25e961e7afb7337377084079 Mon Sep 17 00:00:00 2001
2From: David Seifert <soap@gentoo.org>
3Date: Sat, 31 Dec 2016 18:21:18 +0200
4Subject: [PATCH] Fix compiling in C++14 mode
5
6* Left shifting a negative signed is undefined behaviour
7* Fix incorrect printf() specifiers found with -Wformat
8---
9 source/core/NstCore.hpp | 4 ++--
10 source/unix/gtkui/gtkui.cpp | 2 +-
11 source/unix/gtkui/gtkui.h | 1 -
12 source/unix/gtkui/gtkui_cheats.cpp | 8 ++++----
13 source/unix/video.cpp | 2 +-
14 5 files changed, 8 insertions(+), 9 deletions(-)
15
16diff --git a/source/core/NstCore.hpp b/source/core/NstCore.hpp
17index 50e20f6..420cc4a 100644
18--- a/source/core/NstCore.hpp
19+++ b/source/core/NstCore.hpp
20@@ -279,14 +279,14 @@ namespace Nes
21 template<typename T>
22 inline long signed_shl(T v,uint c)
23 {
24- enum {NATIVE = T(-7) << 1 == -14};
25+ enum {NATIVE = -(T(7) << 1) == -14};
26 return Helper::ShiftSigned<T,NATIVE>::Left( v, c );
27 }
28
29 template<typename T>
30 inline long signed_shr(T v,uint c)
31 {
32- enum {NATIVE = T(-7) >> 1 == -4 || T(-7) >> 1 == -3};
33+ enum {NATIVE = -(T(7) >> 1) == -4 || -(T(7) >> 1) == -3};
34 return Helper::ShiftSigned<T,NATIVE>::Right( v, c );
35 }
36
37diff --git a/source/unix/gtkui/gtkui.cpp b/source/unix/gtkui/gtkui.cpp
38index 3cfeeab..d4a5e2d 100644
39--- a/source/unix/gtkui/gtkui.cpp
40+++ b/source/unix/gtkui/gtkui.cpp
41@@ -438,7 +438,7 @@ void gtkui_message(const char* message) {
42 GTK_DIALOG_DESTROY_WITH_PARENT,
43 GTK_MESSAGE_INFO,
44 GTK_BUTTONS_OK,
45- message);
46+ "%s", message);
47 gtk_dialog_run(GTK_DIALOG(messagewindow));
48 gtk_widget_destroy(messagewindow);
49 }
50diff --git a/source/unix/gtkui/gtkui_cheats.cpp b/source/unix/gtkui/gtkui_cheats.cpp
51index afc01b0..e7b691a 100644
52--- a/source/unix/gtkui/gtkui_cheats.cpp
53+++ b/source/unix/gtkui/gtkui_cheats.cpp
54@@ -373,7 +373,7 @@ void gtkui_cheats_fill_tree(char *filename) {
55 else if (node.GetChild(L"address")) { // Raw
56 char rawbuf[11];
57 snprintf(rawbuf, sizeof(rawbuf),
58- "%04x %02x %02x",
59+ "%04lu %02lu %02lu",
60 node.GetChild(L"address").GetUnsignedValue(),
61 node.GetChild(L"value").GetUnsignedValue(),
62 node.GetChild(L"compare").GetUnsignedValue());
63@@ -545,13 +545,13 @@ gboolean gtkui_cheats_scan_list(GtkTreeModel *model, GtkTreePath *path, GtkTreeI
64 int addr, value, compare;
65 char buf[5];
66
67- snprintf(buf, sizeof(buf), "%c%c%c%c\0", rawcode[0], rawcode[1], rawcode[2], rawcode[3]);
68+ snprintf(buf, sizeof(buf), "%c%c%c%c", rawcode[0], rawcode[1], rawcode[2], rawcode[3]);
69 sscanf(buf, "%x", &addr);
70
71- snprintf(buf, sizeof(buf), "%c%c\0", rawcode[5], rawcode[6]);
72+ snprintf(buf, sizeof(buf), "%c%c", rawcode[5], rawcode[6]);
73 sscanf(buf, "%x", &value);
74
75- snprintf(buf, sizeof(buf), "%c%c\0", rawcode[8], rawcode[9]);
76+ snprintf(buf, sizeof(buf), "%c%c", rawcode[8], rawcode[9]);
77 sscanf(buf, "%x", &compare);
78
79 code.address = addr;
80diff --git a/source/unix/video.cpp b/source/unix/video.cpp
81index 3eff19d..c34bb22 100644
82--- a/source/unix/video.cpp
83+++ b/source/unix/video.cpp
84@@ -757,7 +757,7 @@ void video_screenshot(const char* filename) {
85 if (filename == NULL) {
86 // Set the filename
87 char sshotpath[512];
88- snprintf(sshotpath, sizeof(sshotpath), "%sscreenshots/%s-%d-%d.png", nstpaths.nstdir, nstpaths.gamename, time(NULL), rand() % 899 + 100);
89+ snprintf(sshotpath, sizeof(sshotpath), "%sscreenshots/%s-%ld-%d.png", nstpaths.nstdir, nstpaths.gamename, time(NULL), rand() % 899 + 100);
90
91 // Save the file
92 lodepng_encode32_file(sshotpath, (const unsigned char*)pixels, rendersize.w, rendersize.h);