]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: fix --raw on 64 bit big endian systems
authorPádraig Brady <P@draigBrady.com>
Wed, 15 Mar 2023 13:57:37 +0000 (13:57 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Mar 2023 14:05:38 +0000 (14:05 +0000)
* 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.

src/sum.c

index 5046bb3f0daf26f176a4941a78f56aa8a3bf3759..36464cacf10e3647efa95ec513f8353e3cd386c3 100644 (file)
--- a/src/sum.c
+++ b/src/sum.c
@@ -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;
     }