Skip to content

Commit

Permalink
Fix loading from memory on sparc64
Browse files Browse the repository at this point in the history
This platform is big-endian (requires byte flipping) and has a signed `char` type. Prevent sign-expansion by casting the signed character type to `uint8_t`.
  • Loading branch information
karcherm authored and TinoDidriksen committed Feb 17, 2024
1 parent 9bed46c commit 7b07c0d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hfst-ol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ uint16_t read_uint16_flipping_endianness(FILE * f)
uint16_t read_uint16_flipping_endianness(char * raw)
{
uint16_t result = 0;
result |= *(raw + 1);
result |= static_cast<uint8_t>(*(raw + 1));
result <<= 8;
result |= *raw;
result |= static_cast<uint8_t>(*raw);
return result;
}

Expand All @@ -85,13 +85,13 @@ uint32_t read_uint32_flipping_endianness(FILE * f)
uint32_t read_uint32_flipping_endianness(char * raw)
{
uint32_t result = 0;
result |= *(raw + 3);
result |= static_cast<uint8_t>(*(raw + 3));
result <<= 8;
result |= *(raw + 2);
result |= static_cast<uint8_t>(*(raw + 2));
result <<= 8;
result |= *(raw + 1);
result |= static_cast<uint8_t>(*(raw + 1));
result <<= 8;
result |= *raw;
result |= static_cast<uint8_t>(*raw);
return result;
}

Expand Down

0 comments on commit 7b07c0d

Please sign in to comment.