asmaloney / asmaloney/libE57Format

Possible bug with casting & ternary operators

Open
#71 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
191
Forks
82
Avg merge
7h 21m
Merged PRs (30d)
1

Description

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

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

This also happens in:
```cpp
template void SourceDestBufferImpl::_setNextReal( T inValue )
```
and
```cpp
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.)

Contributor guide

Open the contributing guide

Research direction

Start in SourceDestBufferImpl.cpp with setNextInt64(int64_t), _setNextReal(T), and the scaled setNextInt64 overload. Review the E57_BOOL handling and add tests covering zero and non-zero values in each affected path; done means the tests confirm the intended boolean conversion without changing other types.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.