mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Zero padding byte at end of GIN posting list.
This isn't strictly necessary, but helps debugging.
This commit is contained in:
parent
f235db03ff
commit
38a2b95c34
@ -176,6 +176,9 @@ decode_varbyte(unsigned char **ptr)
|
|||||||
* 'maxsize' bytes in size. The number items in the returned segment is
|
* 'maxsize' bytes in size. The number items in the returned segment is
|
||||||
* returned in *nwritten. If it's not equal to nipd, not all the items fit
|
* returned in *nwritten. If it's not equal to nipd, not all the items fit
|
||||||
* in 'maxsize', and only the first *nwritten were encoded.
|
* in 'maxsize', and only the first *nwritten were encoded.
|
||||||
|
*
|
||||||
|
* The allocated size of the returned struct is short-aligned, and the padding
|
||||||
|
* byte at the end, if any, is zero.
|
||||||
*/
|
*/
|
||||||
GinPostingList *
|
GinPostingList *
|
||||||
ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
|
ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
|
||||||
@ -188,9 +191,12 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
unsigned char *endptr;
|
unsigned char *endptr;
|
||||||
|
|
||||||
|
maxsize = SHORTALIGN_DOWN(maxsize);
|
||||||
|
|
||||||
result = palloc(maxsize);
|
result = palloc(maxsize);
|
||||||
|
|
||||||
maxbytes = maxsize - offsetof(GinPostingList, bytes);
|
maxbytes = maxsize - offsetof(GinPostingList, bytes);
|
||||||
|
Assert(maxbytes > 0);
|
||||||
|
|
||||||
/* Store the first special item */
|
/* Store the first special item */
|
||||||
result->first = ipd[0];
|
result->first = ipd[0];
|
||||||
@ -228,6 +234,13 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
|
|||||||
}
|
}
|
||||||
result->nbytes = ptr - result->bytes;
|
result->nbytes = ptr - result->bytes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we wrote an odd number of bytes, zero out the padding byte at the
|
||||||
|
* end.
|
||||||
|
*/
|
||||||
|
if (result->nbytes != SHORTALIGN(result->nbytes))
|
||||||
|
result->bytes[result->nbytes] = 0;
|
||||||
|
|
||||||
if (nwritten)
|
if (nwritten)
|
||||||
*nwritten = totalpacked;
|
*nwritten = totalpacked;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user