Skip to content

Commit

Permalink
cast signed chars to unsigned longs before left shift in read of sign…
Browse files Browse the repository at this point in the history
…ed long

Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
cary-ilm committed Aug 9, 2020
1 parent 02e1ac5 commit 37e16a8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions OpenEXR/IlmImf/ImfXdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,10 @@ read (T &in, signed long &v)

#if LONG_MAX == 2147483647

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);
v = (static_cast <unsigned long> (b[0]) & 0x000000ff) |
((static_cast <unsigned long> (b[1]) << 8) & 0x0000ff00) |
((static_cast <unsigned long> (b[2]) << 16) & 0x00ff0000) |
(static_cast <unsigned long> (b[3]) << 24);

if (( b[4] || b[5] || b[6] || b[7]) &&
(~b[4] || ~b[5] || ~b[6] || ~b[7]))
Expand All @@ -721,14 +721,14 @@ read (T &in, signed long &v)

#elif LONG_MAX == 9223372036854775807L

v = ((long) b[0] & 0x00000000000000ff) |
(((long) b[1] << 8) & 0x000000000000ff00) |
(((long) b[2] << 16) & 0x0000000000ff0000) |
(((long) b[3] << 24) & 0x00000000ff000000) |
(((long) b[4] << 32) & 0x000000ff00000000) |
(((long) b[5] << 40) & 0x0000ff0000000000) |
(((long) b[6] << 48) & 0x00ff000000000000) |
((long) b[7] << 56);
v = (static_cast <unsigned long> (b[0]) & 0x00000000000000ff) |
((static_cast <unsigned long> (b[1]) << 8) & 0x000000000000ff00) |
((static_cast <unsigned long> (b[2]) << 16) & 0x0000000000ff0000) |
((static_cast <unsigned long> (b[3]) << 24) & 0x00000000ff000000) |
((static_cast <unsigned long> (b[4]) << 32) & 0x000000ff00000000) |
((static_cast <unsigned long> (b[5]) << 40) & 0x0000ff0000000000) |
((static_cast <unsigned long> (b[6]) << 48) & 0x00ff000000000000) |
(static_cast <unsigned long> (b[7]) << 56);

#else

Expand Down

0 comments on commit 37e16a8

Please sign in to comment.