···
1
+
From f4bc74ac4954328b25e961e7afb7337377084079 Mon Sep 17 00:00:00 2001
2
+
From: David Seifert <soap@gentoo.org>
3
+
Date: Sat, 31 Dec 2016 18:21:18 +0200
4
+
Subject: [PATCH] Fix compiling in C++14 mode
6
+
* Left shifting a negative signed is undefined behaviour
7
+
* Fix incorrect printf() specifiers found with -Wformat
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(-)
16
+
diff --git a/source/core/NstCore.hpp b/source/core/NstCore.hpp
17
+
index 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)
24
+
- enum {NATIVE = T(-7) << 1 == -14};
25
+
+ enum {NATIVE = -(T(7) << 1) == -14};
26
+
return Helper::ShiftSigned<T,NATIVE>::Left( v, c );
29
+
template<typename T>
30
+
inline long signed_shr(T v,uint c)
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 );
37
+
diff --git a/source/unix/gtkui/gtkui.cpp b/source/unix/gtkui/gtkui.cpp
38
+
index 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,
47
+
gtk_dialog_run(GTK_DIALOG(messagewindow));
48
+
gtk_widget_destroy(messagewindow);
50
+
diff --git a/source/unix/gtkui/gtkui_cheats.cpp b/source/unix/gtkui/gtkui_cheats.cpp
51
+
index 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
57
+
snprintf(rawbuf, sizeof(rawbuf),
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;
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);
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);
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);
79
+
code.address = addr;
80
+
diff --git a/source/unix/video.cpp b/source/unix/video.cpp
81
+
index 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) {
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);
92
+
lodepng_encode32_file(sshotpath, (const unsigned char*)pixels, rendersize.w, rendersize.h);