Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8e75b36

Browse files
committed
Fix unportable, non-spec-compliant use of offsetof() with a nonconstant
member offset.
1 parent b7ca9a9 commit 8e75b36

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Copyright (c) 2001, PostgreSQL Global Development Group
1818
*
19-
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.14 2001/10/25 05:49:40 momjian Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.15 2001/11/26 22:31:08 tgl Exp $
2020
* ----------
2121
*/
2222
#include "postgres.h"
@@ -464,7 +464,8 @@ pgstat_report_tabstat(void)
464464
for (i = 0; i < pgStatTabstatUsed; i++)
465465
{
466466
n = pgStatTabstatMessages[i]->m_nentries;
467-
len = offsetof(PgStat_MsgTabstat, m_entry[n]);
467+
len = offsetof(PgStat_MsgTabstat, m_entry[0]) +
468+
n * sizeof(PgStat_TableEntry);
468469

469470
pgStatTabstatMessages[i]->m_xact_commit = pgStatXactCommit;
470471
pgStatTabstatMessages[i]->m_xact_rollback = pgStatXactRollback;
@@ -573,7 +574,8 @@ pgstat_vacuum_tabstat(void)
573574
*/
574575
if (msg.m_nentries >= PGSTAT_NUM_TABPURGE)
575576
{
576-
len = offsetof(PgStat_MsgTabpurge, m_tableid[msg.m_nentries]);
577+
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
578+
+ msg.m_nentries * sizeof(Oid);
577579

578580
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
579581
pgstat_send(&msg, len);
@@ -587,7 +589,8 @@ pgstat_vacuum_tabstat(void)
587589
*/
588590
if (msg.m_nentries > 0)
589591
{
590-
len = offsetof(PgStat_MsgTabpurge, m_tableid[msg.m_nentries]);
592+
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
593+
+ msg.m_nentries * sizeof(Oid);
591594

592595
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
593596
pgstat_send(&msg, len);

0 commit comments

Comments
 (0)