Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{standard} Fix invalid range exception in FloatNode implementation #250

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/E57XmlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,18 +745,18 @@ void E57XmlParser::endElement( const XMLCh *const uri, const XMLCh *const localN
break;
case TypeFloat:
{
// Convert child text (if any) to value, else default to 0.0
double floatValue;
// Convert child text (if any) to value
double floatValue = 0.0;
bool validValue = false;

if ( pi.childText.length() > 0 )
{
floatValue = strToDouble( pi.childText );
validValue = true;
}
else
{
floatValue = 0.0;
}
std::shared_ptr<FloatNodeImpl> f_ni(
new FloatNodeImpl( imf_, floatValue, pi.precision, pi.floatMinimum, pi.floatMaximum ) );

std::shared_ptr<FloatNodeImpl> f_ni( new FloatNodeImpl(
imf_, floatValue, validValue, pi.precision, pi.floatMinimum, pi.floatMaximum ) );
current_ni = f_ni;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/FloatNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ be true).
*/
FloatNode::FloatNode( const ImageFile &destImageFile, double value, FloatPrecision precision,
double minimum, double maximum ) :
impl_( new FloatNodeImpl( destImageFile.impl(), value, precision, minimum, maximum ) )
impl_( new FloatNodeImpl( destImageFile.impl(), value, true, precision, minimum, maximum ) )
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/FloatNodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace e57
{
FloatNodeImpl::FloatNodeImpl( ImageFileImplWeakPtr destImageFile, double value,
FloatNodeImpl::FloatNodeImpl( ImageFileImplWeakPtr destImageFile, double value, bool validValue,
FloatPrecision precision, double minimum, double maximum ) :
NodeImpl( destImageFile ),
value_( value ), precision_( precision ), minimum_( minimum ), maximum_( maximum )
Expand All @@ -52,8 +52,8 @@ namespace e57
}
}

// Enforce the given bounds on raw value
if ( value < minimum || maximum < value )
// Enforce the given bounds on raw value if it is valid
if ( validValue && ( value < minimum || value > maximum ) )
{
throw E57_EXCEPTION2( ErrorValueOutOfBounds, "this->pathName=" + this->pathName() +
" value=" + toString( value ) +
Expand Down
2 changes: 1 addition & 1 deletion src/FloatNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace e57
{
public:
explicit FloatNodeImpl( ImageFileImplWeakPtr destImageFile, double value = 0,
FloatPrecision precision = PrecisionDouble,
bool validValue = true, FloatPrecision precision = PrecisionDouble,
double minimum = DOUBLE_MIN, double maximum = DOUBLE_MAX );
~FloatNodeImpl() override = default;

Expand Down