diff options
author | Jim Meyering <jim@meyering.net> | 2005-10-23 15:29:25 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-10-23 15:29:25 +0000 |
commit | 1974bccc56d2826c344497d63c1b2344fa1a0df8 (patch) | |
tree | 87f8ec925466271ca59023c2f478af9cb1a3b5a6 | |
parent | 5528d926f6ef4c596482df5004d86ccdbefb6756 (diff) | |
download | coreutils-1974bccc56d2826c344497d63c1b2344fa1a0df8.tar.xz |
(digest_check, main): Use ptr_align rather than
a dangerous pointer-value-to-`unsigned' cast.
-rw-r--r-- | src/md5sum.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/md5sum.c b/src/md5sum.c index 7cf2783e8..cb86e355a 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -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 " |