Fix bug 1086603 (segfault in readline) by checking for negative input indices in remove_history_item and replace_history_item; GNU code doesn't always return NULL.
Logged In: YES user_id=488897 I have run the test suite after applying this patch, and I found no problems with it. The bug does indeed originate in the readline library, which does not return NULL if the index is negative. I sent a patch to bug-readline@gnu.org, so this will probably be fixed in future versions of readline. But I agree that for now, we need a workaround in Python. Note that there is one more way to fix this bug, which is to interpret negative indeces as counting from the end. So remove_history_item(-1) removes the last item added to the history etc. This would be more consistent with lists etc. in Python, and users may even expect this behavior.
Logged In: YES user_id=1175690 You could do it, but it'd be a larger change: e.g. get_history_item should change as well. The API isn't very listish. Right now get_history_item(-1) returns None, which I left alone because I didn't want to change any previously-working behaviour of the code, though I doubt many people are depending on that.. This comes at the cost of introducing an arguable inconsistency: get_history_item(-1) simply returns None but remove_history_item(-1) raises an error. I wasn't sure to what degree py-gnu-readline is supposed to hew to gnu-readline, so I left everything alone but the case that was segfaulting my fuzz test. :-)
Logged In: YES user_id=488897 I think that both solutions would be good (certainly better than segfaulting). I'll write a patch review to the python-dev mailing list outlining the pros and cons, so hopefully a developer will look at this patch (I don't have CVS write access, so I can't apply the patch myself).