summaryrefslogtreecommitdiff
path: root/src/md5sum.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-06-23 20:16:45 +0200
committerPaul Eggert <eggert@cs.ucla.edu>2016-06-23 20:18:03 +0200
commit818b2f48974298065a43a8a2d5355e4aaa65c09d (patch)
treec33bf70c1f67871a54e954b0bf3cd0c776babaae /src/md5sum.c
parenta3311c966e34f2d9f8aa6b1de31b211124803d02 (diff)
downloadcoreutils-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.c7
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);