From 5f7771acd4ae359b15a14686b033d04e4709bc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 17 Jun 2017 16:51:36 +0200 Subject: [PATCH 1/2] wml_message: fix possible nullpointer dereference. This was found by cppcheck: [src/gui/dialogs/wml_message.cpp:174] -> [src/gui/dialogs/wml_message.cpp:177]: (warning) Either the condition 'right' is redundant or there is possible null pointer dereference: right. Code was as follows: if(left && !right) { dlg.reset(new wml_message_left(title, message, left->portrait, left->mirror)); } else if(!left && right) { dlg.reset(new wml_message_right(title, message, right->portrait, right->mirror)); } else { dlg.reset(new wml_message_double(title, message, left->portrait, left->mirror, right->portrait, right->mirror)); } left right => branch taken T T else {} T F if {} F T elseif {} F F else {} // we could possibly access left->foo and right->foo here Make else {} into an explicit else if (right && left) {} --- src/gui/dialogs/wml_message.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/dialogs/wml_message.cpp b/src/gui/dialogs/wml_message.cpp index 5e0b715ec582..fb481c357a89 100644 --- a/src/gui/dialogs/wml_message.cpp +++ b/src/gui/dialogs/wml_message.cpp @@ -173,7 +173,7 @@ int show_wml_message(CVideo& video, dlg.reset(new wml_message_left(title, message, left->portrait, left->mirror)); } else if(!left && right) { dlg.reset(new wml_message_right(title, message, right->portrait, right->mirror)); - } else { + } else if(right && left) { dlg.reset(new wml_message_double(title, message, left->portrait, left->mirror, right->portrait, right->mirror)); } assert(dlg.get()); From 163749337984eb4392b6da2234185391a8c8cdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 17 Jun 2017 17:04:17 +0200 Subject: [PATCH 2/2] ai/configuration.hpp: parse_side_config(): make arguments in declaration and definition the same. Found by cppcheck: [src/ai/configuration.hpp:108] -> [src/ai/configuration.cpp:178]: (warning) Function 'parse_side_config' argument order different: declaration 'side, cfg, parsed_cfg' definition 'side, original_cfg, cfg' Rename arguments in declaration (configuration.hpp) from 'side, cfg, parsed_cfg' to 'side, original_cfg, cfg'. --- src/ai/configuration.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ai/configuration.hpp b/src/ai/configuration.hpp index 6584805d1581..359626c0cc61 100644 --- a/src/ai/configuration.hpp +++ b/src/ai/configuration.hpp @@ -105,7 +105,7 @@ class configuration { * @retval true success * @retval false failure */ - static bool parse_side_config(side_number side, const config& cfg, config &parsed_cfg); + static bool parse_side_config(side_number side, const config& original_cfg, config &cfg); /**