summaryrefslogtreecommitdiff
path: root/psycopg/adapter_binary.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2006-09-01 08:23:51 +0000
committerFederico Di Gregorio <fog@initd.org>2006-09-01 08:23:51 +0000
commitf88b973bd1c70095813d95371550f7c67a3ae84d (patch)
tree00632f99895edb0d5127fed46b7b3e5a2d64622f /psycopg/adapter_binary.c
parent8eb118c63f71a67e2ad699a6ad4d862f520d3c9d (diff)
downloadpsycopg2-f88b973bd1c70095813d95371550f7c67a3ae84d.tar.gz
Empty binary buffer segfault fix (closes: #119).
Diffstat (limited to 'psycopg/adapter_binary.c')
-rw-r--r--psycopg/adapter_binary.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index e380b2b..dcff6ca 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -136,11 +136,14 @@ binary_quote(binaryObject *self)
const char *buffer;
int buffer_len;
size_t len = 0;
-
+
+ if (self->buffer == NULL)
+ self->buffer = PyString_FromString("");
/* if we got a plain string or a buffer we escape it and save the buffer */
- if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
+ else if (PyString_Check(self->wrapped) || PyBuffer_Check(self->wrapped)) {
/* escape and build quoted buffer */
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
+
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
if (to == NULL) {