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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Strange interval arithmetic


  • From: Michael Fuhr <mike(at)fuhr(dot)org>
  • To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
  • Subject: Re: Strange interval arithmetic
  • Date: Wed, 30 Nov 2005 15:39:16 -0700
  • Message-id: <20051130223916(dot)GA27287(at)winnie(dot)fuhr(dot)org>

On Wed, Nov 30, 2005 at 05:20:54PM -0500, Tom Lane wrote:
> Michael Fuhr <mike(at)fuhr(dot)org> writes:
> > I'm looking at all the strtol() calls in datetime.c right now; I
> > haven't looked anywhere else yet.  Should I bother checking values
> > that will be range checked later anyway?  Time zone displacements,
> > for example?
> 
> Good question.  Is strtol guaranteed to return INT_MAX or INT_MIN on
> overflow, or might it return the overflowed value?

The Open Group Base Specifications say this:

  Upon successful completion, these functions shall return the converted
  value, if any.  If no conversion could be performed, 0 shall be
  returned and errno may be set to [EINVAL].

  If the correct value is outside the range of representable values,
  {LONG_MIN}, {LONG_MAX}, {LLONG_MIN}, or {LLONG_MAX} shall be returned
  (according to the sign of the value), and errno set to [ERANGE].

http://www.opengroup.org/onlinepubs/009695399/functions/strtol.html

FreeBSD and Solaris both peg overflow at LONG_MAX, and that behavior
is what I noticed in the first place.  I don't know if any systems
behave otherwise.  Alvaro suggested checking for both LONG_MAX and
ERANGE; I suppose if we check for LONG_MAX then we should also check
for LONG_MIN.  I don't know if any systems might set ERANGE in a
non-error situation.

-- 
Michael Fuhr



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group