Date: Fri, 30 Jul 2004 07:30:25 GMT From: SAKUMA takayuki <takayuki@finet.fujitsu.com> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/69788: The processing result of strtoul() cannot judge whether it is an error. Message-ID: <200407300730.i6U7UP3O069454@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/69788; it has been noted by GNATS. From: SAKUMA takayuki <takayuki@finet.fujitsu.com> To: sos22@cantab.net Cc: freebsd-gnats-submit@FreeBSD.org, sos22@srcf.ucam.org Subject: Re: misc/69788: The processing result of strtoul() cannot judge whether it is an error. Date: Fri, 30 Jul 2004 16:24:42 +0900 (JST) > In my tests, strtoul correctly leaves errno at 0: > errno=0; > ul = strtoul("4294967295", &p, 10); > o_errno = errno; > printf("ul=%lu,*p=%x,errno=%d(%s)\n", ul, *p, o_errno,strerror(errno)); > > gives the result ``ul=4294967295,*p=0,errno=0(Unknown error: 0)'', as > expected. The problem with the original test case is that strerror() > is setting errno to EINVAL (because 0 isn't a valid error number) > before errno is pushed on the stack for printf (the order in which > function arguments are evaluated is undefined in C). ul = strtoul("4294967296", &p, 10); ul = strtoul("4294967295", &p, 10); 2nd strtoul() will success, but errno == ERANGE. Is it necessary to set errno as 0 before calling 2nd strtoul() ? ------ takayuki@finet.fujitsu.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200407300730.i6U7UP3O069454>