summaryrefslogtreecommitdiff
path: root/Modules/binascii.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-16 17:45:56 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-16 17:45:56 +0000
commitdb983a7c38ba3d98649c916afa12340bd8b6bed2 (patch)
treec2e887f8cac57279d2b4d5127fd80cc16c16b884 /Modules/binascii.c
parentc755dba90680200b550b0d387cbb908ea40ea43a (diff)
downloadcpython-git-db983a7c38ba3d98649c916afa12340bd8b6bed2.tar.gz
Followup to #7703: a2b_hqx() didn't follow the new buffer API (neither in trunk
nor in py3k). Patch by Florent Xicluna as well as additional tests.
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r--Modules/binascii.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index cf027431fa..db675f9eb1 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -537,6 +537,7 @@ PyDoc_STRVAR(doc_a2b_hqx, "ascii -> bin, done. Decode .hqx coding");
static PyObject *
binascii_a2b_hqx(PyObject *self, PyObject *args)
{
+ Py_buffer pascii;
unsigned char *ascii_data, *bin_data;
int leftbits = 0;
unsigned char this_ch;
@@ -545,19 +546,25 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_ssize_t len;
int done = 0;
- if ( !PyArg_ParseTuple(args, "t#:a2b_hqx", &ascii_data, &len) )
+ if ( !PyArg_ParseTuple(args, "s*:a2b_hqx", &pascii) )
return NULL;
+ ascii_data = pascii.buf;
+ len = pascii.len;
assert(len >= 0);
- if (len > PY_SSIZE_T_MAX - 2)
+ if (len > PY_SSIZE_T_MAX - 2) {
+ PyBuffer_Release(&pascii);
return PyErr_NoMemory();
+ }
/* Allocate a string that is too big (fixed later)
Add two to the initial length to prevent interning which
would preclude subsequent resizing. */
- if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, len+2)) == NULL ) {
+ PyBuffer_Release(&pascii);
return NULL;
+ }
bin_data = (unsigned char *)PyString_AS_STRING(rv);
for( ; len > 0 ; len--, ascii_data++ ) {
@@ -567,6 +574,7 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
continue;
if ( this_ch == FAIL ) {
PyErr_SetString(Error, "Illegal char");
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return NULL;
}
@@ -589,6 +597,7 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
if ( leftbits && !done ) {
PyErr_SetString(Incomplete,
"String has incomplete number of bytes");
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return NULL;
}
@@ -600,10 +609,12 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
}
if (rv) {
PyObject *rrv = Py_BuildValue("Oi", rv, done);
+ PyBuffer_Release(&pascii);
Py_DECREF(rv);
return rrv;
}
+ PyBuffer_Release(&pascii);
return NULL;
}