Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34c20cf

Browse files
committed
Patch #102955, fixing one of the warnings in bug #121479:
Simplifies ord()'s logic at the cost of some code duplication, removing a " `ord' might be used uninitialized in this function" warning
1 parent c867f74 commit 34c20cf

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Python/bltinmodule.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
fo
22
/* Built-in functions */
33

44
#include "Python.h"
@@ -1512,20 +1512,22 @@ builtin_ord(PyObject *self, PyObject *args)
15121512

15131513
if (PyString_Check(obj)) {
15141514
size = PyString_GET_SIZE(obj);
1515-
if (size == 1)
1515+
if (size == 1) {
15161516
ord = (long)((unsigned char)*PyString_AS_STRING(obj));
1517+
return PyInt_FromLong(ord);
1518+
}
15171519
} else if (PyUnicode_Check(obj)) {
15181520
size = PyUnicode_GET_SIZE(obj);
1519-
if (size == 1)
1521+
if (size == 1) {
15201522
ord = (long)*PyUnicode_AS_UNICODE(obj);
1523+
return PyInt_FromLong(ord);
1524+
}
15211525
} else {
15221526
PyErr_Format(PyExc_TypeError,
15231527
"ord() expected string or Unicode character, " \
15241528
"%.200s found", obj->ob_type->tp_name);
15251529
return NULL;
15261530
}
1527-
if (size == 1)
1528-
return PyInt_FromLong(ord);
15291531

15301532
PyErr_Format(PyExc_TypeError,
15311533
"ord() expected a character, length-%d string found",

0 commit comments

Comments
 (0)