This gives a place to store the stratch buffer while preserving the size of history. The scratch buffer will be stored at h->last.
history.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1367097889 25200 # Branch HEAD # Node ID 004fe04e05c7a26067af3bd71985b826430872a4 # Parent d3096e8796e7fcbd7ed507b7502029c7f73f159e Increase the size of the history array by 1. (see #3082) This gives a place to store the stratch buffer while preserving the size of history. The scratch buffer will be stored at h->last. diff --git a/history.c b/history.c --- a/history.c +++ b/history.c @@ -47,17 +47,17 @@ { for (i = 0 ; i < OldSize ; i ++) FREE (&h->hist[i]); FREE (&h->hist); } } if (HistSize) - h->hist = safe_calloc (HistSize, sizeof (char *)); + h->hist = safe_calloc (HistSize + 1, sizeof (char *)); h->cur = 0; h->last = 0; } void mutt_read_histfile (void) { FILE *f; @@ -225,60 +225,60 @@ struct history *h = GET_HISTORY(hclass); if (!HistSize || !h) return; /* disabled */ if (*s) { prev = h->last - 1; - if (prev < 0) prev = HistSize - 1; + if (prev < 0) prev = HistSize; /* don't add to prompt history: * - lines beginning by a space * - repeated lines */ if (*s != ' ' && (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0)) { if (save && SaveHist) save_history (hclass, s); mutt_str_replace (&h->hist[h->last++], s); - if (h->last > HistSize - 1) + if (h->last > HistSize) h->last = 0; } } h->cur = h->last; /* reset to the last entry */ } char *mutt_history_next (history_class_t hclass) { int next; struct history *h = GET_HISTORY(hclass); if (!HistSize || !h) return (""); /* disabled */ next = h->cur + 1; - if (next > HistSize - 1) + if (next > HistSize) next = 0; h->cur = h->hist[next] ? next : 0; return (h->hist[h->cur] ? h->hist[h->cur] : ""); } char *mutt_history_prev (history_class_t hclass) { int prev; struct history *h = GET_HISTORY(hclass); if (!HistSize || !h) return (""); /* disabled */ prev = h->cur - 1; if (prev < 0) { - prev = HistSize - 1; + prev = HistSize; while (prev > 0 && h->hist[prev] == NULL) prev--; } if (h->hist[prev]) h->cur = prev; return (h->hist[h->cur] ? h->hist[h->cur] : ""); }
