diff options
author | Jim Meyering <jim@meyering.net> | 2004-03-31 08:25:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-03-31 08:25:04 +0000 |
commit | 35e3e7e672ad918a8c192873a5d08e986e262513 (patch) | |
tree | 129558ccbcc89f7955492a44337b38603f7fc50a /src | |
parent | 75e376362329c5d42777bcc195b02f75c06c3f8e (diff) | |
download | coreutils-35e3e7e672ad918a8c192873a5d08e986e262513.tar.xz |
Specifying an invalid --width=N (-w) or --gap-size=N (-g)
would not elicit an error.
Include "xstrtol.h" and "quotearg.h".
(main): Don't use atoi. Use xstrtoul instead.
Diffstat (limited to 'src')
-rw-r--r-- | src/ptx.c | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -1,5 +1,5 @@ /* Permuted index for GNU, with keywords in their context. - Copyright (C) 1990, 1991, 1993, 1998-2003 Free Software Foundation, Inc. + Copyright (C) 1990, 1991, 1993, 1998-2004 Free Software Foundation, Inc. François Pinard <pinard@iro.umontreal.ca>, 1988. This program is free software; you can redistribute it and/or modify @@ -27,7 +27,9 @@ #include "argmatch.h" #include "diacrit.h" #include "error.h" +#include "quotearg.h" #include "regex.h" +#include "xstrtol.h" /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "ptx" @@ -2027,8 +2029,15 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"), break; case 'g': - gap_size = atoi (optarg); - break; + { + unsigned long int tmp_ulong; + if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK + || ! (0 < tmp_ulong && tmp_ulong <= INT_MAX)) + error (EXIT_FAILURE, 0, _("invalid gap width: %s"), + quotearg (optarg)); + gap_size = tmp_ulong; + break; + } case 'i': ignore_file = optarg; @@ -2048,6 +2057,15 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"), case 'w': line_width = atoi (optarg); + { + unsigned long int tmp_ulong; + if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK + || ! (0 < tmp_ulong && tmp_ulong <= INT_MAX)) + error (EXIT_FAILURE, 0, _("invalid line width: %s"), + quotearg (optarg)); + line_width = tmp_ulong; + break; + } break; case 'A': |