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 <ctype.h>' must be cast to 'unsigned char', not to 'int' [342] While here, fix a typo in an error message.
This commit is contained in:
parent
c59c199782
commit
fea9876874
|
@ -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.
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__COPYRIGHT("@(#) Copyright (c) 2008 \
|
__COPYRIGHT("@(#) Copyright (c) 2008 \
|
||||||
The NetBSD Foundation, inc. All rights reserved.");
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -42,6 +42,7 @@ __RCSID("$NetBSD: tabs.c,v 1.5 2019/02/01 08:29:04 mrg Exp $");
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -84,6 +85,7 @@ main(int argc, char **argv)
|
||||||
char *term, *arg, *token, *end, *tabs = NULL, *p;
|
char *term, *arg, *token, *end, *tabs = NULL, *p;
|
||||||
const char *cr, *spec = NULL;
|
const char *cr, *spec = NULL;
|
||||||
int i, n, inc = 8, stops[NSTOPS], nstops, last, cols, margin = 0;
|
int i, n, inc = 8, stops[NSTOPS], nstops, last, cols, margin = 0;
|
||||||
|
long num = 0;
|
||||||
size_t j;
|
size_t j;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
|
|
||||||
|
@ -97,10 +99,12 @@ main(int argc, char **argv)
|
||||||
margin = 10;
|
margin = 10;
|
||||||
else {
|
else {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
margin = strtol(arg, &end, 10);
|
num = strtol(arg, &end, 10);
|
||||||
if (errno != 0 || *end != '\0' || margin < 0)
|
if (errno != 0 || *end != '\0' ||
|
||||||
|
num < 0 || num > INT_MAX)
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
"%s: invalid margin", arg);
|
"%s: invalid margin", arg);
|
||||||
|
margin = (int)num;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -122,10 +126,10 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isdigit((int)arg[0])) {
|
if (isdigit((unsigned char)arg[0])) {
|
||||||
if (arg[1] != '\0')
|
if (arg[1] != '\0')
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
"%s: invalid increament", arg);
|
"%s: invalid increment", arg);
|
||||||
inc = arg[0] - '0';
|
inc = arg[0] - '0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -154,9 +158,10 @@ main(int argc, char **argv)
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
"too many tab stops (max %d)", NSTOPS);
|
"too many tab stops (max %d)", NSTOPS);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
n = strtol(token, &end, 10);
|
num = strtol(token, &end, 10);
|
||||||
if (errno != 0 || *end != '\0' || n <= 0)
|
if (errno != 0 || *end != '\0' || num <= 0 || num > INT_MAX)
|
||||||
errx(EXIT_FAILURE, "%s: invalid tab stop", token);
|
errx(EXIT_FAILURE, "%s: invalid tab stop", token);
|
||||||
|
n = (int)num;
|
||||||
if (*token == '+') {
|
if (*token == '+') {
|
||||||
if (nstops == 0)
|
if (nstops == 0)
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
|
@ -203,9 +208,10 @@ main(int argc, char **argv)
|
||||||
term = getenv("COLUMNS");
|
term = getenv("COLUMNS");
|
||||||
if (term != NULL) {
|
if (term != NULL) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
cols = strtol(term, &end, 10);
|
num = strtol(term, &end, 10);
|
||||||
if (errno != 0 || *end != '\0' || cols < 0)
|
if (errno == 0 && *end == '\0' &&
|
||||||
cols = 0;
|
0 <= cols && cols <= INT_MAX)
|
||||||
|
cols = (int)num;
|
||||||
}
|
}
|
||||||
if (cols == 0) {
|
if (cols == 0) {
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
|
||||||
|
|
Loading…
Reference in New Issue