Skip to content

Commit a36a7a1

Browse files
committed
Fix bogus assumption that MAXALIGN is at least sizeof(pointer).
1 parent 5085132 commit a36a7a1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.78 1999/04/04 20:10:12 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.79 1999/05/12 04:38:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -92,11 +92,10 @@ static int getNotice(PGconn *conn);
9292
* PGRESULT_SEP_ALLOC_THRESHOLD: objects bigger than this are given separate
9393
* blocks, instead of being crammed into a regular allocation block.
9494
* Requirements for correct function are:
95-
* PGRESULT_ALIGN_BOUNDARY >= sizeof(pointer)
96-
* to ensure the initial pointer in a block is not overwritten.
9795
* PGRESULT_ALIGN_BOUNDARY must be a multiple of the alignment requirements
98-
* of all machine data types.
99-
* PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_ALIGN_BOUNDARY <=
96+
* of all machine data types. (Currently this is set from configure
97+
* tests, so it should be OK automatically.)
98+
* PGRESULT_SEP_ALLOC_THRESHOLD + PGRESULT_BLOCK_OVERHEAD <=
10099
* PGRESULT_DATA_BLOCKSIZE
101100
* pqResultAlloc assumes an object smaller than the threshold will fit
102101
* in a new block.
@@ -105,8 +104,14 @@ static int getNotice(PGconn *conn);
105104
* ----------------
106105
*/
107106

107+
#ifdef MAX
108+
#undef MAX
109+
#endif
110+
#define MAX(a,b) ((a) > (b) ? (a) : (b))
111+
108112
#define PGRESULT_DATA_BLOCKSIZE 2048
109113
#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */
114+
#define PGRESULT_BLOCK_OVERHEAD MAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
110115
#define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
111116

112117

@@ -213,10 +218,10 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
213218
*/
214219
if (nBytes >= PGRESULT_SEP_ALLOC_THRESHOLD)
215220
{
216-
block = (PGresult_data *) malloc(nBytes + PGRESULT_ALIGN_BOUNDARY);
221+
block = (PGresult_data *) malloc(nBytes + PGRESULT_BLOCK_OVERHEAD);
217222
if (! block)
218223
return NULL;
219-
space = block->space + PGRESULT_ALIGN_BOUNDARY;
224+
space = block->space + PGRESULT_BLOCK_OVERHEAD;
220225
if (res->curBlock)
221226
{
222227
/* Tuck special block below the active block, so that we don't
@@ -244,8 +249,8 @@ pqResultAlloc(PGresult *res, int nBytes, int isBinary)
244249
if (isBinary)
245250
{
246251
/* object needs full alignment */
247-
res->curOffset = PGRESULT_ALIGN_BOUNDARY;
248-
res->spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_ALIGN_BOUNDARY;
252+
res->curOffset = PGRESULT_BLOCK_OVERHEAD;
253+
res->spaceLeft = PGRESULT_DATA_BLOCKSIZE - PGRESULT_BLOCK_OVERHEAD;
249254
}
250255
else
251256
{

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