Skip to content

Commit

Permalink
{standard} Fix invalid range exception in FloatNode implementation (#250
Browse files Browse the repository at this point in the history
)

A prototype field like this would throw an exception because it was checking the default value (0.0) against the range:

<cartesianY type="Float" minimum="0.040010999888181686" maximum="0.1873210072517395" />

Instead, only perform the check if we have explicitly set the value.

This fix follows the standard (E57 Standard 8.3.9.3 (1)) which allows this form:

"The values of the prototype elements and sub-elements are ignored, and need not be specified."

Fixes #246
  • Loading branch information
asmaloney authored May 21, 2023
1 parent 6330aa1 commit a691e30
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
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

0 comments on commit a691e30

Please sign in to comment.