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

Commitccd415c

Browse files
committed
Fix unportable assumptions about alignment of local char[n] variables.
1 parent571dbe4 commitccd415c

File tree

4 files changed

+82
-53
lines changed

4 files changed

+82
-53
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.112 2001/03/22 06:16:07 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.113 2001/03/25 23:23:58 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2126,10 +2126,19 @@ static XLogRecPtr
21262126
log_heap_update(Relationreln,Bufferoldbuf,ItemPointerDatafrom,
21272127
Buffernewbuf,HeapTuplenewtup,boolmove)
21282128
{
2129-
chartbuf[MAXALIGN(sizeof(xl_heap_header))+2*sizeof(TransactionId)];
2130-
xl_heap_updatexlrec;
2131-
xl_heap_header*xlhdr= (xl_heap_header*)tbuf;
2129+
/*
2130+
* Note: xlhdr is declared to have adequate size and correct alignment
2131+
* for an xl_heap_header. However the two tids, if present at all,
2132+
* will be packed in with no wasted space after the xl_heap_header;
2133+
* they aren't necessarily aligned as implied by this struct declaration.
2134+
*/
2135+
struct {
2136+
xl_heap_headerhdr;
2137+
TransactionIdtid1;
2138+
TransactionIdtid2;
2139+
}xlhdr;
21322140
inthsize=SizeOfHeapHeader;
2141+
xl_heap_updatexlrec;
21332142
XLogRecPtrrecptr;
21342143
XLogRecDatardata[4];
21352144
Pagepage=BufferGetPage(newbuf);
@@ -2148,10 +2157,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
21482157
rdata[1].len=0;
21492158
rdata[1].next=&(rdata[2]);
21502159

2151-
xlhdr->t_oid=newtup->t_data->t_oid;
2152-
xlhdr->t_natts=newtup->t_data->t_natts;
2153-
xlhdr->t_hoff=newtup->t_data->t_hoff;
2154-
xlhdr->mask=newtup->t_data->t_infomask;
2160+
xlhdr.hdr.t_oid=newtup->t_data->t_oid;
2161+
xlhdr.hdr.t_natts=newtup->t_data->t_natts;
2162+
xlhdr.hdr.t_hoff=newtup->t_data->t_hoff;
2163+
xlhdr.hdr.mask=newtup->t_data->t_infomask;
21552164
if (move)/* remember xmin & xmax */
21562165
{
21572166
TransactionIdxmax;
@@ -2161,13 +2170,13 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
21612170
xmax=InvalidTransactionId;
21622171
else
21632172
xmax=newtup->t_data->t_xmax;
2164-
memcpy(tbuf+hsize,&xmax,sizeof(TransactionId));
2165-
memcpy(tbuf+hsize+sizeof(TransactionId),
2173+
memcpy((char*)&xlhdr+hsize,&xmax,sizeof(TransactionId));
2174+
memcpy((char*)&xlhdr+hsize+sizeof(TransactionId),
21662175
&(newtup->t_data->t_xmin),sizeof(TransactionId));
2167-
hsize+=(2*sizeof(TransactionId));
2176+
hsize+=2*sizeof(TransactionId);
21682177
}
21692178
rdata[2].buffer=newbuf;
2170-
rdata[2].data= (char*)xlhdr;
2179+
rdata[2].data= (char*)&xlhdr;
21712180
rdata[2].len=hsize;
21722181
rdata[2].next=&(rdata[3]);
21732182

@@ -2228,13 +2237,16 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
22282237

22292238
if (record->xl_len>SizeOfHeapClean)
22302239
{
2231-
charunbuf[BLCKSZ];
2232-
OffsetNumber*unused=(OffsetNumber*)unbuf;
2240+
OffsetNumberunbuf[BLCKSZ/sizeof(OffsetNumber)];
2241+
OffsetNumber*unused=unbuf;
22332242
char*unend;
22342243
ItemIdlp;
22352244

2236-
memcpy(unbuf, (char*)xlrec+SizeOfHeapClean,record->xl_len-SizeOfHeapClean);
2237-
unend=unbuf+ (record->xl_len-SizeOfHeapClean);
2245+
Assert((record->xl_len-SizeOfHeapClean) <=BLCKSZ);
2246+
memcpy((char*)unbuf,
2247+
(char*)xlrec+SizeOfHeapClean,
2248+
record->xl_len-SizeOfHeapClean);
2249+
unend= (char*)unbuf+ (record->xl_len-SizeOfHeapClean);
22382250

22392251
while ((char*)unused<unend)
22402252
{
@@ -2318,7 +2330,6 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
23182330
Bufferbuffer;
23192331
Pagepage;
23202332
OffsetNumberoffnum;
2321-
HeapTupleHeaderhtup;
23222333

23232334
if (redo&& (record->xl_info&XLR_BKP_BLOCK_1))
23242335
return;
@@ -2338,7 +2349,11 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
23382349

23392350
if (redo)
23402351
{
2341-
chartbuf[MaxTupleSize];
2352+
struct {
2353+
HeapTupleHeaderDatahdr;
2354+
chardata[MaxTupleSize];
2355+
}tbuf;
2356+
HeapTupleHeaderhtup;
23422357
xl_heap_headerxlhdr;
23432358
uint32newlen;
23442359

@@ -2359,11 +2374,15 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
23592374
elog(STOP,"heap_insert_redo: invalid max offset number");
23602375

23612376
newlen=record->xl_len-SizeOfHeapInsert-SizeOfHeapHeader;
2362-
memcpy((char*)&xlhdr, (char*)xlrec+SizeOfHeapInsert,SizeOfHeapHeader);
2363-
memcpy(tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2364-
(char*)xlrec+SizeOfHeapInsert+SizeOfHeapHeader,newlen);
2377+
Assert(newlen <=MaxTupleSize);
2378+
memcpy((char*)&xlhdr,
2379+
(char*)xlrec+SizeOfHeapInsert,
2380+
SizeOfHeapHeader);
2381+
memcpy((char*)&tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2382+
(char*)xlrec+SizeOfHeapInsert+SizeOfHeapHeader,
2383+
newlen);
23652384
newlen+= offsetof(HeapTupleHeaderData,t_bits);
2366-
htup=(HeapTupleHeader)tbuf;
2385+
htup=&tbuf.hdr;
23672386
htup->t_oid=xlhdr.t_oid;
23682387
htup->t_natts=xlhdr.t_natts;
23692388
htup->t_hoff=xlhdr.t_hoff;
@@ -2496,7 +2515,10 @@ newsame:;
24962515

24972516
if (redo)
24982517
{
2499-
chartbuf[MaxTupleSize];
2518+
struct {
2519+
HeapTupleHeaderDatahdr;
2520+
chardata[MaxTupleSize];
2521+
}tbuf;
25002522
xl_heap_headerxlhdr;
25012523
inthsize;
25022524
uint32newlen;
@@ -2522,20 +2544,27 @@ newsame:;
25222544
hsize+= (2*sizeof(TransactionId));
25232545

25242546
newlen=record->xl_len-hsize;
2525-
memcpy((char*)&xlhdr, (char*)xlrec+SizeOfHeapUpdate,SizeOfHeapHeader);
2526-
memcpy(tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2527-
(char*)xlrec+hsize,newlen);
2547+
Assert(newlen <=MaxTupleSize);
2548+
memcpy((char*)&xlhdr,
2549+
(char*)xlrec+SizeOfHeapUpdate,
2550+
SizeOfHeapHeader);
2551+
memcpy((char*)&tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2552+
(char*)xlrec+hsize,
2553+
newlen);
25282554
newlen+= offsetof(HeapTupleHeaderData,t_bits);
2529-
htup=(HeapTupleHeader)tbuf;
2555+
htup=&tbuf.hdr;
25302556
htup->t_oid=xlhdr.t_oid;
25312557
htup->t_natts=xlhdr.t_natts;
25322558
htup->t_hoff=xlhdr.t_hoff;
25332559
if (move)
25342560
{
25352561
hsize=SizeOfHeapUpdate+SizeOfHeapHeader;
2536-
memcpy(&(htup->t_xmax), (char*)xlrec+hsize,sizeof(TransactionId));
2562+
memcpy(&(htup->t_xmax),
2563+
(char*)xlrec+hsize,
2564+
sizeof(TransactionId));
25372565
memcpy(&(htup->t_xmin),
2538-
(char*)xlrec+hsize+sizeof(TransactionId),sizeof(TransactionId));
2566+
(char*)xlrec+hsize+sizeof(TransactionId),
2567+
sizeof(TransactionId));
25392568
TransactionIdStore(record->xl_xid, (TransactionId*)&(htup->t_cmin));
25402569
htup->t_infomask=xlhdr.mask;
25412570
htup->t_infomask &= ~(HEAP_XMIN_COMMITTED |

‎src/backend/commands/vacuum.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.188 2001/03/22 03:59:24 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.189 2001/03/25 23:23:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -303,10 +303,9 @@ getrels(NameData *VacRelP)
303303
found= true;
304304

305305
d=heap_getattr(tuple,Anum_pg_class_relname,tupdesc,&n);
306-
rname= (char*)d;
306+
rname= (char*)DatumGetPointer(d);
307307

308308
d=heap_getattr(tuple,Anum_pg_class_relkind,tupdesc,&n);
309-
310309
rkind=DatumGetChar(d);
311310

312311
if (rkind!=RELKIND_RELATION)
@@ -997,8 +996,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
997996
blkno;
998997
Pagepage,
999998
ToPage=NULL;
1000-
OffsetNumberoffnum=0,
1001-
maxoff=0,
999+
OffsetNumberoffnum,
1000+
maxoff,
10021001
newoff,
10031002
max_offset;
10041003
ItemIditemid,
@@ -1913,14 +1912,15 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)"
19131912
if (vacpage->blkno== (BlockNumber) (blkno-1)&&
19141913
vacpage->offsets_free>0)
19151914
{
1916-
charunbuf[BLCKSZ];
1917-
OffsetNumber*unused=(OffsetNumber*)unbuf;
1915+
OffsetNumberunbuf[BLCKSZ/sizeof(OffsetNumber)];
1916+
OffsetNumber*unused=unbuf;
19181917
intuncnt;
19191918

19201919
buf=ReadBuffer(onerel,vacpage->blkno);
19211920
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
19221921
page=BufferGetPage(buf);
19231922
num_tuples=0;
1923+
maxoff=PageGetMaxOffsetNumber(page);
19241924
for (offnum=FirstOffsetNumber;
19251925
offnum <=maxoff;
19261926
offnum=OffsetNumberNext(offnum))
@@ -2061,8 +2061,8 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
20612061
staticvoid
20622062
vacuum_page(Relationonerel,Bufferbuffer,VacPagevacpage)
20632063
{
2064-
charunbuf[BLCKSZ];
2065-
OffsetNumber*unused=(OffsetNumber*)unbuf;
2064+
OffsetNumberunbuf[BLCKSZ/sizeof(OffsetNumber)];
2065+
OffsetNumber*unused=unbuf;
20662066
intuncnt;
20672067
Pagepage=BufferGetPage(buffer);
20682068
ItemIditemid;

‎src/backend/storage/large_object/inv_api.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.86 2001/03/22 03:59:45 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.87 2001/03/25 23:23:59 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -416,8 +416,11 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
416416
boolneednextpage;
417417
bytea*datafield;
418418
boolpfreeit;
419-
charworkbuf[LOBLKSIZE+VARHDRSZ];
420-
char*workb=VARATT_DATA(workbuf);
419+
struct {
420+
structvarlenahdr;
421+
chardata[LOBLKSIZE];
422+
}workbuf;
423+
char*workb=VARATT_DATA(&workbuf.hdr);
421424
HeapTuplenewtup;
422425
Datumvalues[Natts_pg_largeobject];
423426
charnulls[Natts_pg_largeobject];
@@ -526,15 +529,15 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
526529
off+=n;
527530
/* compute valid length of new page */
528531
len= (len >=off) ?len :off;
529-
VARATT_SIZEP(workbuf)=len+VARHDRSZ;
532+
VARATT_SIZEP(&workbuf.hdr)=len+VARHDRSZ;
530533

531534
/*
532535
* Form and insert updated tuple
533536
*/
534537
memset(values,0,sizeof(values));
535538
memset(nulls,' ',sizeof(nulls));
536539
memset(replace,' ',sizeof(replace));
537-
values[Anum_pg_largeobject_data-1]=PointerGetDatum(workbuf);
540+
values[Anum_pg_largeobject_data-1]=PointerGetDatum(&workbuf);
538541
replace[Anum_pg_largeobject_data-1]='r';
539542
newtup=heap_modifytuple(&oldtuple,obj_desc->heap_r,
540543
values,nulls,replace);
@@ -575,7 +578,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
575578
obj_desc->offset+=n;
576579
/* compute valid length of new page */
577580
len=off+n;
578-
VARATT_SIZEP(workbuf)=len+VARHDRSZ;
581+
VARATT_SIZEP(&workbuf.hdr)=len+VARHDRSZ;
579582

580583
/*
581584
* Form and insert updated tuple
@@ -584,7 +587,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
584587
memset(nulls,' ',sizeof(nulls));
585588
values[Anum_pg_largeobject_loid-1]=ObjectIdGetDatum(obj_desc->id);
586589
values[Anum_pg_largeobject_pageno-1]=Int32GetDatum(pageno);
587-
values[Anum_pg_largeobject_data-1]=PointerGetDatum(workbuf);
590+
values[Anum_pg_largeobject_data-1]=PointerGetDatum(&workbuf);
588591
newtup=heap_formtuple(obj_desc->heap_r->rd_att,values,nulls);
589592
heap_insert(obj_desc->heap_r,newtup);
590593
if (write_indices)

‎src/backend/utils/mb/wstrncmp.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ register const pg_wchar *s1,
4343
*s2;
4444
registersize_tn;
4545
{
46-
4746
if (n==0)
4847
return0;
4948
do
5049
{
5150
if (*s1!=*s2++)
52-
return (*(constpg_wchar*)s1-
53-
*(constpg_wchar*) (s2-1));
51+
return (*s1-*(s2-1));
5452
if (*s1++==0)
5553
break;
5654
}while (--n!=0);
@@ -63,14 +61,12 @@ register const char *s1;
6361
registerconstpg_wchar*s2;
6462
registersize_tn;
6563
{
66-
6764
if (n==0)
6865
return0;
6966
do
7067
{
71-
if ((pg_wchar)*s1!=*s2++)
72-
return (*(constpg_wchar*)s1-
73-
*(constpg_wchar*) (s2-1));
68+
if ((pg_wchar) ((unsignedchar)*s1)!=*s2++)
69+
return ((pg_wchar) ((unsignedchar)*s1)-*(s2-1));
7470
if (*s1++==0)
7571
break;
7672
}while (--n!=0);
@@ -83,6 +79,7 @@ const pg_wchar *str;
8379
{
8480
registerconstpg_wchar*s;
8581

86-
for (s=str;*s;++s);
82+
for (s=str;*s;++s)
83+
;
8784
return (s-str);
8885
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp