summaryrefslogtreecommitdiff
path: root/src/split.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-04-09 20:48:29 +0000
committerJim Meyering <jim@meyering.net>2003-04-09 20:48:29 +0000
commitf05ad08d198a33deb8f7b5c7c1cd12631b17d9d5 (patch)
treef1147ab4e9cf0cf1d067aeb8d2ef073d58301b50 /src/split.c
parentc3e1712629f8cadb2ab937dfffbe249b60b173cd (diff)
downloadcoreutils-f05ad08d198a33deb8f7b5c7c1cd12631b17d9d5.tar.xz
(line_bytes_split): Arg is of type size_t, since
that's all that is supported for now. (main): Check for overflow in obsolescent line count option.
Diffstat (limited to 'src/split.c')
-rw-r--r--src/split.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/split.c b/src/split.c
index 261fd23ce..70a3d9ad7 100644
--- a/src/split.c
+++ b/src/split.c
@@ -291,18 +291,17 @@ lines_split (uintmax_t n_lines, char *buf, size_t bufsize)
/* Split into pieces that are as large as possible while still not more
than N_BYTES bytes, and are split on line boundaries except
where lines longer than N_BYTES bytes occur.
- FIXME: don't require a buffer of size N_BYTES, in case N_BYTES
- is very large. */
+ FIXME: Allow N_BYTES to be any uintmax_t value, and don't require a
+ buffer of size N_BYTES, in case N_BYTES is very large. */
static void
-line_bytes_split (uintmax_t n_bytes)
+line_bytes_split (size_t n_bytes)
{
size_t n_read;
char *bp;
int eof = 0;
size_t n_buffered = 0;
- size_t n = n_bytes;
- char *buf = (char *) xmalloc (n);
+ char *buf = (char *) xmalloc (n_bytes);
do
{
@@ -459,8 +458,15 @@ main (int argc, char **argv)
if (digits_optind != 0 && digits_optind != this_optind)
n_units = 0; /* More than one number given; ignore other. */
digits_optind = this_optind;
+ if (UINTMAX_MAX / 10 < n_units
+ || n_units * 10 + c - '0' < n_units * 10)
+ {
+ char buffer[INT_BUFSIZE_BOUND (uintmax_t)];
+ error (EXIT_FAILURE, 0,
+ _("line count option -%s%c... is too large"),
+ umaxtostr (n_units, buffer), c);
+ }
n_units = n_units * 10 + c - '0';
- /* FIXME: detect overflow, or remove this support altogether */
break;
case_GETOPT_HELP_CHAR;