Skip to content

Commit

Permalink
BUG: SwapWriteRange functions should just write, when sizeof(T) is 1
Browse files Browse the repository at this point in the history
When `sizeof(T) == 1`, the `ByteSwapper<T>` member functions
`SwapWriteRangeFromSystemToBigEndian` and `SwapWriteRangeFromSystemToLittleEndian`
should just write the specified range to the output stream. (In that case,
byteswapping is not necessary.)

The original code did nothing, in that case. It did not swap, but it did not
write the range either.

Fixed by this commit.
  • Loading branch information
N-Dekker authored and dzenanz committed Oct 3, 2024
1 parent 8a5700a commit 58ff179
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Modules/Core/Common/include/itkByteSwapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ template <typename T>
void
ByteSwapper<T>::SwapWriteRangeFromSystemToBigEndian(const T * p, int num, std::ostream * fp)
{
if constexpr (m_SystemIsBigEndian)
if constexpr (m_SystemIsBigEndian || sizeof(T) == 1)
{
num *= sizeof(T);
fp->write(reinterpret_cast<const char *>(p), num);
Expand All @@ -74,8 +74,6 @@ ByteSwapper<T>::SwapWriteRangeFromSystemToBigEndian(const T * p, int num, std::o
{
switch (sizeof(T))
{
case 1:
return;
case 2:
Self::SwapWrite2Range(p, num, fp);
return;
Expand Down Expand Up @@ -118,12 +116,10 @@ template <typename T>
void
ByteSwapper<T>::SwapWriteRangeFromSystemToLittleEndian(const T * p, int num, std::ostream * fp)
{
if constexpr (m_SystemIsBigEndian)
if constexpr (m_SystemIsBigEndian && sizeof(T) > 1)
{
switch (sizeof(T))
{
case 1:
return;
case 2:
Self::SwapWrite2Range(p, num, fp);
return;
Expand Down

0 comments on commit 58ff179

Please sign in to comment.