questionable code in heap_formtuple()

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: hackers(at)postgreSQL(dot)org
Subject: questionable code in heap_formtuple()
Date: 1998-09-03 06:52:19
Message-ID: 199809030652.PAA01058@srapc451.sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

around line 812 in access/common/heaptuple.c:

len = sizeof *tuple - sizeof tuple->t_bits;

This seems questionable for me.

tuple is a pointer to struct HeaptupleData.

typedef struct HeapTupleData
{
unsigned int t_len; /* length of entire tuple */

[snip]

uint8 t_hoff; /* sizeof tuple header */

bits8 t_bits[MinHeapTupleBitmapSize / 8];
/* bit map of domains */

/* MORE DATA FOLLOWS AT END OF STRUCT */
} HeapTupleData;

I think the code tries to calculate the offset from top of the
structure to t_bits. t_bits is the last structure member of
HeapTupleData, and that would give the offset...

No. since the size of the whole structure is aligned to 2-byte, there
is a "padding" byte after t_bits.

I think more acculate way to calculate the offset is:

len = (char *)&tuple->t_bits[0] - (char *)tuple;

I ran a test and found the first one gives len = 36, while second one
gives 35.

I'm not sure how this affects. maybe nothing (len is aligned to 8-byte
boundary later).
--
Tatsuo Ishii
t-ishii(at)sra(dot)co(dot)jp

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 1998-09-03 08:31:33 Re: [HACKERS] LinuxPPC problems
Previous Message Thomas G. Lockhart 1998-09-03 05:52:52 Re: [HACKERS] index fix report