summaryrefslogtreecommitdiff
path: root/src/paste.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/paste.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/paste.c')
-rw-r--r--src/paste.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/paste.c b/src/paste.c
index bf99fe028..7914aef12 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -465,7 +465,6 @@ int
main (int argc, char **argv)
{
int optc;
- bool ok;
char const *delim_arg = "\t";
initialize_main (&argc, &argv);
@@ -505,8 +504,12 @@ main (int argc, char **argv)
}
}
- if (optind == argc)
- argv[argc++] = bad_cast ("-");
+ int nfiles = argc - optind;
+ if (nfiles == 0)
+ {
+ argv[optind] = bad_cast ("-");
+ nfiles++;
+ }
if (collapse_escapes (delim_arg))
{
@@ -517,10 +520,8 @@ main (int argc, char **argv)
quotearg_n_style_colon (0, c_maybe_quoting_style, delim_arg));
}
- if (!serial_merge)
- ok = paste_parallel (argc - optind, &argv[optind]);
- else
- ok = paste_serial (argc - optind, &argv[optind]);
+ bool ok = ((serial_merge ? paste_serial : paste_parallel)
+ (nfiles, &argv[optind]));
free (delims);