diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 38ca5f90..5c54f160 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -195,12 +195,12 @@ psyco_conn_set_client_encoding(connectionObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "s", &enc)) return NULL; /* convert to upper case and remove '-' and '_' from string */ - buffer = PyMem_Malloc(strlen(enc)); + buffer = PyMem_Malloc(strlen(enc)+1); for (i=j=0 ; i < strlen(enc) ; i++) { if (enc[i] == '_' || enc[i] == '-') - continue; - else - buffer[j++] = toupper(enc[i]); + continue; + else + buffer[j++] = toupper(enc[i]); } buffer[j] = '\0';