mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
Centralize definition of integer limits.
Several submitted and even committed patches have run into the problem that C89, our baseline, does not provide minimum/maximum values for various integer datatypes. C99's stdint.h does, but we can't rely on it. Several parts of the code defined limits locally, so instead centralize the definitions to c.h. This patch also changes the more obvious usages of literal limit values; there's more places that could be changed, but it's less clear whether it's beneficial to change those. Author: Andrew Gierth Discussion: 87619tc5wc.fsf@news-spur.riddles.org.uk
This commit is contained in:
@@ -1408,7 +1408,7 @@ WALInsertLockAcquireExclusive(void)
|
||||
{
|
||||
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
|
||||
&WALInsertLocks[i].l.insertingAt,
|
||||
UINT64CONST(0xFFFFFFFFFFFFFFFF));
|
||||
UINT64_MAX);
|
||||
}
|
||||
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
|
||||
&WALInsertLocks[i].l.insertingAt,
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "catalog/pg_collation.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "tsearch/ts_locale.h"
|
||||
@@ -2047,7 +2049,7 @@ hlCover(HeadlineParsedText *prs, TSQuery query, int *p, int *q)
|
||||
int pos = *p;
|
||||
|
||||
*q = -1;
|
||||
*p = 0x7fffffff;
|
||||
*p = INT_MAX;
|
||||
|
||||
for (j = 0; j < query->size; j++)
|
||||
{
|
||||
@@ -2258,7 +2260,7 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, int highlight,
|
||||
for (f = 0; f < max_fragments; f++)
|
||||
{
|
||||
maxitems = 0;
|
||||
minwords = 0x7fffffff;
|
||||
minwords = INT32_MAX;
|
||||
minI = -1;
|
||||
|
||||
/*
|
||||
|
||||
@@ -78,7 +78,7 @@ scanint8(const char *str, bool errorOK, int64 *result)
|
||||
*/
|
||||
if (strncmp(ptr, "9223372036854775808", 19) == 0)
|
||||
{
|
||||
tmp = -INT64CONST(0x7fffffffffffffff) - 1;
|
||||
tmp = INT64_MIN;
|
||||
ptr += 19;
|
||||
goto gotdigits;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ pg_lltoa(int64 value, char *a)
|
||||
* Avoid problems with the most negative integer not being representable
|
||||
* as a positive integer.
|
||||
*/
|
||||
if (value == (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1))
|
||||
if (value == INT64_MIN)
|
||||
{
|
||||
memcpy(a, "-9223372036854775808", 21);
|
||||
return;
|
||||
|
||||
@@ -44,14 +44,6 @@
|
||||
|
||||
#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0))
|
||||
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef INT64_MIN
|
||||
#define INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
|
||||
#endif
|
||||
|
||||
/* Set at postmaster start */
|
||||
TimestampTz PgStartTime;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "tsearch/ts_utils.h"
|
||||
@@ -555,7 +556,7 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
|
||||
|
||||
memset(qr->operandexist, 0, sizeof(bool) * qr->query->size);
|
||||
|
||||
ext->p = 0x7fffffff;
|
||||
ext->p = INT_MAX;
|
||||
ext->q = 0;
|
||||
ptr = doc + ext->pos;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
|
||||
/* txid will be signed int8 in database, so must limit to 63 bits */
|
||||
#define MAX_TXID UINT64CONST(0x7FFFFFFFFFFFFFFF)
|
||||
#define MAX_TXID ((uint64) INT64_MAX)
|
||||
|
||||
/* Use unsigned variant internally */
|
||||
typedef uint64 txid;
|
||||
|
||||
Reference in New Issue
Block a user