From owner-freebsd-current@FreeBSD.ORG Sun Jan 23 18:59:01 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8175116A4CE for ; Sun, 23 Jan 2005 18:59:01 +0000 (GMT) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id AE18643D39 for ; Sun, 23 Jan 2005 18:59:00 +0000 (GMT) (envelope-from keramida@freebsd.org) Received: from gothmog.gr (patr530-a056.otenet.gr [212.205.215.56]) j0NIwvFp005370; Sun, 23 Jan 2005 20:58:58 +0200 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.1/8.13.1) with ESMTP id j0NIwtHu051643; Sun, 23 Jan 2005 20:58:55 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from giorgos@localhost) by gothmog.gr (8.13.1/8.13.1/Submit) id j0NEUORs042838; Sun, 23 Jan 2005 16:30:24 +0200 (EET) (envelope-from keramida@freebsd.org) Date: Sun, 23 Jan 2005 16:30:24 +0200 From: Giorgos Keramidas To: Andrey Chernov , Joerg Wunsch , current@freebsd.org Message-ID: <20050123143024.GA28604@gothmog.gr> References: <20050121201400.GQ30862@uriah.heep.sax.de> <20050121221156.GA21459@nagual.pp.ru> <20050120192324.GA30862@uriah.heep.sax.de> <20050120205501.GA69123@nagual.pp.ru> <20050120211449.GC30862@uriah.heep.sax.de> <20050120214406.GA70088@nagual.pp.ru> <20050120222137.GE30862@uriah.heep.sax.de> <20050121230949.GA34313@VARK.MIT.EDU> <20050122113015.GV30862@uriah.heep.sax.de> <20050122171743.GB39943@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050122171743.GB39943@nagual.pp.ru> Subject: Re: Implementation errors in strtol() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jan 2005 18:59:01 -0000 On 2005-01-22 20:17, Andrey Chernov wrote: > On Sat, Jan 22, 2005 at 12:30:15PM +0100, Joerg Wunsch wrote: > > Nope. Just think about it: code which doesn't take this feature into > > account needs to check for conversion errors by means of verifying > > endptr. It simply wouldn't care about errno at all, except for > > possibly checking for overflows -- which only needs to be verified > > after it is already clear from checking endptr that the conversion was > > OK. Thus, errno could not possibly be EINVAL anymore in that case. > > I know portable way of doing that. You describe one case from two. The > another case you miss is more indirect: portable application which set > "errno = 0" before calling strtol() to detect overflows (it is only > method) even after checking that endptr moved can't check just > > if (errno) { ... } > > but must check > > if (errno == ERANGE) { ... } > > instead. Hi Andrey, Why would checking for explicit errno values be necessary? IIRC, after a few emails I had exchanged with Dima Dorfman a few months ago, checking for endptr *and* errno != 0 was ok. Something like this was what we had come up with: char *optarg, *endp; long val; errno = 0; val = strtol(optarg, &endp, 0); if (*ep != '\0' && *optarg != '\0') err(1, "Partially converted string: %s", optarg); if (errno != 0) err(1, "Other error"); > That is, what I mean, saying that portable application should consider > _both_ cases. Just to clarify this a bit, when you say "both cases" you mean "both ERANGE and EINVAL", or "both endp/nptr _and_ errno being zero (because it was explicitly set to zero before calling strtol())"? - Giorgos