Mercurial > hg > orthanc
diff Core/Images/PamReader.cpp @ 2807:6356e2ceb493
Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Sep 2018 15:58:26 +0200 |
parents | 5c18a22cb981 |
children | 2ca9cd064b15 |
line wrap: on
line diff
--- a/Core/Images/PamReader.cpp Tue Sep 04 15:07:40 2018 +0200 +++ b/Core/Images/PamReader.cpp Tue Sep 04 15:58:26 2018 +0200 @@ -209,7 +209,8 @@ throw OrthancException(ErrorCode_NotImplemented); } - if (Toolbox::DetectEndianness() == Endianness_Little && bytesPerChannel == 2) + if (Toolbox::DetectEndianness() == Endianness_Little && + bytesPerChannel == 2) { for (unsigned int h = 0; h < height; ++h) { @@ -217,7 +218,12 @@ for (unsigned int w = 0; w < GetWidth(); ++w, ++pixel) { - *pixel = htobe16(*pixel); + // memcpy() is necessary to avoid segmentation fault if the + // "pixel" pointer is not 16-bit aligned (which is the case + // if "offset" is an odd number). Check out issue #99: + // https://bitbucket.org/sjodogne/orthanc/issues/99 + uint16_t v = htobe16(*pixel); + memcpy(pixel, &v, sizeof(v)); } } }