Skip to content

Commit

Permalink
cast signed chars to unsigned before bitwise left shift in Xdr::read()
Browse files Browse the repository at this point in the history
Signed-off-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
cary-ilm committed Aug 9, 2020
1 parent 3cf874c commit 09eadd1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions OpenEXR/IlmImf/ImfXdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ read (T &in, signed short &v)

readSignedChars<S> (in, b, 2);

v = (b[0] & 0x00ff) |
(b[1] << 8);
v = (static_cast <unsigned char> (b[0]) & 0x00ff) |
(static_cast <unsigned char> (b[1]) << 8);
}


Expand All @@ -675,10 +675,10 @@ read (T &in, signed int &v)

readSignedChars<S> (in, b, 4);

v = (b[0] & 0x000000ff) |
((b[1] << 8) & 0x0000ff00) |
((b[2] << 16) & 0x00ff0000) |
(b[3] << 24);
v = (static_cast <unsigned char> (b[0]) & 0x000000ff) |
((static_cast <unsigned char> (b[1]) << 8) & 0x0000ff00) |
((static_cast <unsigned char> (b[2]) << 16) & 0x00ff0000) |
(static_cast <unsigned char> (b[3]) << 24);
}


Expand Down Expand Up @@ -707,10 +707,10 @@ read (T &in, signed long &v)

#if LONG_MAX == 2147483647

v = (b[0] & 0x000000ff) |
((b[1] << 8) & 0x0000ff00) |
((b[2] << 16) & 0x00ff0000) |
(b[3] << 24);
v = (static_cast <unsigned char> (b[0]) & 0x000000ff) |
((static_cast <unsigned char> (b[1]) << 8) & 0x0000ff00) |
((static_cast <unsigned char> (b[2]) << 16) & 0x00ff0000) |
(static_cast <unsigned char> (b[3]) << 24);

if (( b[4] || b[5] || b[6] || b[7]) &&
(~b[4] || ~b[5] || ~b[6] || ~b[7]))
Expand Down

0 comments on commit 09eadd1

Please sign in to comment.