summaryrefslogtreecommitdiff
path: root/src/uniq.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-12-15 03:20:40 +0000
committerJim Meyering <jim@meyering.net>1995-12-15 03:20:40 +0000
commit208fa17ad01c21f5ad3d328a6b85e05ad5e4c9c2 (patch)
tree1d236b9e5e8467d3517d34e75f0245ec72ea552f /src/uniq.c
parent5a1b7d267a31d811cf53474d92555e85bf2c8f11 (diff)
downloadcoreutils-208fa17ad01c21f5ad3d328a6b85e05ad5e4c9c2.tar.xz
(main): Use xstrtol instead of atoi.
Diffstat (limited to 'src/uniq.c')
-rw-r--r--src/uniq.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/uniq.c b/src/uniq.c
index aa2b4e441..2d261de50 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -25,10 +25,24 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+
+#ifndef UINT_MAX
+# define UINT_MAX ((unsigned int) ~(unsigned int) 0)
+#endif
+
+#ifndef INT_MAX
+# define INT_MAX ((int) (UINT_MAX >> 1))
+#endif
+
#include "system.h"
#include "linebuffer.h"
#include "version.h"
#include "error.h"
+#include "xstrtol.h"
/* Undefine, to avoid warning about redefinition on some systems. */
#undef min
@@ -302,11 +316,25 @@ main (int argc, char **argv)
break;
case 'f': /* Like '-#'. */
- skip_fields = atoi (optarg);
+ {
+ long int tmp_long;
+ if (xstrtol (optarg, NULL, 10, &tmp_long, NULL) != LONGINT_OK
+ || tmp_long <= 0 || tmp_long > INT_MAX)
+ error (1, 0, _("invalid number of fields to skip: `%s'"),
+ optarg);
+ skip_fields = (int) tmp_long;
+ }
break;
case 's': /* Like '+#'. */
- skip_chars = atoi (optarg);
+ {
+ long int tmp_long;
+ if (xstrtol (optarg, NULL, 10, &tmp_long, NULL) != LONGINT_OK
+ || tmp_long <= 0 || tmp_long > INT_MAX)
+ error (1, 0, _("invalid number of bytes to skip: `%s'"),
+ optarg);
+ skip_chars = (int) tmp_long;
+ }
break;
case 'u':
@@ -314,7 +342,14 @@ main (int argc, char **argv)
break;
case 'w':
- check_chars = atoi (optarg);
+ {
+ long int tmp_long;
+ if (xstrtol (optarg, NULL, 10, &tmp_long, NULL) != LONGINT_OK
+ || tmp_long <= 0 || tmp_long > INT_MAX)
+ error (1, 0, _("invalid number of bytes to compare: `%s'"),
+ optarg);
+ check_chars = (int) tmp_long;
+ }
break;
default:
@@ -336,7 +371,15 @@ main (int argc, char **argv)
/* Interpret non-option arguments with leading `+' only
if we haven't seen `--'. */
while (optind < argc && argv[optind][0] == '+')
- skip_chars = atoi (argv[optind++]);
+ {
+ char *opt_str = argv[optind++];
+ long int tmp_long;
+ if (xstrtol (opt_str, NULL, 10, &tmp_long, NULL) != LONGINT_OK
+ || tmp_long <= 0 || tmp_long > INT_MAX)
+ error (1, 0, _("invalid number of bytes to compare: `%s'"),
+ opt_str);
+ skip_chars = (int) tmp_long;
+ }
}
if (optind < argc)