Skip to content

Fix unintialized pointer warning in Objects/obmalloc.c#15293

Closed
hansrajdas wants to merge 1 commit intopython:masterfrom
hansrajdas:warning-fix
Closed

Fix unintialized pointer warning in Objects/obmalloc.c#15293
hansrajdas wants to merge 1 commit intopython:masterfrom
hansrajdas:warning-fix

Conversation

@hansrajdas
Copy link
Copy Markdown
Contributor

Steps to reproduce, check compilation logs:

make clean;make

warning-2019-08-15 01-15-06

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is useless and would have a big negative impact on performances.

If you want initialized memory, use PyObject_Calloc(), not PyObject_Malloc(). PyObject_Malloc() returns uninitialized memory by design.

I understand that the compiler warnings says that ptr value may be initialized. GCC is wrong: it is always initialized. What is your GCC version? What is your OS? Please open a bug report.

@bedevere-bot
Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@vstinner vstinner closed this Aug 14, 2019
@vstinner
Copy link
Copy Markdown
Member

If you want the compiler bug to be fixed, please open a bug report. But this change is wrong, so I closed the PR.

@hansrajdas
Copy link
Copy Markdown
Contributor Author

Thanks @vstinner for your valuable inputs. I am using Ubuntu 18.04.2 LTS and GCC version 7.4.0-1ubuntu1~18.04.1. I will open a bug for this compiler warning.

As PyObject_Malloc is designed to return uninitialized memory, we can assign ptr to NULL(void* ptr = NULL) while declaration to fix this warning, will this be a better approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants