Skip to content

Commit 3023dc6

Browse files
committed
A few changes to cleanup the code.
- Added the header access/heapam.h. - Changed all instances of "length" to "data_length" to quiet the compiler. - initialized a few variables. The compiler couldn't see that the code guaranteed that these would be initialized before being dereferenced. If anyone wants to check my work follow the usage of these variables and make sure that this true and wasn't actually a bug in the original code. - added a missing break statement to a default case. This was a benign error but bad style. - layed out heap_sysattrlen differently. I think this way makes the structure of the code crystal clear. There should be no actual difference in the actual behaviour of the code. Submitted by: darcy@druid.druid.com (D'Arcy J.M. Cain)
1 parent efebd7b commit 3023dc6

File tree

1 file changed

+36
-57
lines changed

1 file changed

+36
-57
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.3 1996/08/27 07:42:13 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.4 1996/09/19 20:00:37 scrappy Exp $
1212
*
1313
* NOTES
1414
* The old interface functions have been converted to macros
@@ -24,6 +24,7 @@
2424
#include "access/itup.h"
2525
#include "access/tupmacs.h"
2626
#include "access/skey.h"
27+
#include "access/heapam.h"
2728
#include "storage/ipc.h"
2829
#include "storage/buf.h"
2930
#include "storage/bufmgr.h"
@@ -56,12 +57,12 @@ ComputeDataSize(TupleDesc tupleDesc,
5657
Datum value[],
5758
char nulls[])
5859
{
59-
uint32 length;
60+
uint32 data_length;
6061
int i;
6162
int numberOfAttributes = tupleDesc->natts;
6263
AttributeTupleForm *att = tupleDesc->attrs;
6364

64-
for (length = 0, i = 0; i < numberOfAttributes; i++) {
65+
for (data_length = 0, i = 0; i < numberOfAttributes; i++) {
6566
if (nulls[i] != ' ') continue;
6667

6768
switch (att[i]->attlen) {
@@ -71,35 +72,35 @@ ComputeDataSize(TupleDesc tupleDesc,
7172
* must include the additional sizeof long.
7273
*/
7374
if (att[i]->attalign == 'd') {
74-
length = DOUBLEALIGN(length)
75+
data_length = DOUBLEALIGN(data_length)
7576
+ VARSIZE(DatumGetPointer(value[i]));
7677
} else {
77-
length = INTALIGN(length)
78+
data_length = INTALIGN(data_length)
7879
+ VARSIZE(DatumGetPointer(value[i]));
7980
}
8081
break;
8182
case sizeof(char):
82-
length++;
83+
data_length++;
8384
break;
8485
case sizeof(short):
85-
length = SHORTALIGN(length + sizeof(short));
86+
data_length = SHORTALIGN(data_length + sizeof(short));
8687
break;
8788
case sizeof(int32):
88-
length = INTALIGN(length + sizeof(int32));
89+
data_length = INTALIGN(data_length + sizeof(int32));
8990
break;
9091
default:
9192
if (att[i]->attlen < sizeof(int32))
9293
elog(WARN, "ComputeDataSize: attribute %d has len %d",
9394
i, att[i]->attlen);
9495
if (att[i]->attalign == 'd')
95-
length = DOUBLEALIGN(length) + att[i]->attlen;
96+
data_length = DOUBLEALIGN(data_length) + att[i]->attlen;
9697
else
97-
length = LONGALIGN(length) + att[i]->attlen;
98+
data_length = LONGALIGN(data_length) + att[i]->attlen;
9899
break;
99100
}
100101
}
101102

102-
return length;
103+
return data_length;
103104
}
104105

105106
/* ----------------
@@ -114,12 +115,12 @@ DataFill(char *data,
114115
char *infomask,
115116
bits8 *bit)
116117
{
117-
bits8 *bitP;
118-
int bitmask;
119-
uint32 length;
118+
bits8 *bitP = 0;
119+
int bitmask = 0;
120+
uint32 data_length;
120121
int i;
121122
int numberOfAttributes = tupleDesc->natts;
122-
AttributeTupleForm* att = tupleDesc->attrs;
123+
AttributeTupleForm *att = tupleDesc->attrs;
123124

124125
if (bit != NULL) {
125126
bitP = &bit[-1];
@@ -154,9 +155,9 @@ DataFill(char *data,
154155
} else {
155156
data = (char *) INTALIGN(data);
156157
}
157-
length = VARSIZE(DatumGetPointer(value[i]));
158-
memmove(data, DatumGetPointer(value[i]),length);
159-
data += length;
158+
data_length = VARSIZE(DatumGetPointer(value[i]));
159+
memmove(data, DatumGetPointer(value[i]),data_length);
160+
data += data_length;
160161
break;
161162
case sizeof(char):
162163
*data = att[i]->attbyval ?
@@ -192,7 +193,7 @@ DataFill(char *data,
192193
att[i]->attlen);
193194
data += att[i]->attlen;
194195
}
195-
196+
break;
196197
}
197198
}
198199
}
@@ -256,49 +257,27 @@ int
256257
heap_sysattrlen(AttrNumber attno)
257258
{
258259
HeapTupleData *f = NULL;
259-
int len;
260260

261261
switch (attno) {
262-
case SelfItemPointerAttributeNumber:
263-
len = sizeof f->t_ctid;
264-
break;
265-
case ObjectIdAttributeNumber:
266-
len = sizeof f->t_oid;
267-
break;
268-
case MinTransactionIdAttributeNumber:
269-
len = sizeof f->t_xmin;
270-
break;
271-
case MinCommandIdAttributeNumber:
272-
len = sizeof f->t_cmin;
273-
break;
274-
case MaxTransactionIdAttributeNumber:
275-
len = sizeof f->t_xmax;
276-
break;
277-
case MaxCommandIdAttributeNumber:
278-
len = sizeof f->t_cmax;
279-
break;
280-
case ChainItemPointerAttributeNumber:
281-
len = sizeof f->t_chain;
282-
break;
262+
case SelfItemPointerAttributeNumber: return sizeof f->t_ctid;
263+
case ObjectIdAttributeNumber: return sizeof f->t_oid;
264+
case MinTransactionIdAttributeNumber: return sizeof f->t_xmin;
265+
case MinCommandIdAttributeNumber: return sizeof f->t_cmin;
266+
case MaxTransactionIdAttributeNumber: return sizeof f->t_xmax;
267+
case MaxCommandIdAttributeNumber: return sizeof f->t_cmax;
268+
case ChainItemPointerAttributeNumber: return sizeof f->t_chain;
269+
case MinAbsoluteTimeAttributeNumber: return sizeof f->t_tmin;
270+
case MaxAbsoluteTimeAttributeNumber: return sizeof f->t_tmax;
271+
case VersionTypeAttributeNumber: return sizeof f->t_vtype;
272+
283273
case AnchorItemPointerAttributeNumber:
284274
elog(WARN, "heap_sysattrlen: field t_anchor does not exist!");
285-
break;
286-
case MinAbsoluteTimeAttributeNumber:
287-
len = sizeof f->t_tmin;
288-
break;
289-
case MaxAbsoluteTimeAttributeNumber:
290-
len = sizeof f->t_tmax;
291-
break;
292-
case VersionTypeAttributeNumber:
293-
len = sizeof f->t_vtype;
294-
break;
275+
return 0;
276+
295277
default:
296-
elog(WARN, "sysattrlen: System attribute number %d unknown.",
297-
attno);
298-
len = 0;
299-
break;
278+
elog(WARN, "sysattrlen: System attribute number %d unknown.", attno);
279+
return 0;
300280
}
301-
return (len);
302281
}
303282

304283
/* ----------------
@@ -437,7 +416,7 @@ fastgetattr(HeapTuple tup,
437416
bool *isnull)
438417
{
439418
char *tp; /* ptr to att in tuple */
440-
bits8 *bp; /* ptr to att in tuple */
419+
bits8 *bp = NULL; /* ptr to att in tuple */
441420
int slow; /* do we have to walk nulls? */
442421
AttributeTupleForm *att = tupleDesc->attrs;
443422

0 commit comments

Comments
 (0)