-
-
Notifications
You must be signed in to change notification settings - Fork 87
Fix that malloc() doesn't return a null pointer for too large allocations #117
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
Conversation
…ions The _sbrk() function wasn't implemented. It's used by malloc() to request more heap memory. This function must be defined and correctly implemented if we want malloc() to return a null pointer if more space is requested than is available. It already works that way for the Mbed Core (although with a different implementation), but doesn't for the Renesas Core before this addition.
@alrvid I think we are already including this implementation of |
Interesting, because when I call malloc() with very large requests I get a non-null pointer back, and when I add my fix I get a null pointer back. So I assumed that you hadn't implemented it. There must be something else going wrong then, because malloc() doesn't work correctly in this aspect. I've tried it on both the C33 and the Uno R4 with the same result. |
Sorry for butting in, but was curious. Quick comments:
Code in PR does not round up:
Not sure why new one would detect it and the old one did not? They do have different parameter types: int versus ptrdiff_t |
This function isn't necessary when the root cause is fixed in the next commit.
The malloc() function doesn't return a null pointer for too large requests. The cause is that the _sbrk() function isn't linked from the Renesas FSP as it should be, but instead from the Arm toolchain. This fix makes sure that the correct version of _sbrk() is linked.
The issue was that the _sbrk() function from the Renesas FSP wasn't linked as it should. Instead, we got a _sbrk() from the Arm toolchain. Since both these come from .a files, my first fix solved it by overriding the Arm toolchain version (coming from an .o file at link time). But this new fix solves the root cause, and the old one is no longer necessary. |
Another option would be to use |
I love the final solution, thank you so much! Merging! |
The _sbrk() function wasn't implemented. It's used by malloc() to request more heap memory. This function must be defined and correctly implemented if we want malloc() to return a null pointer if more space is requested than is available. It already works that way for the Mbed Core (although with a different implementation), but doesn't for the Renesas Core before this addition.