According to the PostgreSQL documentation, the VARHDRSZ header needs to be included in the allocation for the return value. Without this, the allocations are 4 bytes short (which explains the results described in issue #19), writing the data flies off the end of the allocated space (by 4 bytes), and is then overwritten by subsequent allocations.
(Notice the VARHDRSZ + 40 in both the palloc() and the SET_VARSIZE() calls. While the existing code had + VARHDRSZ in the VARSIZE() call, it was missing from palloc().
According to the PostgreSQL documentation, the VARHDRSZ header needs to be included in the allocation for the return value. Without this, the allocations are 4 bytes short (which explains the results described in issue #19), writing the data flies off the end of the allocated space (by 4 bytes), and is then overwritten by subsequent allocations.
From the docs:
(Notice the
VARHDRSZ + 40
in both thepalloc()
and theSET_VARSIZE()
calls. While the existing code had+ VARHDRSZ
in theVARSIZE()
call, it was missing frompalloc()
.Fixes #19, and probably #15.
Signed-off-by: Jared Reisinger jaredreisinger@hotmail.com