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

Possible bug with casting & ternary operators #71

Open
asmaloney opened this issue Jul 22, 2021 · 0 comments
Open

Possible bug with casting & ternary operators #71

asmaloney opened this issue Jul 22, 2021 · 0 comments

Comments

@asmaloney
Copy link
Owner

I was just looking over some code and ran across this in SourceDestBufferImpl.cpp:

void SourceDestBufferImpl::setNextInt64( int64_t value )
{
...
      case E57_BOOL:
         *reinterpret_cast<bool *>( p ) = ( value ? false : true );
         break;
...

This also happens in:

template <typename T> void SourceDestBufferImpl::_setNextReal( T inValue )

and

void SourceDestBufferImpl::setNextInt64( int64_t value, double scale, double offset )

These ternaries seem backwards... If value is non-zero, I would expect the bool to be true.

I'm surprised we don't see bugs pop up but I suppose it's possible this code never runs.

I'm hesitant to change it without tests in place, but I would appreciate another set of eyes to look at it!

(These could probably just be rewritten using static_cast anyways.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant