]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(decode_switches): Replace two more atoi uses with xstrtol.
authorJim Meyering <jim@meyering.net>
Sun, 21 Apr 1996 04:45:12 +0000 (04:45 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 21 Apr 1996 04:45:12 +0000 (04:45 +0000)
src/ls.c

index 5f56e857e309b70f6d0e3572f2477d65b3ff08ca..ad4e69132014bd33a4d6f4ba1f54b2351c9f3580 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -727,10 +727,10 @@ decode_switches (int argc, char **argv)
   }
 #endif
 
-  /* TABSIZE is not POSIX-approved.
+  /* Using the TABSIZE environment variable is not POSIX-approved.
      Ignore it when POSIXLY_CORRECT is set.  */
   tabsize = 8;
-  if (getenv ("POSIXLY_CORRECT") == 0 && (p = getenv ("TABSIZE")))
+  if (!getenv ("POSIXLY_CORRECT") && (p = getenv ("TABSIZE")))
     {
       if (xstrtol (p, NULL, 0, &tmp_long, NULL) == LONGINT_OK
          && 0 < tmp_long && tmp_long <= INT_MAX)
@@ -839,9 +839,10 @@ decode_switches (int argc, char **argv)
          break;
 
        case 'w':
-         line_length = atoi (optarg);
-         if (line_length < 1)
+         if (xstrtol (optarg, NULL, 0, &tmp_long, NULL) != LONGINT_OK
+             || tmp_long <= 0 || tmp_long > INT_MAX)
            error (1, 0, _("invalid line width: %s"), optarg);
+         line_length = (int) tmp_long;
          break;
 
        case 'x':
@@ -901,9 +902,10 @@ decode_switches (int argc, char **argv)
          break;
 
        case 'T':
-         tabsize = atoi (optarg);
-         if (tabsize < 1)
+         if (xstrtol (optarg, NULL, 0, &tmp_long, NULL) != LONGINT_OK
+             || tmp_long <= 0 || tmp_long > INT_MAX)
            error (1, 0, _("invalid tab size: %s"), optarg);
+         tabsize = (int) tmp_long;
          break;
 
        case 'U':