Skip to content

Commit

Permalink
use a possible solution to #1655
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDuvert committed Nov 14, 2023
1 parent ba16768 commit 0039998
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/saverestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
}
}

//we write only "normal" (i.e. no PROMOTE64) headers
inline uint64_t writeNewRecordHeader(XDR *xdrs, int code){
int32_t rectype=code;
xdr_int32_t(xdrs, &rectype); //-16
Expand Down Expand Up @@ -183,11 +184,15 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
}
xdr_set_gdl_pos(xdrs, cur-12); //ptrs0
//copy next (64 bit) as two 32 bits. Should be OK on 32 bit machines as next is uint64.
if (BigEndian()) { //first 32 bit is low, second high (XDRS is BigEndian)
xdr_uint64_t(xdrs, &next);

Check warning on line 188 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L188

Added line #L188 was not covered by tests
} else {
uint32_t first,second;
first = ((uint32_t *) &next)[0];
second = ((uint32_t *) &next)[1];
xdr_uint32_t(xdrs, &first);
xdr_uint32_t(xdrs, &second);
}
xdr_set_gdl_pos(xdrs, next);
return next;
}
Expand Down Expand Up @@ -1601,7 +1606,7 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
//will start at TMESTAMP
uint64_t currentptr = 0;
uint64_t nextptr = LONG;
uint32_t ptrs0, ptrs1;
uint32_t ptr_low, ptr_high;
int32_t rectype;
int32_t UnknownLong;
bool SomethingFussyHappened = true;
Expand All @@ -1625,17 +1630,17 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
{
uint64_t my_ulong64;
if (!xdr_uint64_t(xdrs, &my_ulong64)) break;
nextptr = my_ulong64;
nextptr = my_ulong64; //HDR64 is followed by 2 longs.

Check warning on line 1633 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L1633

Added line #L1633 was not covered by tests
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
} else //the 2 pointers may point together to a l64 address, bug #1545
{
if (!xdr_uint32_t(xdrs, &ptrs0)) break;
nextptr = ptrs0;
if (!xdr_uint32_t(xdrs, &ptrs1)) break;
DULong64 tmp = ptrs1;
{ //we read a sort of BigEndian format
if (!xdr_uint32_t(xdrs, &ptr_low)) break;
if (!xdr_uint32_t(xdrs, &ptr_high)) break;
nextptr = ptr_low;
uint64_t tmp = ptr_high;
nextptr |= (tmp << 32);
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (!xdr_int32_t(xdrs, &UnknownLong)) break; //only 1 long following in non-HDR64 format
if (nextptr <=LONG) e->Throw("error in pointers, please report.");
}

Expand Down Expand Up @@ -1673,6 +1678,7 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
break;
case PROMOTE64:
isHdr64 = true;
Message("Using unsupported PROMOTE64 pointers, expect problems.");

Check warning on line 1681 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L1681

Added line #L1681 was not covered by tests
break;
case IDENTIFICATION:
if (verbose)
Expand Down Expand Up @@ -1808,12 +1814,11 @@ bool_t xdr_set_gdl_pos(XDR *x, long int y){
nextptr = my_ulong64;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
} else
{
if (!xdr_uint32_t(xdrs, &ptrs0)) break;
nextptr = ptrs0;
if (!xdr_uint32_t(xdrs, &ptrs1)) break;
DULong64 tmp = ptrs1;
} else {//we read a sort of BigEndian format
if (!xdr_uint32_t(xdrs, &ptr_low)) break;
if (!xdr_uint32_t(xdrs, &ptr_high)) break;
nextptr = ptr_low;
uint64_t tmp = ptr_high;
nextptr |= (tmp << 32);
if (!xdr_int32_t(xdrs, &UnknownLong)) break;
}
Expand Down

0 comments on commit 0039998

Please sign in to comment.