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

Broken calloc implementation #11

Closed
ZeroIntensity opened this issue May 4, 2022 · 0 comments
Closed

Broken calloc implementation #11

ZeroIntensity opened this issue May 4, 2022 · 0 comments

Comments

@ZeroIntensity
Copy link
Owner

it seems my initial guess of why calloc caused so many segfaults was wrong.

example:

from pointers import calloc, free

mem = calloc(200, 28)
mem += 200
mem <<= 1
mem -= 200
print(~mem)  # works just fine!

free(mem)

mem_2 = calloc(4, 28)
mem_2 += 1
mem_2 <<= 1
mem_2 -= 1
print(*mem_2)  # segfault

it seems that i need to skip 24 digits when using pointer arithmetic, not 1.

mem = calloc(200, 28)
mem += 24
mem <<= 1
mem -= 24
print(~mem)  # works correctly, no segfault

another example:

mem = calloc(200, 28)
mem += 23
mem <<= 1
mem -= 23
print(~mem)  # OverflowError
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

1 participant