Mercurial > hg > orthanc
diff Core/Images/PamWriter.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 | 4e43e67f8ecf |
line wrap: on
line diff
--- a/Core/Images/PamWriter.cpp Tue Sep 04 15:07:40 2018 +0200 +++ b/Core/Images/PamWriter.cpp Tue Sep 04 15:58:26 2018 +0200 @@ -130,7 +130,13 @@ for (unsigned int w = 0; w < width * channelCount; ++w) { - *q = htobe16(*p); + // 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(*p); + memcpy(q, &v, sizeof(uint16_t)); + p++; q++; }