Skip to content

Commit 0514ad1

Browse files
committed
Tweak AbsoluteTimeIsReal() to avoid compiler bugs on machines where
a > comparison against INT_MIN may do the wrong thing. Per suggestion from Andreas.
1 parent 6ba959e commit 0514ad1

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/include/utils/nabstime.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: nabstime.h,v 1.26 2000/06/09 01:11:15 tgl Exp $
10+
* $Id: nabstime.h,v 1.27 2000/11/18 05:41:45 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#ifndef NABSTIME_H
1515
#define NABSTIME_H
1616

17+
#include <limits.h>
1718
#include <time.h>
1819

1920
#include "fmgr.h"
@@ -78,37 +79,25 @@ typedef TimeIntervalData *TimeInterval;
7879
#define CURRENT_ABSTIME ((AbsoluteTime) 0x7FFFFFFD) /* 2147483646 (2^31 - 2) */
7980
#define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
8081
#define BIG_ABSTIME ((AbsoluteTime) 0x7FFFFFFB) /* 2147483644 (2^31 - 4) */
81-
82-
#if defined(_AIX)
83-
/*
84-
* AIX considers 2147483648 == -2147483648 (since they have the same bit
85-
* representation) but uses a different sign sense in a comparison to
86-
* these integer constants depending on whether the constant is signed
87-
* or not!
88-
*/
89-
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN)
90-
#else
91-
#define NOSTART_ABSTIME ((AbsoluteTime) 0x80000001) /* -2147483647 (- 2^31) */
92-
#endif /* _AIX */
82+
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) /* -2147483648 */
9383

9484
#define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
9585

9686
#define AbsoluteTimeIsValid(time) \
9787
((bool) ((time) != INVALID_ABSTIME))
9888

89+
/*
90+
* Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any
91+
* AbsoluteTime values less than it. Therefore, we can code the test
92+
* "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids
93+
* compiler bugs on some platforms. --- tgl & az, 11/2000
94+
*/
9995
#define AbsoluteTimeIsReal(time) \
100-
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
101-
((AbsoluteTime) time) > NOSTART_ABSTIME))
96+
((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \
97+
((AbsoluteTime) (time)) != NOSTART_ABSTIME))
10298

10399
#define RelativeTimeIsValid(time) \
104-
((bool) (((RelativeTime) time) != INVALID_RELTIME))
105-
106-
/*
107-
* getSystemTime
108-
* Returns system time.
109-
*/
110-
#define getSystemTime() \
111-
((time_t) (time(0l)))
100+
((bool) (((RelativeTime) (time)) != INVALID_RELTIME))
112101

113102

114103
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy