From 04e12dc222d9a7f5094bd3fa6c5b545ea30c1bf4 Mon Sep 17 00:00:00 2001 From: Hannes Steffenhagen Date: Mon, 29 Jun 2020 17:40:37 +0100 Subject: [PATCH] Fix bug where reference to temporary string was returned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is fortunately only in a unit tests and apparently hasn’t caused any problems so far, but we nevertheless should avoid returning references to temporaries. As a bonus the fixed code is simpler. --- jbmc/unit/java-testing-utils/require_goto_statements.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/jbmc/unit/java-testing-utils/require_goto_statements.h b/jbmc/unit/java-testing-utils/require_goto_statements.h index cc843023e90..ffc69472de4 100644 --- a/jbmc/unit/java-testing-utils/require_goto_statements.h +++ b/jbmc/unit/java-testing-utils/require_goto_statements.h @@ -34,19 +34,17 @@ class no_decl_found_exceptiont : public std::exception { public: explicit no_decl_found_exceptiont(const std::string &var_name) - : _varname(var_name) + : message{"Failed to find declaration for: " + var_name} { } virtual const char *what() const throw() { - std::ostringstream stringStream; - stringStream << "Failed to find declaration for: " << _varname; - return stringStream.str().c_str(); + return message.c_str(); } private: - std::string _varname; + std::string message; }; pointer_assignment_locationt find_struct_component_assignments(