From 2ec958721d6b13061c1778ca9cbdc41f8cd4d7a1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 24 Nov 2001 19:57:06 +0000 Subject: [PATCH] Tweak int8in to accept -9223372036854775808, per recent discussion in pgsql-patches. --- doc/src/sgml/datatype.sgml | 4 ++-- src/backend/utils/adt/int8.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index c7c0d740a94..52ff88ed9d7 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ @@ -385,7 +385,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.75 2001/11/21 21:12:34 tg bigint 8 bytes Very large range fixed-precision - -9223372036854775807 to 9223372036854775807 + -9223372036854775808 to 9223372036854775807 diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index b689cb764a4..380e0238238 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.35 2001/10/25 14:10:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.36 2001/11/24 19:57:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -26,6 +26,12 @@ #define INT64_FORMAT "%ld" #endif +#ifdef HAVE_LL_CONSTANTS +#define INT64CONST(x) ((int64) x##LL) +#else +#define INT64CONST(x) ((int64) x) +#endif + #define MAXINT8LEN 25 #ifndef INT_MAX @@ -69,8 +75,23 @@ int8in(PG_FUNCTION_ARGS) */ while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */ ptr++; - if (*ptr == '-') /* handle sign */ - sign = -1, ptr++; + /* handle sign */ + if (*ptr == '-') + { + ptr++; + sign = -1; + /* + * Do an explicit check for INT64_MIN. Ugly though this is, it's + * cleaner than trying to get the loop below to handle it portably. + */ +#ifndef INT64_IS_BUSTED + if (strcmp(ptr, "9223372036854775808") == 0) + { + result = - INT64CONST(0x7fffffffffffffff) - 1; + PG_RETURN_INT64(result); + } +#endif + } else if (*ptr == '+') ptr++; if (!isdigit((unsigned char) *ptr)) /* require at least one digit */ -- 2.39.5