libsframe: write out SFrame FRE start address correctly

The following test was failing on ppc64 and s390x:
  "FAIL: encode-1: Encode buffer match"

The offending stub was how we memcpy the FRE start address to the buffer
(on-disk format).  When the host is big-endian, the address of the
source buffer for the memcpy needs to point to the uint8_t/uint16_t sized
value of the FRE start addr, not uint32_t sized value; we intend to copy
out only the fre_start_addr_sz number of bytes.

ChangeLog:

	* libsframe/sframe.c (sframe_encoder_write_fre_start_addr): New
	function.
	(sframe_encoder_write_fre): Use it instead of memcpy.
This commit is contained in:
Indu Bhagat 2022-12-25 00:06:22 -08:00
parent 111b1cf97e
commit 68bb0d2765

View File

@ -1502,6 +1502,39 @@ sframe_sort_funcdesc (sframe_encoder_ctx *encoder)
return 0;
}
/* Write the SFrame FRE start address from the in-memory FRE_START_ADDR
to the buffer CONTENTS (on-disk format), given the FRE_TYPE and
FRE_START_ADDR_SZ. */
static int
sframe_encoder_write_fre_start_addr (char *contents,
uint32_t fre_start_addr,
unsigned int fre_type,
size_t fre_start_addr_sz)
{
int err = 0;
if (fre_type == SFRAME_FRE_TYPE_ADDR1)
{
uint8_t uc = fre_start_addr;
memcpy (contents, &uc, fre_start_addr_sz);
}
else if (fre_type == SFRAME_FRE_TYPE_ADDR2)
{
uint16_t ust = fre_start_addr;
memcpy (contents, &ust, fre_start_addr_sz);
}
else if (fre_type == SFRAME_FRE_TYPE_ADDR4)
{
uint32_t uit = fre_start_addr;
memcpy (contents, &uit, fre_start_addr_sz);
}
else
return sframe_set_errno (&err, SFRAME_ERR_INVAL);
return 0;
}
/* Write a frame row entry pointed to by FREP into the buffer CONTENTS. The
size in bytes written out are updated in ESZ.
@ -1529,9 +1562,8 @@ sframe_encoder_write_fre (char *contents, sframe_frame_row_entry *frep,
uint64_t bitmask = SFRAME_BITMASK_OF_SIZE (fre_start_addr_sz);
sframe_assert ((uint64_t)frep->fre_start_addr <= bitmask);
memcpy (contents,
&frep->fre_start_addr,
fre_start_addr_sz);
sframe_encoder_write_fre_start_addr (contents, frep->fre_start_addr,
fre_type, fre_start_addr_sz);
contents += fre_start_addr_sz;
memcpy (contents,