Browse Source

Fix return value going out of scope.

(From Coverity report.)
pull/16/head
Jeff Young 5 years ago
parent
commit
552dde8976
  1. 2
      common/libeval_compiler/libeval_compiler.cpp
  2. 5
      include/libeval_compiler/libeval_compiler.h
  3. 14
      qa/libeval_compiler/libeval_compiler_test.cpp

2
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;

5
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 )

14
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 )
{

Loading…
Cancel
Save