mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-110819: Fix ‘kind’ may be used uninitialized warning in longobject
(GH-116599) (#116648)
gh-110819: Fix ‘kind’ may be used uninitialized warning in `longobject` (GH-116599)
(cherry picked from commit eb947cdc13
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
d4e8cbbed4
commit
4ea9d15761
1 changed files with 35 additions and 28 deletions
|
@ -1766,7 +1766,9 @@ long_to_decimal_string_internal(PyObject *aa,
|
||||||
digit *pout, *pin, rem, tenpow;
|
digit *pout, *pin, rem, tenpow;
|
||||||
int negative;
|
int negative;
|
||||||
int d;
|
int d;
|
||||||
int kind;
|
|
||||||
|
// writer or bytes_writer can be used, but not both at the same time.
|
||||||
|
assert(writer == NULL || bytes_writer == NULL);
|
||||||
|
|
||||||
a = (PyLongObject *)aa;
|
a = (PyLongObject *)aa;
|
||||||
if (a == NULL || !PyLong_Check(a)) {
|
if (a == NULL || !PyLong_Check(a)) {
|
||||||
|
@ -1879,7 +1881,6 @@ long_to_decimal_string_internal(PyObject *aa,
|
||||||
Py_DECREF(scratch);
|
Py_DECREF(scratch);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
kind = writer->kind;
|
|
||||||
}
|
}
|
||||||
else if (bytes_writer) {
|
else if (bytes_writer) {
|
||||||
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, strlen);
|
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, strlen);
|
||||||
|
@ -1894,7 +1895,6 @@ long_to_decimal_string_internal(PyObject *aa,
|
||||||
Py_DECREF(scratch);
|
Py_DECREF(scratch);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
kind = PyUnicode_KIND(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WRITE_DIGITS(p) \
|
#define WRITE_DIGITS(p) \
|
||||||
|
@ -1942,19 +1942,23 @@ long_to_decimal_string_internal(PyObject *aa,
|
||||||
WRITE_DIGITS(p);
|
WRITE_DIGITS(p);
|
||||||
assert(p == *bytes_str);
|
assert(p == *bytes_str);
|
||||||
}
|
}
|
||||||
else if (kind == PyUnicode_1BYTE_KIND) {
|
|
||||||
Py_UCS1 *p;
|
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS1);
|
|
||||||
}
|
|
||||||
else if (kind == PyUnicode_2BYTE_KIND) {
|
|
||||||
Py_UCS2 *p;
|
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS2);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
Py_UCS4 *p;
|
int kind = writer ? writer->kind : PyUnicode_KIND(str);
|
||||||
assert (kind == PyUnicode_4BYTE_KIND);
|
if (kind == PyUnicode_1BYTE_KIND) {
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS4);
|
Py_UCS1 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS1);
|
||||||
|
}
|
||||||
|
else if (kind == PyUnicode_2BYTE_KIND) {
|
||||||
|
Py_UCS2 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert (kind == PyUnicode_4BYTE_KIND);
|
||||||
|
Py_UCS4 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef WRITE_DIGITS
|
#undef WRITE_DIGITS
|
||||||
#undef WRITE_UNICODE_DIGITS
|
#undef WRITE_UNICODE_DIGITS
|
||||||
|
|
||||||
|
@ -1995,11 +1999,12 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
||||||
PyObject *v = NULL;
|
PyObject *v = NULL;
|
||||||
Py_ssize_t sz;
|
Py_ssize_t sz;
|
||||||
Py_ssize_t size_a;
|
Py_ssize_t size_a;
|
||||||
int kind;
|
|
||||||
int negative;
|
int negative;
|
||||||
int bits;
|
int bits;
|
||||||
|
|
||||||
assert(base == 2 || base == 8 || base == 16);
|
assert(base == 2 || base == 8 || base == 16);
|
||||||
|
// writer or bytes_writer can be used, but not both at the same time.
|
||||||
|
assert(writer == NULL || bytes_writer == NULL);
|
||||||
if (a == NULL || !PyLong_Check(a)) {
|
if (a == NULL || !PyLong_Check(a)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2047,7 +2052,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
||||||
if (writer) {
|
if (writer) {
|
||||||
if (_PyUnicodeWriter_Prepare(writer, sz, 'x') == -1)
|
if (_PyUnicodeWriter_Prepare(writer, sz, 'x') == -1)
|
||||||
return -1;
|
return -1;
|
||||||
kind = writer->kind;
|
|
||||||
}
|
}
|
||||||
else if (bytes_writer) {
|
else if (bytes_writer) {
|
||||||
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, sz);
|
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, sz);
|
||||||
|
@ -2058,7 +2062,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
||||||
v = PyUnicode_New(sz, 'x');
|
v = PyUnicode_New(sz, 'x');
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
kind = PyUnicode_KIND(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WRITE_DIGITS(p) \
|
#define WRITE_DIGITS(p) \
|
||||||
|
@ -2119,19 +2122,23 @@ long_format_binary(PyObject *aa, int base, int alternate,
|
||||||
WRITE_DIGITS(p);
|
WRITE_DIGITS(p);
|
||||||
assert(p == *bytes_str);
|
assert(p == *bytes_str);
|
||||||
}
|
}
|
||||||
else if (kind == PyUnicode_1BYTE_KIND) {
|
|
||||||
Py_UCS1 *p;
|
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS1);
|
|
||||||
}
|
|
||||||
else if (kind == PyUnicode_2BYTE_KIND) {
|
|
||||||
Py_UCS2 *p;
|
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS2);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
Py_UCS4 *p;
|
int kind = writer ? writer->kind : PyUnicode_KIND(v);
|
||||||
assert (kind == PyUnicode_4BYTE_KIND);
|
if (kind == PyUnicode_1BYTE_KIND) {
|
||||||
WRITE_UNICODE_DIGITS(Py_UCS4);
|
Py_UCS1 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS1);
|
||||||
|
}
|
||||||
|
else if (kind == PyUnicode_2BYTE_KIND) {
|
||||||
|
Py_UCS2 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert (kind == PyUnicode_4BYTE_KIND);
|
||||||
|
Py_UCS4 *p;
|
||||||
|
WRITE_UNICODE_DIGITS(Py_UCS4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef WRITE_DIGITS
|
#undef WRITE_DIGITS
|
||||||
#undef WRITE_UNICODE_DIGITS
|
#undef WRITE_UNICODE_DIGITS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue