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

Don't cast the return pointer from [cm]alloc(3) #11

Merged
merged 1 commit into from
Apr 8, 2020

Conversation

ac000
Copy link
Contributor

@ac000 ac000 commented Apr 7, 2020

Hi,

First I acknowledge that this may be contentious, so no worries if you choose not to apply this.

Some background.

In C, you don't need to (and perhaps really shouldn't) cast the return pointer from calloc/malloc/realloc etc. In fact doing so can hide bugs.

See 0 for a lengthy debate on the topic... also note the "Exceptions" from 1. But the general consensus seems to be that you shouldn't cast the pointer returned, and I'm firmly in that camp...

Cheers,
Andrew

In C, you don't need to cast the return pointer from
calloc/malloc/realloc etc. In fact doing so can hide bugs.

See [0] for a lengthy debate on the topic... also note the "Exceptions"
from [1] relating to the above bug hiding.

[0]: https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
[1]: https://wiki.sei.cmu.edu/confluence/display/c/MEM02-C.+Immediately+cast+the+result+of+a+memory+allocation+function+call+into+a+pointer+to+the+allocated+type
@TimeToogo TimeToogo merged commit 86c8b45 into TimeToogo:master Apr 8, 2020
@TimeToogo
Copy link
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants