Skip to content

Commit 93f3467

Browse files
committed
iobuffer: Fix encoding/decoding on big-endian
It is possible (albeit unusual) to boot a big-endian system on a smartphone, and it's generally good to have portable code. le32toh and htole32 are a glibc extension that is also implemented by musl-libc, uclibc-ng, and bionic. Signed-off-by: J. Neuschäfer <[email protected]>
1 parent c4109b4 commit 93f3467

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

hexagonrpcd/iobuffer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ static size_t consume_size(struct fastrpc_decoder_context *ctx,
3939
ctx->size_off = (ctx->size_off + segment) % 4;
4040
ctx->align = (ctx->align + segment) & 0x7;
4141

42+
if (ctx->size_off == 0)
43+
ctx->size = le32toh(ctx->size);
44+
4245
return segment;
4346
}
4447

@@ -212,7 +215,7 @@ void outbufs_encode(size_t n_outbufs, const struct fastrpc_io_buffer *outbufs,
212215
size_t i;
213216

214217
for (i = 0; i < n_outbufs; i++) {
215-
*(uint32_t *) ptr = outbufs[i].s;
218+
*(uint32_t *) ptr = htole32(outbufs[i].s);
216219
ptr = &ptr[4];
217220
align = (align + 4) & 0x7;
218221

0 commit comments

Comments
 (0)