diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-03 18:24:43 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-03 18:24:43 (GMT) |
commit | a85998af7c44c047cb4e35cfa8373330e3f45088 (patch) | |
tree | 4f8af4d5cd63bb592f4504b729916a3cf8bb9285 /Modules/parsermodule.c | |
parent | 999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff) | |
download | cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2 |
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 9cc1227..497d4e6 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -717,11 +717,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num) Py_DECREF(o); } } - temp_str = PyUnicode_AsString(temp); - len = PyUnicode_GET_SIZE(temp) + 1; - strn = (char *)PyObject_MALLOC(len); + temp_str = PyUnicode_AsStringAndSize(temp, &len); + strn = (char *)PyObject_MALLOC(len + 1); if (strn != NULL) - (void) memcpy(strn, temp_str, len); + (void) memcpy(strn, temp_str, len + 1); Py_DECREF(temp); } else if (!ISNONTERMINAL(type)) { @@ -807,11 +806,10 @@ build_node_tree(PyObject *tuple) if (res && encoding) { Py_ssize_t len; const char *temp; - temp = PyUnicode_AsString(encoding); - len = PyUnicode_GET_SIZE(encoding) + 1; - res->n_str = (char *)PyObject_MALLOC(len); + temp = PyUnicode_AsStringAndSize(encoding, &len); + res->n_str = (char *)PyObject_MALLOC(len + 1); if (res->n_str != NULL && temp != NULL) - (void) memcpy(res->n_str, temp, len); + (void) memcpy(res->n_str, temp, len + 1); Py_DECREF(encoding); Py_DECREF(tuple); } |