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

Bug in Free List Allocator on 32bit systems #18

Open
kochol opened this issue May 27, 2020 · 3 comments
Open

Bug in Free List Allocator on 32bit systems #18

kochol opened this issue May 27, 2020 · 3 comments

Comments

@kochol
Copy link

kochol commented May 27, 2020

Hi
There is a bug in your Free List Allocator when alignmentPadding is not zero like on 32 bit systems.

const std::size_t alignmentPadding = padding - allocationHeaderSize;

One bug is here obviously and newFreeNode address is inside of the current block when alignmentPadding is not zero.

Node * newFreeNode = (Node *)((std::size_t) affectedNode + requiredSize);

@degski
Copy link

degski commented May 27, 2020

That depends (on Windows) where you get the memory from, as far as I know (VirtualMemory is zeroed), the padding bytes are undefined (so it depends on what the allocator did). On the other hand, you can just set them to zero by making the padding part of your type:

struct alignas ( 8 ) type  { int val, _ = 0; };

@kochol
Copy link
Author

kochol commented May 27, 2020

It is still a bug.

@degski
Copy link

degski commented May 27, 2020

I'm just pointing out to how to keep the padding of an object under control as it might be that comparison might depend on it (like with std::memcmp ) as the size of the object includes the padding (so one could be more careful from the get-go), it will not compare equal when the padding differs, while they all have equivalent (e.i. not unequal) value (equal is not necessarily equal to not unequal, its' defined as equivalence). Somewhere someone needs to put a zero, and/or make sure the padding is not considered in any comparison, initing the padding is an option (and makes clear there is some unused space in the struct available for future use):

struct alignas ( 16 ) type2  { long long value, reserved_ = 0; };

The trick is to have no padding, which can be statically asserted and/or sfinaed, specilized.

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