Skip to content

Conversation

@neuschaefer
Copy link
Contributor

It is possible (albeit unusual) to boot a big-endian system on a smartphone, and it's generally good to have portable code.

The code readability is debatable, but the function is tested on little-endian and big-endian systems. The iobuffer test passes.

It is possible (albeit unusual) to boot a big-endian system on a
smartphone, and it's generally good to have portable code.

Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
Copy link
Collaborator

@flamingradian flamingradian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not sending a review earlier. I wanted to not add extra functions but couldn't think of how to do this until now.

Comment on lines +58 to 61
ctx->size &= ~(mask_bytes(segment) << ctx->size_off * 8);
ctx->size |= read_le(buf, segment) << ctx->size_off * 8;
ctx->size_off = (ctx->size_off + segment) % 4;
ctx->align = (ctx->align + segment) & 0x7;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx->size &= ~(mask_bytes(segment) << ctx->size_off * 8);
ctx->size |= read_le(buf, segment) << ctx->size_off * 8;
ctx->size_off = (ctx->size_off + segment) % 4;
ctx->align = (ctx->align + segment) & 0x7;
memcpy(&((char *) &ctx->size)[ctx->size_off], buf, segment);
ctx->size_off = (ctx->size_off + segment) % 4;
ctx->align = (ctx->align + segment) & 0x7;
if (ctx->size_off == 0)
ctx->size = htole32(ctx->size);

Maybe this could be converted to host endianness after completely reading the size, instead of adding small functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants