Module Name:src
Committed By: rillig
Date: Fri Aug 27 18:28:41 UTC 2021
Modified Files:
src/usr.bin/tabs: tabs.c
Log Message:
tabs: fix lint warnings about ctype functions and conversions
lines 100, 157, 206: conversion from 'long' to 'int' may lose accuracy
[132]
line 125: warning: argument to 'function from ' must be cast to
'unsigned char', not to 'int' [342]
While here, fix a typo in an error message.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/tabs/tabs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/tabs/tabs.c
diff -u src/usr.bin/tabs/tabs.c:1.5 src/usr.bin/tabs/tabs.c:1.6
--- src/usr.bin/tabs/tabs.c:1.5 Fri Feb 1 08:29:04 2019
+++ src/usr.bin/tabs/tabs.c Fri Aug 27 18:28:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tabs.c,v 1.5 2019/02/01 08:29:04 mrg Exp $ */
+/* $NetBSD: tabs.c,v 1.6 2021/08/27 18:28:41 rillig Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 2008 \
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: tabs.c,v 1.5 2019/02/01 08:29:04 mrg Exp $");
+__RCSID("$NetBSD: tabs.c,v 1.6 2021/08/27 18:28:41 rillig Exp $");
#endif /* not lint */
#include
@@ -42,6 +42,7 @@ __RCSID("$NetBSD: tabs.c,v 1.5 2019/02/0
#include
#include
#include
+#include
#include
#include
#include
@@ -84,6 +85,7 @@ main(int argc, char **argv)
char *term, *arg, *token, *end, *tabs = NULL, *p;
const char *cr, *spec = NULL;
int i, n, inc = 8, stops[NSTOPS], nstops, last, cols, margin = 0;
+ long num = 0;
size_t j;
struct winsize ws;
@@ -97,10 +99,12 @@ main(int argc, char **argv)
margin = 10;
else {
errno = 0;
-margin = strtol(arg, , 10);
-if (errno != 0 || *end != '\0' || margin < 0)
+num = strtol(arg, , 10);
+if (errno != 0 || *end != '\0' ||
+num < 0 || num > INT_MAX)
errx(EXIT_FAILURE,
"%s: invalid margin", arg);
+margin = (int)num;
}
continue;
}
@@ -122,10 +126,10 @@ main(int argc, char **argv)
usage();
continue;
}
- if (isdigit((int)arg[0])) {
+ if (isdigit((unsigned char)arg[0])) {
if (arg[1] != '\0')
errx(EXIT_FAILURE,
- "%s: invalid increament", arg);
+ "%s: invalid increment", arg);
inc = arg[0] - '0';
continue;
}
@@ -154,9 +158,10 @@ main(int argc, char **argv)
errx(EXIT_FAILURE,
"too many tab stops (max %d)", NSTOPS);
errno = 0;
- n = strtol(token, , 10);
- if (errno != 0 || *end != '\0' || n <= 0)
+ num = strtol(token, , 10);
+ if (errno != 0 || *end != '\0' || num <= 0 || num > INT_MAX)
errx(EXIT_FAILURE, "%s: invalid tab stop", token);
+ n = (int)num;
if (*token == '+') {
if (nstops == 0)
errx(EXIT_FAILURE,
@@ -203,9 +208,10 @@ main(int argc, char **argv)
term = getenv("COLUMNS");
if (term != NULL) {
errno = 0;
- cols = strtol(term, , 10);
- if (errno != 0 || *end != '\0' || cols < 0)
-cols = 0;
+ num = strtol(term, , 10);
+ if (errno == 0 && *end == '\0' &&
+ 0 <= cols && cols <= INT_MAX)
+cols = (int)num;
}
if (cols == 0) {
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, ) == 0)