FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-106307: Fix PyMapping_GetOptionalItemString() by serhiy-storchaka · Pull Request #108797 · python/cpython · GitHub

/ cpython Public

gh-106307: Fix PyMapping_GetOptionalItemString() - #108797

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:PyMapping_GetOptionalItemString-errors
Sep 6, 2023
Merged

gh-106307: Fix PyMapping_GetOptionalItemString()#108797
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:PyMapping_GetOptionalItemString-errors

Conversation

Copy link
Copy Markdown
Member

The resulting pointer was not set to NULL if the creation of a temporary string object was failed.

The tests were also missed due to oversight.

The resulting pointer was not set to NULL if the creation of a temporary
string object was failed.

The tests were also missed due to oversight.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. I just propose adding a comment on the new macro.

Does Valgrind or similar tool detect the usage of uninitialized memory?

Comment thread Modules/_testcapi/util.h
serhiy-storchaka enabled auto-merge (squash) September 6, 2023 19:39
serhiy-storchaka merged commit 3a08db8 into python:main Sep 6, 2023

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

The _testcapi now intializes the variable used in the test:

static PyObject *
mapping_getoptionalitemstring(PyObject *self, PyObject *args)
{
    PyObject *obj, *value = UNINITIALIZED_PTR;

vstinner commented Sep 6, 2023

Copy link
Copy Markdown
Member

@erlend-aasland: Idea for the devguide: We should suggest to always initialized the &value parameter to NULL in case of errors. I just avoid any risk of using an uninitialized variable by misusing the C API. What do you think?

Copy link
Copy Markdown
Contributor

@erlend-aasland: Idea for the devguide: We should suggest to always initialized the &value parameter to NULL in case of errors. I just avoid any risk of using an uninitialized variable by misusing the C API. What do you think?

I have a PR for this, and you already approved it twice 😃 python/devguide#1128

Copy link
Copy Markdown
Member Author

There are exceptions, like _PyEval_SliceIndex(), where the output parameter should not be set in some cases.

serhiy-storchaka deleted the PyMapping_GetOptionalItemString-errors branch September 7, 2023 09:07

Copy link
Copy Markdown
Contributor

Exceptions are fine; guidelines are for the general case, not the special case.

vstinner commented Sep 7, 2023

Copy link
Copy Markdown
Member

I have a PR for this, and you already approved it twice 😃 python/devguide#1128

Alright, I should approve it 3 or 4 times 👍👍👍👍

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL