8000 gh-102509: Start initializing `ob_digit` of `_PyLongValue` by illia-v · Pull Request #102510 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-102509: Start initializing ob_digit of _PyLongValue #102510

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

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Prev Previous commit
Merge branch 'main' into gh-102509
  • Loading branch information
illia-v authored Jul 28, 2023
commit d1016a6dc7f9cd02cde6e8658fd92532b0dc9439
22 changes: 21 additions & 1 deletion Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,31 @@ _PyLong_New(Py_ssize_t size)
PyErr_NoMemory();
return NULL;
}
_PyObject_InitVar((PyVarObject*)result, &PyLong_Type, size);
_PyLong_SetSignAndDigitCount(result, size != 0, size);
_PyObject_Init((PyObject*)result, &PyLong_Type);
/* The digit has to be initialized explicitly to avoid
* use-of-uninitialized-value. */
result->long_value.ob_digit[0] = 0;
return result;
}

PyLongObject *
_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits)
{
assert(digit_count >= 0);
if (digit_count == 0) {
return (PyLongObject *)Py_NewRef(_PyLong_GetZero());
}
PyLongObject *result = _PyLong_New(digit_count);
if (result == NULL) {
PyErr_NoMemory();
return NULL;
}
_PyLong_SetSignAndDigitCount(result, negative?-1:1, digit_count);
memcpy(result->long_value.ob_digit, digits, digit_count * sizeof(digit));
return result;
}

PyObject *
_PyLong_Copy(PyLongObject *src)
{
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0