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

Commita36a7a1

Browse files
committed
Fix bogus assumption that MAXALIGN is at least sizeof(pointer).
1 parent5085132 commita36a7a1

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 intgetNotice(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 intgetNotice(PGconn *conn);
105104
* ----------------
106105
*/
107106

107+
#ifdefMAX
108+
#undef MAX
109+
#endif
110+
#defineMAX(a,b) ((a) > (b) ? (a) : (b))
111+
108112
#definePGRESULT_DATA_BLOCKSIZE2048
109113
#definePGRESULT_ALIGN_BOUNDARYMAXIMUM_ALIGNOF/* from configure */
114+
#definePGRESULT_BLOCK_OVERHEADMAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
110115
#definePGRESULT_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
returnNULL;
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)

[8]ページ先頭

©2009-2025 Movatter.jp