Skip to content

GH-110819: fix maybe-uninitialized warnings on longobject.c #110821

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
Diff view
6 changes: 4 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ long_to_decimal_string_internal(PyObject *aa,
digit *pout, *pin, rem, tenpow;
int negative;
int d;
int kind;
int kind = -1;

a = (PyLongObject *)aa;
if (a == NULL || !PyLong_Check(a)) {
Expand Down Expand Up @@ -1936,6 +1936,7 @@ long_to_decimal_string_internal(PyObject *aa,
} while (0)

/* fill the string right-to-left */
assert (kind > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This assert would seem to fail when just bytes_writer is passed into the function. It seems that this is the case where kind is uninitialized (the if-block at lines 1875-1896, particularly 1882-1887).

Copy link
Member

Choose a reason for hiding this comment

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

We can fix that and land that PR first.

if (bytes_writer) {
char *p = *bytes_str + strlen;
WRITE_DIGITS(p);
Expand Down Expand Up @@ -1994,7 +1995,7 @@ long_format_binary(PyObject *aa, int base, int alternate,
PyObject *v = NULL;
Py_ssize_t sz;
Py_ssize_t size_a;
int kind;
int kind = -1;
int negative;
int bits;

Expand Down Expand Up @@ -2113,6 +2114,7 @@ long_format_binary(PyObject *aa, int base, int alternate,
assert(p == (TYPE*)PyUnicode_DATA(v)); \
} while (0)

assert (kind > 0);
if (bytes_writer) {
char *p = *bytes_str + sz;
WRITE_DIGITS(p);
Expand Down