Fix return value going out of scope.

(From Coverity report.)
This commit is contained in:
Jeff Young 2020-07-26 12:22:49 +01:00
parent 124afa5fc4
commit 552dde8976
3 changed files with 13 additions and 8 deletions

View File

@ -108,7 +108,7 @@ std::string UOP::Format() const
else if( val->GetType() == VT_NUMERIC ) else if( val->GetType() == VT_NUMERIC )
snprintf( str, LIBEVAL_MAX_LITERAL_LENGTH, "PUSH NUM [%.10f]", val->AsDouble() ); snprintf( str, LIBEVAL_MAX_LITERAL_LENGTH, "PUSH NUM [%.10f]", val->AsDouble() );
else 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; break;

View File

@ -196,11 +196,6 @@ public:
return m_valueStr; return m_valueStr;
} }
const char* AsChars() const
{
return m_valueStr.ToStdString().c_str();
}
bool operator==( const VALUE& b ) const bool operator==( const VALUE& b ) const
{ {
if( m_type == VT_NUMERIC && b.m_type == VT_NUMERIC ) if( m_type == VT_NUMERIC && b.m_type == VT_NUMERIC )

View File

@ -45,9 +45,19 @@ bool testEvalExpr( const std::string expr, LIBEVAL::VALUE expectedResult, bool e
} }
if( expectedResult.GetType() == LIBEVAL::VT_NUMERIC ) 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 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 ) if (!ok )
{ {