summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
committerAlexandre Vassalotti <alexandre@peadrop.com>2008-05-03 18:24:43 (GMT)
commita85998af7c44c047cb4e35cfa8373330e3f45088 (patch)
tree4f8af4d5cd63bb592f4504b729916a3cf8bb9285 /Python
parent999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff)
downloadcpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c13
-rw-r--r--Python/structmember.c15
2 files changed, 20 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c
index 8b11aad..5dabd9f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2131,13 +2131,15 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
if ((pkgname != NULL) && (pkgname != Py_None)) {
/* __package__ is set, so use it */
+ char *pkgname_str;
Py_ssize_t len;
+
if (!PyUnicode_Check(pkgname)) {
PyErr_SetString(PyExc_ValueError,
"__package__ set to non-string");
return NULL;
}
- len = PyUnicode_GET_SIZE(pkgname);
+ pkgname_str = PyUnicode_AsStringAndSize(pkgname, &len);
if (len == 0) {
if (level > 0) {
PyErr_SetString(PyExc_ValueError,
@@ -2151,7 +2153,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
"Package name too long");
return NULL;
}
- strcpy(buf, PyUnicode_AsString(pkgname));
+ strcpy(buf, pkgname_str);
} else {
/* __package__ not set, so figure it out and set it */
modname = PyDict_GetItem(globals, namestr);
@@ -2161,14 +2163,17 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
modpath = PyDict_GetItem(globals, pathstr);
if (modpath != NULL) {
/* __path__ is set, so modname is already the package name */
- Py_ssize_t len = PyUnicode_GET_SIZE(modname);
+ char *modname_str;
+ Py_ssize_t len;
int error;
+
+ modname_str = PyUnicode_AsStringAndSize(modname, &len);
if (len > MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError,
"Module name too long");
return NULL;
}
- strcpy(buf, PyUnicode_AsString(modname));
+ strcpy(buf, modname_str);
error = PyDict_SetItem(globals, pkgstr, modname);
if (error) {
PyErr_SetString(PyExc_ValueError,
diff --git a/Python/structmember.c b/Python/structmember.c
index 769acfc..6c1e932 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -239,15 +239,22 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
*(PyObject **)addr = v;
Py_XDECREF(oldv);
break;
- case T_CHAR:
- if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) {
- *(char*)addr = PyUnicode_AsString(v)[0];
+ case T_CHAR: {
+ char *string;
+ Py_ssize_t len;
+
+ if (!PyUnicode_Check(v)) {
+ PyErr_BadArgument();
+ return -1;
}
- else {
+ string = PyUnicode_AsStringAndSize(v, &len);
+ if (len != 1) {
PyErr_BadArgument();
return -1;
}
+ *(char*)addr = string[0];
break;
+ }
#ifdef HAVE_LONG_LONG
case T_LONGLONG:{
PY_LONG_LONG value;