From e9144d1a7839fe2c7f5becb4fd22dde53c8e9096 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Thu, 29 May 2014 02:58:18 +0200 Subject: [PATCH] Fixed #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp. --- lib/checkother.cpp | 2 ++ test/testother.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 560ba9078..447dcd032 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3189,6 +3189,8 @@ void CheckOther::checkRedundantCopy() continue; const Token* tok = startTok->next()->astOperand2(); + if (!tok) + continue; if (!Token::Match(tok->previous(), "%var% (")) continue; if (!Token::Match(tok->link(), ") )| ;")) // bailout for usage like "const A a = getA()+3" diff --git a/test/testother.cpp b/test/testother.cpp index 8c80e27fe..abe04cde4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6358,6 +6358,14 @@ private: " }\n" "}\n"); TODO_ASSERT_EQUALS("", "[test.cpp:7]: (performance, inconclusive) Use const reference for 'temp' to avoid unnecessary data copying.\n", errout.str()); + + // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp + check_redundant_copy("typedef std::vector X;\n" + "X f(const X &in) {\n" + " const X s = f(in);\n" + " return f(s);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkNegativeShift() {