Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
2806:4fdb25c5df9c | 2807:6356e2ceb493 |
---|---|
207 bytesPerChannel != 2) | 207 bytesPerChannel != 2) |
208 { | 208 { |
209 throw OrthancException(ErrorCode_NotImplemented); | 209 throw OrthancException(ErrorCode_NotImplemented); |
210 } | 210 } |
211 | 211 |
212 if (Toolbox::DetectEndianness() == Endianness_Little && bytesPerChannel == 2) | 212 if (Toolbox::DetectEndianness() == Endianness_Little && |
213 bytesPerChannel == 2) | |
213 { | 214 { |
214 for (unsigned int h = 0; h < height; ++h) | 215 for (unsigned int h = 0; h < height; ++h) |
215 { | 216 { |
216 uint16_t* pixel = reinterpret_cast<uint16_t*>(GetRow(h)); | 217 uint16_t* pixel = reinterpret_cast<uint16_t*>(GetRow(h)); |
217 | 218 |
218 for (unsigned int w = 0; w < GetWidth(); ++w, ++pixel) | 219 for (unsigned int w = 0; w < GetWidth(); ++w, ++pixel) |
219 { | 220 { |
220 *pixel = htobe16(*pixel); | 221 // memcpy() is necessary to avoid segmentation fault if the |
222 // "pixel" pointer is not 16-bit aligned (which is the case | |
223 // if "offset" is an odd number). Check out issue #99: | |
224 // https://bitbucket.org/sjodogne/orthanc/issues/99 | |
225 uint16_t v = htobe16(*pixel); | |
226 memcpy(pixel, &v, sizeof(v)); | |
221 } | 227 } |
222 } | 228 } |
223 } | 229 } |
224 } | 230 } |
225 | 231 |