]> granicus.if.org Git - python/commitdiff
Bernard Herzog pointed out that rl_parse_and_bind modifies its
authorGuido van Rossum <guido@python.org>
Fri, 4 Dec 1998 15:34:39 +0000 (15:34 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 4 Dec 1998 15:34:39 +0000 (15:34 +0000)
argument string (bad function!), so we make a temporary copy.

Modules/readline.c

index 899a2232b6104465110482f006ada703f56fa7e8..915cc4a16712c6f9ff9b15de3429ff0a2a312656 100644 (file)
@@ -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;
 }