diff options
author | Pádraig Brady <P@draigBrady.com> | 2023-03-15 13:57:37 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2023-03-15 14:05:38 +0000 |
commit | a8e6e627f1a1142ec9cb273cfadc3f9aa2aa412a (patch) | |
tree | fad43bc93ad36549f7581179ccbc6a2d345bd9c0 | |
parent | f1ff021247304698ae71892060330bcb91683d70 (diff) | |
download | coreutils-a8e6e627f1a1142ec9cb273cfadc3f9aa2aa412a.tar.gz |
cksum: fix --raw on 64 bit big endian systems
* src/sum.c (output_bsd): On sparc64 for example,
a crc of 0 was output due to casting an int variable
to uint16_t and thus operating on the wrong end of the variable.
Instead use explicit assignment to the narrower type
to ensure we get the appropriate data.
(output_sysv): Likewise.
Reported by Bruno Haible.
-rw-r--r-- | src/sum.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -197,7 +197,8 @@ output_bsd (char const *file, int binary_file, void const *digest, if (raw) { /* Output in network byte order (big endian). */ - uint16_t out_int = SWAP (*(uint16_t *)digest); + uint16_t out_int = *(int *)digest; + out_int = SWAP (out_int); fwrite (&out_int, 1, 16/8, stdout); return; } @@ -221,7 +222,8 @@ output_sysv (char const *file, int binary_file, void const *digest, if (raw) { /* Output in network byte order (big endian). */ - uint16_t out_int = SWAP (*(uint16_t *)digest); + uint16_t out_int = *(int *)digest; + out_int = SWAP (out_int); fwrite (&out_int, 1, 16/8, stdout); return; } |