Skip to content

Commit

Permalink
Fix an endian issue and some ambiguous evaluation order
Browse files Browse the repository at this point in the history
  • Loading branch information
calc84maniac committed Jul 9, 2024
1 parent c43763f commit bc613e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ int main(int argc, char** argv)

data_t data;
data.resize(filesize + 2);
*(uint16_t*) &data[0] = filesize & 0xFFFFu;
data[0] = filesize & 0xFF;
data[1] = (filesize >> 8) & 0xFF;
in.read((char*) &data[2], filesize);
in.close();

Expand Down
4 changes: 3 additions & 1 deletion src/TIVarFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ namespace tivars
// Extends BinaryFile.
uint16_t get_two_bytes_swapped()
{
return (this->get_raw_byte() & 0xFF) + (this->get_raw_byte() << 8);
uint8_t low = this->get_raw_byte();
uint8_t high = this->get_raw_byte();
return low + (high << 8);
}

var_header_t header;
Expand Down

0 comments on commit bc613e9

Please sign in to comment.