variant.cpp: Tighten bool parsing in variant::as_bool() cryptonomex/graphene#525
This commit is contained in:
parent
9128edb0d6
commit
46ed830373
1 changed files with 8 additions and 1 deletions
|
|
@ -431,7 +431,14 @@ bool variant::as_bool()const
|
|||
switch( get_type() )
|
||||
{
|
||||
case string_type:
|
||||
return **reinterpret_cast<const const_string_ptr*>(this) == "true";
|
||||
{
|
||||
const string& s = **reinterpret_cast<const const_string_ptr*>(this);
|
||||
if( s == "true" )
|
||||
return true;
|
||||
if( s == "false" )
|
||||
return false;
|
||||
FC_THROW_EXCEPTION( bad_cast_exception, "Cannot convert string to bool (only \"true\" or \"false\" can be converted)" );
|
||||
}
|
||||
case double_type:
|
||||
return *reinterpret_cast<const double*>(this) != 0.0;
|
||||
case int64_type:
|
||||
|
|
|
|||
Loading…
Reference in a new issue