Skip to content

Commit 98be228

Browse files
committed
should not get the aliasing error reported in gnudatalanguage#1852
1 parent 12e394c commit 98be228

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/saverestore.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
434434
return xdr_get_gdl_pos(xdrs); //end of header
435435
}
436436

437+
union U
438+
{
439+
u_int32_t trentedeux[2];
440+
u_int64_t soixantequatre;
441+
};
442+
437443
inline u_int64_t updateNewRecordHeader(XDR *xdrs, u_int64_t cur) {
438444
u_int64_t next = xdr_get_gdl_pos(xdrs);
439445
//dirty trick for compression: write uncompressed, rewind, read what was just written, compress, write over, reset positions.
@@ -457,18 +463,18 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
457463
}
458464
xdr_set_gdl_pos(xdrs, cur-12); //ptrs0
459465
//copy next (64 bit) as two 32 bits. Should be OK on 32 bit machines as next is u_int64.
460-
if (BigEndian()) { //first 32 bit is low, second high (XDRS is BigEndian)
461-
xdr_uint64_t(xdrs, &next);
462-
} else {
463-
u_int32_t first,second;
464-
first = ((u_int32_t *) &next)[0];
465-
second = ((u_int32_t *) &next)[1];
466-
xdr_uint32_t(xdrs, &first);
467-
xdr_uint32_t(xdrs, &second);
466+
if (!BigEndian()) { //first 32 bit is low, second high (XDRS is BigEndian)
467+
U u;
468+
u.soixantequatre=next;
469+
u_int32_t temp=u.trentedeux[0];
470+
u.trentedeux[0]=u.trentedeux[1];
471+
u.trentedeux[1]=temp;
472+
next=u.soixantequatre;
468473
}
474+
xdr_uint64_t(xdrs, &next);
469475
xdr_set_gdl_pos(xdrs, next);
470476
return next;
471-
}
477+
}
472478

473479
u_int64_t writeTimeUserHost(XDR *xdrs, char* FileDatestring, char* FileUser, char* FileHost) {
474480
u_int64_t cur=writeNewRecordHeader(xdrs, TIMESTAMP);

0 commit comments

Comments
 (0)