Fix unportable, non-spec-compliant use of offsetof() with a nonconstant

member offset.
This commit is contained in:
Tom Lane 2001-11-26 22:31:08 +00:00
parent b7ca9a9403
commit 8e75b36aeb

View File

@ -16,7 +16,7 @@
*
* Copyright (c) 2001, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.14 2001/10/25 05:49:40 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.15 2001/11/26 22:31:08 tgl Exp $
* ----------
*/
#include "postgres.h"
@ -464,7 +464,8 @@ pgstat_report_tabstat(void)
for (i = 0; i < pgStatTabstatUsed; i++)
{
n = pgStatTabstatMessages[i]->m_nentries;
len = offsetof(PgStat_MsgTabstat, m_entry[n]);
len = offsetof(PgStat_MsgTabstat, m_entry[0]) +
n * sizeof(PgStat_TableEntry);
pgStatTabstatMessages[i]->m_xact_commit = pgStatXactCommit;
pgStatTabstatMessages[i]->m_xact_rollback = pgStatXactRollback;
@ -573,7 +574,8 @@ pgstat_vacuum_tabstat(void)
*/
if (msg.m_nentries >= PGSTAT_NUM_TABPURGE)
{
len = offsetof(PgStat_MsgTabpurge, m_tableid[msg.m_nentries]);
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
+ msg.m_nentries * sizeof(Oid);
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
pgstat_send(&msg, len);
@ -587,7 +589,8 @@ pgstat_vacuum_tabstat(void)
*/
if (msg.m_nentries > 0)
{
len = offsetof(PgStat_MsgTabpurge, m_tableid[msg.m_nentries]);
len = offsetof(PgStat_MsgTabpurge, m_tableid[0])
+ msg.m_nentries * sizeof(Oid);
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE);
pgstat_send(&msg, len);