summaryrefslogtreecommitdiff
path: root/src/cut.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-26 09:12:30 +0000
committerJim Meyering <jim@meyering.net>2003-07-26 09:12:30 +0000
commit421680e11c620750a294c229f028098619c8c470 (patch)
treebfb8b24373020048953c7668e7faa95997eabf1a /src/cut.c
parentcab4bde6e1f2ac125859f605a2e95109c4aa3e47 (diff)
downloadcoreutils-421680e11c620750a294c229f028098619c8c470.tar.xz
(set_fields): Detect overflow properly.
Diffstat (limited to 'src/cut.c')
-rw-r--r--src/cut.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cut.c b/src/cut.c
index f14eea890..aad951027 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -400,7 +400,7 @@ set_fields (const char *fieldstr)
}
else if (ISDIGIT (*fieldstr))
{
- unsigned int prev;
+ unsigned int new_v;
/* Record beginning of digit string, in case we have to
complain about it. */
static char const *num_start;
@@ -409,9 +409,8 @@ set_fields (const char *fieldstr)
in_digits = true;
/* Detect overflow. */
- prev = value;
- value = 10 * value + *fieldstr - '0';
- if (value < prev)
+ new_v = 10 * value + *fieldstr - '0';
+ if (UINT_MAX / 10 < value || new_v < value * 10)
{
/* In case the user specified -c4294967296-22,
complain only about the first number. */
@@ -427,6 +426,8 @@ set_fields (const char *fieldstr)
free (bad_num);
exit (EXIT_FAILURE);
}
+ value = new_v;
+
fieldstr++;
}
else