delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/28/15:44:31

Date: Wed, 28 Feb 2001 22:39:55 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: rafael AT geninfor DOT com
Message-Id: <1438-Wed28Feb2001223955+0200-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
CC: djgpp AT delorie DOT com
In-reply-to: <3a9cf8f1$1@filemon.telecable.es> (rafael@geninfor.com)
Subject: Re: atoi() with 8 bit chars
References: <3a9cf8f1$1 AT filemon DOT telecable DOT es>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: "Rafael Garcia" <rafael AT geninfor DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Wed, 28 Feb 2001 14:09:30 +0100
> 
> Hello all. I have found a bug in one of my functions due to an extrange
> behaviour of atoi() with bad data introduced by a user in a date. If you
> give 8-bit chars to atoi, it does not return cero. Does anybody know why?

It's a bug in the library; thanks for reporting it.  Here's a patch
for the strtol function which is responsible for this bug:

--- src/libc/ansi/stdlib/strtol.c~0	Wed Aug  4 21:58:22 1999
+++ src/libc/ansi/stdlib/strtol.c	Wed Feb 28 22:36:06 2001
@@ -60,7 +60,7 @@ strtol(const char *nptr, char **endptr, 
   cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
   cutlim = cutoff % (unsigned long)base;
   cutoff /= (unsigned long)base;
-  for (acc = 0, any = 0;; c = *s++, c &= 0xff)
+  for (acc = 0, any = 0, c &= 0xff;; c = *s++, c &= 0xff)
   {
     if (isdigit(c))
       c -= '0';

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019