Skip to content

Commit

Permalink
Fix precedence error in put_le.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHarte committed Feb 26, 2025
1 parent 1f6f30a commit ddccb94
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Storage/FileHolder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class FileHolder final {
*/
template <typename IntT, size_t bytes = 0>
void put_le(IntT value) {
for(size_t c = 0; c < bytes ? bytes : sizeof(IntT); c++) {
constexpr auto size = bytes ? bytes : sizeof(IntT);
for(size_t c = 0; c < size; c++) {
put8(uint8_t(value));
value >>= 8;
}
Expand All @@ -75,11 +76,11 @@ class FileHolder final {
*/
template <typename IntT, size_t bytes = 0>
IntT get_le() {
constexpr auto length = bytes ? bytes : sizeof(IntT);
constexpr auto size = bytes ? bytes : sizeof(IntT);
IntT result{};
for(size_t c = 0; c < length; c++) {
for(size_t c = 0; c < size; c++) {
result >>= 8;
result |= IntT(get8() << ((length - 1) * 8));
result |= IntT(get8() << ((size - 1) * 8));
}
return result;
}
Expand All @@ -89,9 +90,9 @@ class FileHolder final {
*/
template <typename IntT, size_t bytes = 0>
IntT get_be() {
constexpr auto length = bytes ? bytes : sizeof(IntT);
constexpr auto size = bytes ? bytes : sizeof(IntT);
IntT result{};
for(size_t c = 0; c < length; c++) {
for(size_t c = 0; c < size; c++) {
result <<= 8;
result |= get8();
}
Expand Down

0 comments on commit ddccb94

Please sign in to comment.