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

Skip to content

Commit 4e998bc

Browse files
committed
M.-A. Lemburg <[email protected]>:
Fixed problem with Unicode string concatenation: u = (u"abc" u"abc") previously dumped core.
1 parent afe73a4 commit 4e998bc

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Python/compile.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,32 @@ parsestrplus(n)
984984
REQ(CHILD(n, 0), STRING);
985985
if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) {
986986
/* String literal concatenation */
987-
for (i = 1; i < NCH(n) && v != NULL; i++) {
988-
PyString_ConcatAndDel(&v, parsestr(STR(CHILD(n, i))));
987+
for (i = 1; i < NCH(n); i++) {
988+
PyObject *s;
989+
s = parsestr(STR(CHILD(n, i)));
990+
if (s == NULL)
991+
goto onError;
992+
if (PyString_Check(v) && PyString_Check(s)) {
993+
PyString_ConcatAndDel(&v, s);
994+
if (v == NULL)
995+
goto onError;
996+
}
997+
else {
998+
PyObject *temp;
999+
temp = PyUnicode_Concat(v, s);
1000+
Py_DECREF(s);
1001+
if (temp == NULL)
1002+
goto onError;
1003+
Py_DECREF(v);
1004+
v = temp;
1005+
}
9891006
}
9901007
}
9911008
return v;
1009+
1010+
onError:
1011+
Py_XDECREF(v);
1012+
return NULL;
9921013
}
9931014

9941015
static void

0 commit comments

Comments
 (0)