Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit23a4157

Browse files
committed
Adjust DatumGetBool macro so that it isn't fooled by garbage in the Datum
to the left of the actual bool value. While in most cases there won't beany, our support for old-style user-defined functions violates the C specto the extent of calling functions that might return char or short througha function pointer declared to return "char *", which we then coerce toDatum. It is not surprising that the result might contain garbagehigh-order bits ... what is surprising is that we didn't see such caseslong ago. Per report from Magnus.
1 parent547b6e5 commit23a4157

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

‎src/include/postgres.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1995, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.77 2007/02/27 23:48:09 tgl Exp $
13+
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.78 2007/03/23 20:24:41 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -125,13 +125,18 @@ typedef struct varattrib
125125
*
126126
*sizeof(short) == 2
127127
*
128-
*If your machine meets these requirements, Datums should also be checked
129-
*to see if the positioning is correct.
128+
* When a type narrower than Datum is stored in a Datum, we place it in the
129+
* low-order bits and are careful that the DatumGetXXX macro for it discards
130+
* the unused high-order bits (as opposed to, say, assuming they are zero).
131+
* This is needed to support old-style user-defined functions, since depending
132+
* on architecture and compiler, the return value of a function returning char
133+
* or short may contain garbage when called as if it returned Datum.
130134
*/
131135

132136
typedefunsigned longDatum;/* XXX sizeof(long) >= sizeof(void *) */
133137

134138
#defineSIZEOF_DATUM SIZEOF_UNSIGNED_LONG
139+
135140
typedefDatum*DatumPtr;
136141

137142
#defineGET_1_BYTE(datum)(((Datum) (datum)) & 0x000000ff)
@@ -145,10 +150,11 @@ typedef Datum *DatumPtr;
145150
* DatumGetBool
146151
*Returns boolean value of a datum.
147152
*
148-
* Note: any nonzero value will be considered TRUE.
153+
* Note: any nonzero value will be considered TRUE, but we ignore bits to
154+
* the left of the width of bool, per comment above.
149155
*/
150156

151-
#defineDatumGetBool(X) ((bool) (((Datum) (X)) != 0))
157+
#defineDatumGetBool(X) ((bool) (((bool) (X)) != 0))
152158

153159
/*
154160
* BoolGetDatum

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp