Re: [COMMITTERS] pgsql: Add comments about why errno is set to zero. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [COMMITTERS] pgsql: Add comments about why errno is set to zero.
Date
Msg-id 18483.1133484165@sss.pgh.pa.us
Whole thread Raw
In response to Re: [COMMITTERS] pgsql: Add comments about why errno is set to zero.  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: [COMMITTERS] pgsql: Add comments about why errno is set
List pgsql-hackers
Bruce Momjian <pgman@candle.pha.pa.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 arealso valid returns on success, an application wishing to
checkforerror situations should set errno to 0, then call strtol(),then check errno.
 
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Add comments about why errno is
Next
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Add comments about why errno is set to zero.