Skip to content

Commit

Permalink
Fix off-by-one error in PyMem_Malloc() call in
Browse files Browse the repository at this point in the history
psyco_conn_set_client_encoding().  Fixes psycopg#211
  • Loading branch information
jhenstridge committed Feb 13, 2008
1 parent 6c2e3ab commit b5f4a5f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions psycopg/connection_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit b5f4a5f

Please sign in to comment.