diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-06-23 20:16:45 +0200 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-06-23 20:18:03 +0200 |
commit | 818b2f48974298065a43a8a2d5355e4aaa65c09d (patch) | |
tree | c33bf70c1f67871a54e954b0bf3cd0c776babaae /src/md5sum.c | |
parent | a3311c966e34f2d9f8aa6b1de31b211124803d02 (diff) | |
download | coreutils-818b2f48974298065a43a8a2d5355e4aaa65c09d.tar.xz |
maint: work even if argc == INT_MAX
GCC 7 warned about undefined behavior in this unlikely case.
Problem reported by Jim Meyering in: http://bugs.gnu.org/23825
* src/md5sum.c (main):
* src/paste.c (main):
* src/yes.c (main):
Avoid undefined behavior when argc == INT_MAX.
Diffstat (limited to 'src/md5sum.c')
-rw-r--r-- | src/md5sum.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/md5sum.c b/src/md5sum.c index 39132e340..3ed1b65e7 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -864,12 +864,13 @@ main (int argc, char **argv) if (!O_BINARY && binary < 0) binary = 0; + char **operand_lim = argv + argc; if (optind == argc) - argv[argc++] = bad_cast ("-"); + *operand_lim++ = bad_cast ("-"); - for (; optind < argc; ++optind) + for (char **operandp = argv + optind; operandp < operand_lim; operandp++) { - char *file = argv[optind]; + char *file = *operandp; if (do_check) ok &= digest_check (file); |