]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(digest_check, main): Use ptr_align rather than
authorJim Meyering <jim@meyering.net>
Sun, 23 Oct 2005 15:29:25 +0000 (15:29 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 23 Oct 2005 15:29:25 +0000 (15:29 +0000)
a dangerous pointer-value-to-`unsigned' cast.

src/md5sum.c

index 7cf2783e8a60e0978e523e9ac8a2700924615379..cb86e355ad390f96a2ebee82f18b6121b0b86fa2 100644 (file)
@@ -426,17 +426,14 @@ digest_check (const char *checkfile_name)
   uintmax_t n_properly_formatted_lines = 0;
   uintmax_t n_mismatched_checksums = 0;
   uintmax_t n_open_or_read_failures = 0;
-  unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES+DIGEST_ALIGN];
-  unsigned char *bin_buffer;
+  unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN];
+  /* Make sure bin_buffer is properly aligned. */
+  unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN);
   uintmax_t line_number;
   char *line;
   size_t line_chars_allocated;
   bool is_stdin = STREQ (checkfile_name, "-");
 
-  /* Make sure bin_buffer is properly aligned. */
-  bin_buffer = bin_buffer_unaligned
-    + ((unsigned)DIGEST_ALIGN - ((unsigned)bin_buffer_unaligned))%DIGEST_ALIGN;
-
   if (is_stdin)
     {
       have_read_stdin = true;
@@ -599,7 +596,8 @@ int
 main (int argc, char **argv)
 {
   unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES+DIGEST_ALIGN];
-  unsigned char *bin_buffer;
+  /* Make sure bin_buffer is properly aligned. */
+  unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN);
   bool do_check = false;
   int opt;
   bool ok = true;
@@ -643,10 +641,6 @@ main (int argc, char **argv)
   min_digest_line_length = MIN_DIGEST_LINE_LENGTH;
   digest_hex_bytes = DIGEST_HEX_BYTES;
 
-  /* Make sure bin_buffer is properly aligned. */
-  bin_buffer = bin_buffer_unaligned
-    + ((unsigned)DIGEST_ALIGN - ((unsigned)bin_buffer_unaligned))%DIGEST_ALIGN;
-
   if (0 <= binary && do_check)
     {
       error (0, 0, _("the --binary and --text options are meaningless when "