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

Remove unnecessary null pointer checks #3

Open
elfring opened this issue Aug 26, 2020 · 1 comment
Open

Remove unnecessary null pointer checks #3

elfring opened this issue Aug 26, 2020 · 1 comment

Comments

@elfring
Copy link

elfring commented Aug 26, 2020

An extra null pointer check is not needed in functions like the following.

@DyncEric
Copy link
Contributor

Thanks, it's will be modified soon.
Free(NULL); same as delete NULL;
I didn't think about it before.

**Description
The C library function void free(void ptr) deallocates the memory previously allocated by a call to calloc, malloc, or realloc.
Declaration
Following is the declaration for free() function.
void free(void ptr)
Parameters
ptr —— This is the pointer to a memory block previously allocated with malloc, calloc or realloc to be deallocated. If a null pointer is passed as argument, no action occurs.
Return Value
This function does not return any value.

**Description
The C++ language guarantees that delete p will do nothing if p is null. Since you might get the test backwards, and since most testing methodologies force you to explicitly test every branch point, you should not put in the redundant if test.

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