Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 46644:ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Sat, 03 May 2008 18:24:43 +0000 |
| parents | b91ca87e6f32 |
| children | dd5513b472dc |
line wrap: on
line diff
--- a/Modules/parsermodule.c Sat May 03 04:42:16 2008 +0000 +++ b/Modules/parsermodule.c Sat May 03 18:24:43 2008 +0000 @@ -717,11 +717,10 @@ 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 @@ 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); }
