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

[suggestion] add a comment at the declaration of mi_arena_t for easier custom modify #896

Closed
LXYan2333 opened this issue May 15, 2024 · 1 comment

Comments

@LXYan2333
Copy link

LXYan2333 commented May 15, 2024

Dear maintainer:

Hello, I suggest to add a comment right after

mi_bitmap_field_t blocks_inuse[1]; // in-place bitmap of in-use blocks (of size `field_count`)

// A memory arena descriptor
typedef struct mi_arena_s {
  //…………
  mi_bitmap_field_t  blocks_inuse[1];     // in-place bitmap of in-use blocks (of size `field_count`)
  // add a comment here: do not add custom field after `blocks_inuse` field because the bitmat array bounds will overflow and override its later fields. check https://github.com/microsoft/mimalloc/blob/81a771161e37c8559c442fff099115cd1977db1e/src/arena.c#L903C3-L903C8
} mi_arena_t;

Array out of bounds is not a well-defined behaviour and should be documented explicitly, or people (like me) may waste some time on it……

Thanks for this awesome project anyway.

@LXYan2333
Copy link
Author

LXYan2333 commented Jul 4, 2024

I just learned that this is something resemble to "flexible array" https://en.wikipedia.org/wiki/Flexible_array_member, but according to https://stackoverflow.com/a/46251908 specify the length of blocks_inuse array is actually an UB.

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