-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-110819: Fix ‘kind’ may be used uninitialized warning in longobject
#116599
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
Conversation
@FFY00 has a similar PR up: |
longobject
longobject
This is a larger diff, but it avoids the initialisation: diff --git a/Objects/longobject.c b/Objects/longobject.c
index 2d1c6ad788..a631dc05b2 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2197 +2196,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- int kind;
@@ -2249 +2247,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- kind = writer->kind;
@@ -2260 +2257,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- kind = PyUnicode_KIND(v);
@@ -2321,8 +2317,0 @@ long_format_binary(PyObject *aa, int base, int alternate,
- 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);
- }
@@ -2330,3 +2319,14 @@ long_format_binary(PyObject *aa, int base, int alternate,
- Py_UCS4 *p;
- assert (kind == PyUnicode_4BYTE_KIND);
- WRITE_UNICODE_DIGITS(Py_UCS4);
+ int kind = writer ? writer->kind : PyUnicode_KIND(v);
+ 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 {
+ Py_UCS4 *p;
+ assert (kind == PyUnicode_4BYTE_KIND);
+ WRITE_UNICODE_DIGITS(Py_UCS4);
+ }
|
I don't have much bandwidth right now, we can close mine in favor of this PR. |
@erlend-aasland yes, I liked your idea. I've implemented the change. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This comment was marked as outdated.
This comment was marked as outdated.
Thanks everyone involved 👍 |
…gobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This comment was marked as outdated.
This comment was marked as outdated.
GH-116648 is a backport of this pull request to the 3.12 branch. |
This comment was marked as outdated.
This comment was marked as outdated.
…in `longobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
GH-116650 is a backport of this pull request to the 3.11 branch. |
…in `longobject` (pythonGH-116599) (cherry picked from commit eb947cd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
I've also added an
assert
to make sure that both parameterswriter
andbytes_writer
cannot be passed at the same time.longobject.c
#116592maybe-uninitialized
compiler warnings onlong_format_binary
andlong_to_decimal_string_internal
#110819