NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/42143: A transformation without the cast
>Number: 42143
>Category: bin
>Synopsis: A transformation without the cast
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 01 06:50:00 +0000 2009
>Originator: Yamanishi Yasuyo
>Release: i386
>Organization:
Nara Women's University
>Environment:
NetBSD ayanamirei 4.0 NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:20:10 PST 2007
builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/GENERIC
i386
>Description:
Implicit cast from long to int may cause an integer overflow
especially with 64-bit CPU. A wrapper function can fix it.
>How-To-Repeat:
>Fix:
--- kill2.c 2009-09-30 23:58:53.000000000 +0900
+++ kill.c 2009-09-25 23:00:33.000000000 +0900
@@ -64,6 +64,7 @@
static void printsignals(FILE *);
static int signame_to_signum(char *);
static void usage(void);
+static strto_int(const char*,char**,int);
int main(int, char *[]);
int
@@ -87,7 +88,7 @@
if (argc == 1) {
if (isdigit((unsigned char)**argv) == 0)
usage();
- numsig = strtol(*argv, &ep, 10);
+ numsig = strto_int(*argv, &ep, 10);
if (*ep != '\0') {
errx(EXIT_FAILURE, "illegal signal number: %s",
*argv);
@@ -122,7 +123,7 @@
if ((numsig = signame_to_signum(sn)) < 0)
nosig(sn);
} else if (isdigit((unsigned char)*sn)) {
- numsig = strtol(sn, &ep, 10);
+ numsig = strto_int(sn, &ep, 10);
if (*ep) {
errx(EXIT_FAILURE, "illegal signal number: %s",
sn);
@@ -151,7 +152,7 @@
} else
#endif
{
- pid = strtol(*argv, &ep, 10);
+ pid = strto_int(*argv, &ep, 10);
if (!**argv || *ep) {
warnx("illegal process id: %s", *argv);
errors = 1;
@@ -240,4 +241,23 @@
getprogname(), getprogname(), getprogname(),
getprogname());
exit(1);
/* NOTREACHED */
-}
\ No newline at end of file
+}
+
+static int
+strto_int(const char * nptr ,char ** end ,int base)
+{
+ int tmp;
+ long sig,check;
+
+ sig = strtol(nptr, end, base);
+ tmp = (int) sig;
+ check = (long) tmp;
+
+ if( check != sig ){
+ warnx("Overflow occered in the cast (from long to int) .");
+ }
+
+ return tmp;
+}
+
+
Home |
Main Index |
Thread Index |
Old Index