From: Guido van Rossum Date: Fri, 4 Dec 1998 15:34:39 +0000 (+0000) Subject: Bernard Herzog pointed out that rl_parse_and_bind modifies its X-Git-Tag: v1.5.2b1~129 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b5330ef2d9b6c19ac18e7630059d90e4f5ab991;p=python Bernard Herzog pointed out that rl_parse_and_bind modifies its argument string (bad function!), so we make a temporary copy. --- diff --git a/Modules/readline.c b/Modules/readline.c index 899a2232b6..915cc4a167 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -48,10 +48,17 @@ parse_and_bind(self, args) PyObject *self; PyObject *args; { - char *s; + char *s, *copy; if (!PyArg_ParseTuple(args, "s", &s)) return NULL; - rl_parse_and_bind(s); + /* Make a copy -- rl_parse_and_bind() modifies its argument */ + /* Bernard Herzog */ + copy = malloc(1 + strlen(s)); + if (copy == NULL) + return PyErr_NoMemory(); + strcpy(copy, s); + rl_parse_and_bind(copy); + free(copy); /* Free the copy */ Py_INCREF(Py_None); return Py_None; }