Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misaligned pointer access in the command list. #19

Open
prideout opened this issue Oct 28, 2019 · 1 comment
Open

Misaligned pointer access in the command list. #19

prideout opened this issue Oct 28, 2019 · 1 comment

Comments

@prideout
Copy link
Contributor

This is minor but it might be nice to fix the address sanitizer output that look like this:

runtime error: member access within misaligned address 0x000112e73f44 for type 'mu_Command', which requires 8 byte alignment

Thankfully this seems really to fix:

  1. Add an expect(size % 8 == 0) at the top of mu_push_command
  2. Add 4 bytes of padding to mu_RectCommand
  3. Change mu_draw_text to do:
    int aligned_size = len + 8 - (len % 8);
    cmd = mu_push_command(ctx, MU_COMMAND_TEXT, sizeof(mu_TextCommand) + aligned_size);
@andreas-jonsson
Copy link

Same issue here.

I fixed it by changing mu_push_command to this:

mu_Command* mu_push_command(mu_Context *ctx, int type, int size) {
  mu_Command *cmd = (mu_Command*) (ctx->command_list.items + ctx->command_list.idx);
  const int al = sizeof(void*) - 1;
  size = (size + al) & ~al;
  expect(size % sizeof(void*) == 0);
  expect(ctx->command_list.idx + size < MU_COMMANDLIST_SIZE);
  cmd->base.type = type;
  cmd->base.size = size;
  ctx->command_list.idx += size;
  return cmd;
}

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

No branches or pull requests

2 participants