[widelands] use string literals as format strings (#1037384)

Nils Philippsen nphilipp at fedoraproject.org
Tue Dec 3 14:22:18 UTC 2013


commit 2894f07327b74d740a2d419c7a4009a5239b71b9
Author: Nils Philippsen <nils at redhat.com>
Date:   Tue Dec 3 15:21:43 2013 +0100

    use string literals as format strings (#1037384)

 widelands-build17-src-format-security.patch |  311 +++++++++++++++++++++++++++
 widelands.spec                              |    8 +-
 2 files changed, 318 insertions(+), 1 deletions(-)
---
diff --git a/widelands-build17-src-format-security.patch b/widelands-build17-src-format-security.patch
new file mode 100644
index 0000000..d0781f9
--- /dev/null
+++ b/widelands-build17-src-format-security.patch
@@ -0,0 +1,311 @@
+From 209f5a15358e10b1acfcc29a385d1210830f6197 Mon Sep 17 00:00:00 2001
+From: Nils Philippsen <nils at redhat.com>
+Date: Tue, 3 Dec 2013 15:15:02 +0100
+Subject: [PATCH] patch: format-security
+
+Squashed commit of the following:
+
+commit b85881a87547f2284f97b7680315073aa5aaa600
+Author: Holger Rapp <SirVer at gmx.de>
+Date:   Sun May 6 18:28:43 2012 +0200
+
+    Compile time warning silencing by Aelia
+
+    (cherry picked from commit 5d1212c7e8d748878ecf0c57f8f40c9278b55445)
+
+commit a90dafa66dcef411ac499c38541c7354a5b3f6e4
+Author: Borim <borim7 at web.de>
+Date:   Sun May 27 13:54:05 2012 +0200
+
+    fix typo
+
+    (cherry picked from commit 7bd487c2ebbdfe7b040d4088e9afd5b6fbf106b7)
+
+commit a4db6feff423cff00efc437c67651b9382b27af1
+Author: Borim <borim7 at web.de>
+Date:   Sun May 27 09:30:28 2012 +0200
+
+    fix use of warning constructor
+
+    (cherry picked from commit 6de81f443f7490170b48f5535c22aad8c2f77389)
+---
+ src/editor/editorinteractive.cc      |  2 +-
+ src/editor/editorinteractive.h       |  2 +-
+ src/io/basic_fileread.h              |  2 +-
+ src/io/dedicated_log.cc              |  6 +++---
+ src/io/filesystem/disk_filesystem.cc |  2 +-
+ src/io/filesystem/filesystem.h       |  2 +-
+ src/io/streamread.h                  |  2 +-
+ src/logic/map.h                      |  2 +-
+ src/logic/productionsite.cc          |  2 +-
+ src/logic/productionsite.h           |  2 +-
+ src/logic/soldier.cc                 |  2 +-
+ src/network/internet_gaming.cc       | 10 +++++++---
+ src/scripting/lua_game.h             |  3 +++
+ src/scripting/lua_map.h              |  2 ++
+ src/wui/interactive_base.h           |  2 +-
+ src/wui/watchwindow.cc               |  5 +----
+ 16 files changed, 27 insertions(+), 21 deletions(-)
+
+diff --git a/src/editor/editorinteractive.cc b/src/editor/editorinteractive.cc
+index 65c1c77..7ece0d9 100644
+--- a/src/editor/editorinteractive.cc
++++ b/src/editor/editorinteractive.cc
+@@ -510,7 +510,7 @@ void Editor_Interactive::select_tool
+  *  data is a pointer to a tribe (for buildings)
+  */
+ void Editor_Interactive::reference_player_tribe
+-(Widelands::Player_Number const player, void const * const data) {
++(Widelands::Player_Number player, void const * const data) {
+ 	assert(0 < player);
+ 	assert(player <= egbase().map().get_nrplayers());
+ 
+diff --git a/src/editor/editorinteractive.h b/src/editor/editorinteractive.h
+index 5092274..9531cbd 100644
+--- a/src/editor/editorinteractive.h
++++ b/src/editor/editorinteractive.h
+@@ -115,7 +115,7 @@ public:
+ 	void exit();
+ 
+ 	//  reference functions
+-	void   reference_player_tribe(Widelands::Player_Number, void const *);
++	void   reference_player_tribe(Widelands::Player_Number, const void * const);
+ 	void unreference_player_tribe(Widelands::Player_Number, void const *);
+ 	bool is_player_tribe_referenced(Widelands::Player_Number);
+ 	void set_need_save(bool const t) {m_need_save = t;}
+diff --git a/src/io/basic_fileread.h b/src/io/basic_fileread.h
+index 31729f5..035a780 100644
+--- a/src/io/basic_fileread.h
++++ b/src/io/basic_fileread.h
+@@ -106,7 +106,7 @@ template<typename Base> struct basic_FileRead : public Base {
+ 	/// does not specify a position.
+ 	Pos GetPos() const throw () {return filepos;}
+ 
+-	size_t Data(void * const dst, const size_t bufsize) {
++	size_t Data(void * dst, size_t bufsize) {
+ 		assert(data);
+ 		size_t read = 0;
+ 		for (; read < bufsize and filepos < length; ++read, ++filepos)
+diff --git a/src/io/dedicated_log.cc b/src/io/dedicated_log.cc
+index e13afb5..98f2240 100644
+--- a/src/io/dedicated_log.cc
++++ b/src/io/dedicated_log.cc
+@@ -78,7 +78,7 @@ void DedicatedLog::chat(ChatMessage & c) {
+ 	temp += c.sender.empty() ? "SYSTEM" : c.sender;
+ 	temp += "</td><td class=\"recipient\"> ->" + c.recipient + "</td><td class=\"message\">";
+ 	temp += c.msg + "</td></tr>\n";
+-	m_chat.Printf(temp.c_str());
++	m_chat.Printf("%s", temp.c_str());
+ 	m_chat.WriteAppend(*root, m_chat_file_path.c_str());
+ }
+ 
+@@ -185,7 +185,7 @@ void DedicatedLog::info_update() {
+ 		}
+ 	}
+ 	temp += "</table>\n";
+-	m_chat.Printf(temp.c_str());
++	m_chat.Printf("%s", temp.c_str());
+ 	m_chat.Write(*root, m_info_file_path.c_str());
+ }
+ 
+@@ -197,7 +197,7 @@ void DedicatedLog::dlog(std::string msg) {
+ 	std::string temp("<tr><td class=\"log\">");
+ 	temp += msg;
+ 	temp += "</td></tr>\n";
+-	m_chat.Printf(temp.c_str());
++	m_chat.Printf("%s", temp.c_str());
+ 	m_chat.WriteAppend(*root, m_log_file_path.c_str());
+ }
+ 
+diff --git a/src/io/filesystem/disk_filesystem.cc b/src/io/filesystem/disk_filesystem.cc
+index 4a9b5a9..ec22493 100644
+--- a/src/io/filesystem/disk_filesystem.cc
++++ b/src/io/filesystem/disk_filesystem.cc
+@@ -526,7 +526,7 @@ struct RealFSStreamRead : public StreamRead {
+ 		fclose(m_file);
+ 	}
+ 
+-	size_t Data(void * const data, size_t const bufsize) {
++	size_t Data(void * data, size_t const bufsize) {
+ 		return fread(data, 1, bufsize, m_file);
+ 	}
+ 
+diff --git a/src/io/filesystem/filesystem.h b/src/io/filesystem/filesystem.h
+index 6edb9de..dfd904a 100644
+--- a/src/io/filesystem/filesystem.h
++++ b/src/io/filesystem/filesystem.h
+@@ -109,7 +109,7 @@ struct FileSystem {
+ 
+ 	// basic path/filename manipulation
+ 	std::string fixCrossFile(std::string const &) const;
+-	const char  fileSeparator() {return m_filesep;}
++	char fileSeparator() {return m_filesep;}
+ 	std::string getWorkingDirectory() const;
+ 	std::string FS_CanonicalizeName(std::string path) const;
+ 	bool pathIsAbsolute(std::string const & path) const;
+diff --git a/src/io/streamread.h b/src/io/streamread.h
+index 7e67fe0..d194b65 100644
+--- a/src/io/streamread.h
++++ b/src/io/streamread.h
+@@ -55,7 +55,7 @@ struct StreamRead : boost::noncopyable {
+ 	 * \return the number of bytes that were actually read. Will return 0 at
+ 	 * end of stream.
+ 	 */
+-	virtual size_t Data(void * const data, size_t bufsize) = 0;
++	virtual size_t Data(void * data, size_t bufsize) = 0;
+ 
+ 	/**
+ 	 * \return \c true if the end of file / end of stream has been reached.
+diff --git a/src/logic/map.h b/src/logic/map.h
+index b347605..154ea2d 100644
+--- a/src/logic/map.h
++++ b/src/logic/map.h
+@@ -199,7 +199,7 @@ struct Map :
+ 	const std::string & get_background() const {return m_background;}
+ 	typedef std::set<std::string> Tags;
+ 	const Tags & get_tags() const {return m_tags;}
+-	const bool has_tag(std::string & s) const {return m_tags.count(s);}
++	bool has_tag(std::string & s) const {return m_tags.count(s);}
+ 
+ 	Player_Number get_nrplayers() const throw () {return m_nrplayers;}
+ 	ScenarioTypes scenario_types() const throw () {return m_scenario_types;}
+diff --git a/src/logic/productionsite.cc b/src/logic/productionsite.cc
+index 849821a..149f2c0 100644
+--- a/src/logic/productionsite.cc
++++ b/src/logic/productionsite.cc
+@@ -655,7 +655,7 @@ bool ProductionSite::fetch_from_flag(Game & game)
+ }
+ 
+ 
+-void ProductionSite::log_general_info(Editor_Game_Base & egbase) {
++void ProductionSite::log_general_info(Editor_Game_Base const & egbase) {
+ 	Building::log_general_info(egbase);
+ 
+ 	molog("m_is_stopped: %u\n", m_is_stopped);
+diff --git a/src/logic/productionsite.h b/src/logic/productionsite.h
+index 14f0d72..4da54ba 100644
+--- a/src/logic/productionsite.h
++++ b/src/logic/productionsite.h
+@@ -132,7 +132,7 @@ public:
+ 	ProductionSite(const ProductionSite_Descr & descr);
+ 	virtual ~ProductionSite();
+ 
+-	void log_general_info(Editor_Game_Base &);
++	void log_general_info(Editor_Game_Base const &);
+ 
+ 	bool is_stopped() const {return m_is_stopped;}
+ 	void set_stopped(bool);
+diff --git a/src/logic/soldier.cc b/src/logic/soldier.cc
+index b8b929f..cf9c98f 100644
+--- a/src/logic/soldier.cc
++++ b/src/logic/soldier.cc
+@@ -753,7 +753,7 @@ Bob::Task const Soldier::taskAttack = {
+ void Soldier::start_task_attack
+ 	(Game & game, Building & building, uint8_t retreat)
+ {
+-	dynamic_cast<Attackable const &>(building);
++	//dynamic_cast<Attackable const &>(building);
+ 
+ 	push_task(game, taskAttack);
+ 	State & state  = top_state();
+diff --git a/src/network/internet_gaming.cc b/src/network/internet_gaming.cc
+index 58417d0..bb9e0c6 100644
+--- a/src/network/internet_gaming.cc
++++ b/src/network/internet_gaming.cc
+@@ -362,7 +362,8 @@ void InternetGaming::handle_packet(RecvPacket & packet)
+ 			logout();
+ 			setError();
+ 			throw warning
+-				(_
++				(_("Unexpected packet"),
++				 _
+ 				 	("Expected a LOGIN, RELOGIN or REJECTED packet from server, but received command "
+ 				 	 "%s. Maybe the metaserver is using a different protocol version ?"),
+ 				 cmd.c_str());
+@@ -403,7 +404,7 @@ void InternetGaming::handle_packet(RecvPacket & packet)
+ 			std::string type     = packet.String();
+ 
+ 			if (type != "public" && type != "private" && type != "system")
+-				throw warning("Invalid chat message type \"%s\".", type.c_str());
++				throw warning(_("Invalid message type"), _("Invalid chat message type \"%s\"."), type.c_str());
+ 
+ 			bool        personal = type == "private";
+ 			bool        system   = type == "system";
+@@ -708,7 +709,10 @@ void InternetGaming::send(std::string const & msg) {
+  */
+ bool InternetGaming::str2bool(std::string str) {
+ 	if ((str != "true") && (str != "false"))
+-		throw warning("Conversion from std::string to bool failed. String was \"%s\"", str.c_str());
++		throw warning
++			(_("Conversion error"),
++			_("Conversion from std::string to bool failed. String was \"%s\""), str.c_str());
++
+ 	return str == "true";
+ }
+ 
+diff --git a/src/scripting/lua_game.h b/src/scripting/lua_game.h
+index a369102..ba5a921 100644
+--- a/src/scripting/lua_game.h
++++ b/src/scripting/lua_game.h
+@@ -113,6 +113,8 @@ class L_Objective : public L_GameModuleClass {
+ public:
+ 	LUNA_CLASS_HEAD(L_Objective);
+ 
++	virtual ~L_Objective() {}
++
+ 	L_Objective(Widelands::Objective n);
+ 	L_Objective() : m_name("") {}
+ 	L_Objective(lua_State * L) {
+@@ -153,6 +155,7 @@ class L_Message : public L_GameModuleClass {
+ 
+ public:
+ 	LUNA_CLASS_HEAD(L_Message);
++	virtual ~L_Message() {}
+ 
+ 	L_Message(uint8_t, Widelands::Message_Id);
+ 	L_Message() : m_plr(0), m_mid(0) {}
+diff --git a/src/scripting/lua_map.h b/src/scripting/lua_map.h
+index a06d5a9..0e8cd87 100644
+--- a/src/scripting/lua_map.h
++++ b/src/scripting/lua_map.h
+@@ -56,6 +56,8 @@ class L_Map : public L_MapModuleClass {
+ public:
+ 	LUNA_CLASS_HEAD(L_Map);
+ 
++	virtual ~L_Map() {}
++
+ 	L_Map() {}
+ 	L_Map(lua_State * L) {
+ 		report_error(L, "Cannot instantiate a 'Map' directly!");
+diff --git a/src/wui/interactive_base.h b/src/wui/interactive_base.h
+index 7ab6adf..a5c07e1 100644
+--- a/src/wui/interactive_base.h
++++ b/src/wui/interactive_base.h
+@@ -57,7 +57,7 @@ struct Interactive_Base : public Map_View, public DebugConsole::Handler {
+ 	virtual ~Interactive_Base();
+ 
+ 	Widelands::Editor_Game_Base & egbase() const {return m_egbase;}
+-	virtual void reference_player_tribe(const int32_t, const void * const) {}
++	virtual void reference_player_tribe(Widelands::Player_Number, const void * const) {}
+ 
+ 	bool m_show_workarea_preview;
+ 
+diff --git a/src/wui/watchwindow.cc b/src/wui/watchwindow.cc
+index aa7c9f7..9760032 100644
+--- a/src/wui/watchwindow.cc
++++ b/src/wui/watchwindow.cc
+@@ -294,10 +294,7 @@ void WatchWindow::stop_tracking_by_drag(int32_t, int32_t) {
+ void WatchWindow::do_follow()
+ {
+ 	Widelands::Game & g = game();
+-	if
+-		(Widelands::Map_Object const * const obj =
+-			views[cur_index].tracking.get(g))
+-	{
++	if (views[cur_index].tracking.get(g)) {
+ 		views[cur_index].tracking = 0;
+ 	} else {
+ 		//  Find the nearest bob. Other object types can not move and are
+-- 
+1.8.4.2
+
diff --git a/widelands.spec b/widelands.spec
index 4021053..8778662 100644
--- a/widelands.spec
+++ b/widelands.spec
@@ -4,7 +4,7 @@
 
 Name:           widelands
 Version:        0
-Release:        0.39.%{buildid}%{?dist}
+Release:        0.40.%{buildid}%{?dist}
 Summary:        Open source realtime-strategy game
 
 Group:          Amusements/Games
@@ -16,6 +16,8 @@ Source0:        http://launchpad.net/widelands/%{buildid}/%{build_id}/+download/
 Patch0:         widelands-build17-src-crash-on-messagebox.patch
 # Build issue with gcc 4.7, already fixed upstream
 Patch1:         widelands-build17-src-includes.patch
+# Use string literals as format strings (#1037384). Backported from upstream.
+Patch2:         widelands-build17-src-format-security.patch
 
 BuildRequires: SDL-devel >= 1.2.11
 BuildRequires: SDL_gfx-devel
@@ -57,6 +59,7 @@ perhaps will have a thought, what Widelands is all about.
 %setup -q -n widelands-%{buildid}-src
 %patch0 -p1 -b .crash-on-messagebox
 %patch1 -p1 -b .includes
+%patch2 -p1 -b .format-security
 
 
 %build
@@ -154,6 +157,9 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
 
 
 %changelog
+* Tue Dec 03 2013 Nils Philippsen <nils at redhat.com> - 0-0.40.build17
+- use string literals as format strings (#1037384)
+
 * Mon Nov 18 2013 Dave Airlie <airlied at redhat.com> - 0-0.39.build17
 - rebuilt for GLEW 1.10
 


More information about the scm-commits mailing list