summaryrefslogtreecommitdiffstats
path: root/Modules
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 /Modules
parent999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff)
downloadcpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz
cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c3
-rw-r--r--Modules/parsermodule.c14
-rw-r--r--Modules/zipimport.c15
3 files changed, 14 insertions, 18 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 711adba..e64b230 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1217,10 +1217,9 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(object && format && timetuple);
assert(PyUnicode_Check(format));
/* Convert the input format to a C string and size */
- pin = PyUnicode_AsString(format);
+ pin = PyUnicode_AsStringAndSize(format, &flen);
if (!pin)
return NULL;
- flen = PyUnicode_GetSize(format);
/* Give up if the year is before 1900.
* Python strftime() plays games with the year, and different
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);
}
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index cd56be3..3b8eb93 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -61,16 +61,14 @@ static int
zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
{
char *path, *p, *prefix, buf[MAXPATHLEN+2];
- size_t len;
+ Py_ssize_t len;
if (!_PyArg_NoKeywords("zipimporter()", kwds))
return -1;
- if (!PyArg_ParseTuple(args, "s:zipimporter",
- &path))
+ if (!PyArg_ParseTuple(args, "s#:zipimporter", &path, &len))
return -1;
- len = strlen(path);
if (len == 0) {
PyErr_SetString(ZipImportError, "archive path is empty");
return -1;
@@ -329,7 +327,7 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
fullpath = PyUnicode_FromFormat("%s%c%s%s",
PyUnicode_AsString(self->archive),
SEP,
- *prefix ? prefix : "",
+ prefix ? prefix : "",
subname);
if (fullpath == NULL)
goto error;
@@ -388,6 +386,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
#endif
PyObject *toc_entry;
Py_ssize_t len;
+ char *archive_str;
if (!PyArg_ParseTuple(args, "s:zipimporter.get_data", &path))
return NULL;
@@ -404,9 +403,9 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
}
path = buf;
#endif
- len = PyUnicode_GET_SIZE(self->archive);
+ archive_str = PyUnicode_AsStringAndSize(self->archive, &len);
if ((size_t)len < strlen(path) &&
- strncmp(path, PyUnicode_AsString(self->archive), len) == 0 &&
+ strncmp(path, archive_str, len) == 0 &&
path[len] == SEP) {
path = path + len + 1;
}
@@ -416,7 +415,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
PyErr_SetFromErrnoWithFilename(PyExc_IOError, path);
return NULL;
}
- return get_data(PyUnicode_AsString(self->archive), toc_entry);
+ return get_data(archive_str, toc_entry);
}
static PyObject *