Module Name: src Committed By: christos Date: Thu Jun 2 15:11:18 UTC 2016
Modified Files: src/lib/libedit: readline.c Log Message: >From Ingo Schwarze: In libedit, the only way how H_ENTER can fail is memory exhaustion, too, and of course it is handled gracefully, returning -1 from history(). So of course, we will continue to handle it gracefully in add_history() as well, but we are free to decide what to do with the library state in this case because GNU just dies... I think the most reasonable course of action is to simply not change the library state in any way when add_history() fails due to memory exhaustion, but just return. If H_ENTER does not fail, we know that the history now contains at least one entry, so there is no need any longer to check the H_GETSIZE return value. And we can of course always set current_history_valid. While testing these changes, i noticed three problems so closely related that i'd like to fix them in the same diff. 1. libedit has the wrong prototype for add_history(). GNU readline-6.3 defines it as void add_history(const char *). Of course, that is very stupid - no way to report problems to the caller! But the whole point of a compatibility mode is being compatible, so we should ultimately change this. Of course, changing the prototype of a public symbol requires a libedit major bump. I don't want to do that casually. Rather, i will take a note and change the prototype the next time we need a libedit major bump for more important reasons. For now, let's just always return 0. 2. While *implicitely* pushing an old entry off the history increments history_base in GNU readline, testing reveals that *explicitly* deleting one does not. Again, this is not documented, but it applies to both remove_history() and stifle_history(). So delete history_base manipulation from stifle_history(), which also allows to simplify the code and delete two automatic variables. 3. GNU readline add_history(NULL) crashes with a segfault. There is nothing wrong with having a public interface behave that way. Many standard interfaces do, including strlen(3). Such crashes can even be useful to catch buggy application programs. In libedit/readline.c rev. 1.104, Christos made add_history() silently ignore this coding error, according to the commit message to hide a bug in nslookup(1). That change was never merged to OpenBSD. I strongly disagree with this change. If nslookup(1) is still broken, that program needs to be fixed instead. In any case, delete the bogus check; hiding bugs is dangerous. To generate a diff of this commit: cvs rdiff -u -r1.134 -r1.135 src/lib/libedit/readline.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.