From 552dde8976b3b2f68cd400e07989c6fe1ea32143 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 26 Jul 2020 12:22:49 +0100 Subject: [PATCH] Fix return value going out of scope. (From Coverity report.) --- common/libeval_compiler/libeval_compiler.cpp | 2 +- include/libeval_compiler/libeval_compiler.h | 5 ----- qa/libeval_compiler/libeval_compiler_test.cpp | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/libeval_compiler/libeval_compiler.cpp b/common/libeval_compiler/libeval_compiler.cpp index 008b3aeae3..5efcac71d9 100644 --- a/common/libeval_compiler/libeval_compiler.cpp +++ b/common/libeval_compiler/libeval_compiler.cpp @@ -108,7 +108,7 @@ std::string UOP::Format() const else if( val->GetType() == VT_NUMERIC ) snprintf( str, LIBEVAL_MAX_LITERAL_LENGTH, "PUSH NUM [%.10f]", val->AsDouble() ); else - snprintf( str, LIBEVAL_MAX_LITERAL_LENGTH, "PUSH STR [%s]", val->AsChars() ); + snprintf( str, LIBEVAL_MAX_LITERAL_LENGTH, "PUSH STR [%ls]", GetChars( val->AsString() ) ); } break; diff --git a/include/libeval_compiler/libeval_compiler.h b/include/libeval_compiler/libeval_compiler.h index d1a098c799..dbd73593a1 100644 --- a/include/libeval_compiler/libeval_compiler.h +++ b/include/libeval_compiler/libeval_compiler.h @@ -196,11 +196,6 @@ public: return m_valueStr; } - const char* AsChars() const - { - return m_valueStr.ToStdString().c_str(); - } - bool operator==( const VALUE& b ) const { if( m_type == VT_NUMERIC && b.m_type == VT_NUMERIC ) diff --git a/qa/libeval_compiler/libeval_compiler_test.cpp b/qa/libeval_compiler/libeval_compiler_test.cpp index 80510f7343..e0f74857aa 100644 --- a/qa/libeval_compiler/libeval_compiler_test.cpp +++ b/qa/libeval_compiler/libeval_compiler_test.cpp @@ -45,9 +45,19 @@ bool testEvalExpr( const std::string expr, LIBEVAL::VALUE expectedResult, bool e } if( expectedResult.GetType() == LIBEVAL::VT_NUMERIC ) - printf("result: %s (got %.10f expected: %.10f)\n", ok ? "OK" : "FAIL", result.AsDouble(), expectedResult.AsDouble() ); + { + printf( "result: %s (got %.10f expected: %.10f)\n", + ok ? "OK" : "FAIL", + result.AsDouble(), + expectedResult.AsDouble() ); + } else - printf("result: %s (got '%s' expected: '%s')\n", ok ? "OK" : "FAIL", result.AsChars(), expectedResult.AsChars() ); + { + printf( "result: %s (got '%ls' expected: '%ls')\n", + ok ? "OK" : "FAIL", + GetChars( result.AsString() ), + GetChars( expectedResult.AsString() ) ); + } if (!ok ) {