Skip to content

Commit dcdf911

Browse files
committed
Tweak interval_avg support to avoid coredump with Alpha/Tru64 compiler.
Per report from Bernd Tegge.
1 parent 52ca149 commit dcdf911

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.59 2001/10/25 05:49:45 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.60 2001/11/21 18:29:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1570,9 +1570,12 @@ interval_accum(PG_FUNCTION_ARGS)
15701570
* buggy array code: it won't ensure proper alignment of Interval
15711571
* objects on machines where double requires 8-byte alignment. That
15721572
* should be fixed, but in the meantime...
1573+
*
1574+
* Note: must use DatumGetPointer here, not DatumGetIntervalP,
1575+
* else some compilers optimize into double-aligned load/store anyway.
15731576
*/
1574-
memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval));
1575-
memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval));
1577+
memcpy((void *) &sumX, DatumGetPointer(transdatums[0]), sizeof(Interval));
1578+
memcpy((void *) &N, DatumGetPointer(transdatums[1]), sizeof(Interval));
15761579

15771580
newsum = DatumGetIntervalP(DirectFunctionCall2(interval_pl,
15781581
IntervalPGetDatum(&sumX),
@@ -1609,9 +1612,12 @@ interval_avg(PG_FUNCTION_ARGS)
16091612
* buggy array code: it won't ensure proper alignment of Interval
16101613
* objects on machines where double requires 8-byte alignment. That
16111614
* should be fixed, but in the meantime...
1615+
*
1616+
* Note: must use DatumGetPointer here, not DatumGetIntervalP,
1617+
* else some compilers optimize into double-aligned load/store anyway.
16121618
*/
1613-
memcpy(&sumX, DatumGetIntervalP(transdatums[0]), sizeof(Interval));
1614-
memcpy(&N, DatumGetIntervalP(transdatums[1]), sizeof(Interval));
1619+
memcpy((void *) &sumX, DatumGetPointer(transdatums[0]), sizeof(Interval));
1620+
memcpy((void *) &N, DatumGetPointer(transdatums[1]), sizeof(Interval));
16151621

16161622
/* SQL92 defines AVG of no values to be NULL */
16171623
if (N.time == 0)

0 commit comments

Comments
 (0)