Skip site navigation (1) Skip section navigation (2)

Re: [COMMITTERS] pgsql: Add comments about why errno is set

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql: Add comments about why errno is set
Date: 2005-12-02 02:49:21
Message-ID: 200512020249.jB22nLd10985@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-hackers
OK, comments removed, and comment added to port/strtol.c.

---------------------------------------------------------------------------

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > I modified it to:
> >         errno = 0;  /* avoid having to check the result for failure */
> 
> Just for the record, that's *still* wrong.  It implies that if we
> tested (result == LONG_MAX && errno == ERANGE), without zeroing
> errno beforehand, the code would be correct.  But it would not,
> because the errno value could still be leftover.  The plain fact
> of the matter is that if you're going to check for strtol overflow at
> all, you have to zero errno beforehand.  This is perfectly well
> explained in the strtol spec page, and I see no need to duplicate it:
> 
> 	Because 0, LONG_MIN and LONG_MAX are returned on error and are
> 	also valid returns on success, an application wishing to check
> 	for error situations should set errno to 0, then call strtol(),
> 	then check errno.
> 
> 			regards, tom lane
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

pgsql-hackers by date

Next:From: Greg Sabino MullaneDate: 2005-12-02 02:56:45
Subject: Re: Windows installation notes
Previous:From: Christopher Kings-LynneDate: 2005-12-02 02:45:02
Subject: Re: Reducing relation locking overhead

pgsql-committers by date

Next:From: Bruce MomjianDate: 2005-12-02 04:28:27
Subject: pgsql: Add calcluation of bitmap storage capacity.
Previous:From: Bruce MomjianDate: 2005-12-02 02:49:12
Subject: pgsql: Remove comment on errno=0 lines, but add mention to port/strtol.c

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group