Skip to content

Commit

Permalink
Cast <int>_MAX comparisons to fix clang warnings (#257)
Browse files Browse the repository at this point in the history
These should be safe because we aren't checking equality.

Note that Apple's clang doesn't warn about these, but it looks like the official clang releases do.

Fixes #256
  • Loading branch information
asmaloney authored Aug 15, 2023
1 parent 72908b9 commit 507c98a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/SourceDestBufferImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ template <typename T> void SourceDestBufferImpl::_setNextReal( T inValue )
{
throw E57_EXCEPTION2( ErrorConversionRequired, "pathName=" + pathName_ );
}
if ( inValue < INT32_MIN || INT32_MAX < inValue )
if ( inValue < INT32_MIN || ( inValue > static_cast<T>( INT32_MAX ) ) )
{
throw E57_EXCEPTION2( ErrorValueNotRepresentable,
"pathName=" + pathName_ + " value=" + toString( inValue ) );
Expand All @@ -215,7 +215,7 @@ template <typename T> void SourceDestBufferImpl::_setNextReal( T inValue )
{
throw E57_EXCEPTION2( ErrorConversionRequired, "pathName=" + pathName_ );
}
if ( inValue < UINT32_MIN || UINT32_MAX < inValue )
if ( inValue < UINT32_MIN || ( inValue > ( static_cast<T>( UINT32_MAX ) ) ) )
{
throw E57_EXCEPTION2( ErrorValueNotRepresentable,
"pathName=" + pathName_ + " value=" + toString( inValue ) );
Expand All @@ -227,7 +227,7 @@ template <typename T> void SourceDestBufferImpl::_setNextReal( T inValue )
{
throw E57_EXCEPTION2( ErrorConversionRequired, "pathName=" + pathName_ );
}
if ( inValue < INT64_MIN || INT64_MAX < inValue )
if ( inValue < INT64_MIN || ( inValue > ( static_cast<T>( INT64_MAX ) ) ) )
{
throw E57_EXCEPTION2( ErrorValueNotRepresentable,
"pathName=" + pathName_ + " value=" + toString( inValue ) );
Expand Down Expand Up @@ -491,8 +491,9 @@ int64_t SourceDestBufferImpl::getNextInt64( double scale, double offset )
default:
throw E57_EXCEPTION2( ErrorInternal, "pathName=" + pathName_ );
}

/// Make sure that value is representable in an int64_t
if ( doubleRawValue < INT64_MIN || INT64_MAX < doubleRawValue )
if ( doubleRawValue < INT64_MIN || ( doubleRawValue > ( static_cast<double>( INT64_MAX ) ) ) )
{
throw E57_EXCEPTION2( ErrorScaledValueNotRepresentable,
"pathName=" + pathName_ + " value=" + toString( doubleRawValue ) );
Expand Down

0 comments on commit 507c98a

Please sign in to comment.