Skip to content

Commit

Permalink
Silence -Werror=format-truncation
Browse files Browse the repository at this point in the history
Ideally we wanted to use __builtin_assume() or [[assume]], but the former
is available only in clang and the latter is in C++23.

Fixes rui314/mold#966
  • Loading branch information
rui314 committed Jan 18, 2023
1 parent f4b0596 commit 54ab1ec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion common/tar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ struct UstarHeader {
int sum = 0;
for (i64 i = 0; i < sizeof(*this); i++)
sum += ((u8 *)this)[i];
assert(sum < 01000000);

// We need to convince the compiler that sum isn't too big to silence
// -Werror=format-truncation.
if (01'000'000 < sum)
__builtin_unreachable();

snprintf(checksum, sizeof(checksum), "%06o", sum);
}

Expand Down

0 comments on commit 54ab1ec

Please sign in to comment.