[prev in list] [next in list] [prev in thread] [next in thread]
List: mutt-dev
Subject: Re: [PATCH 1 of 3] Increase the size of the history array by 1. (see #3082)
From: "Kevin J. McCarthy" <kevin () 8t8 ! us>
Date: 2013-04-27 23:13:57
Message-ID: 20130427231357.GB3420 () zaogao ! lan
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
As soon as I sent the patch, I realized I forgot to fix the
re-allocation loop with OldSize in init_history().
Corrected patch attached, and uploaded to trac too.
-Kevin
["part-1-increase-history-array-size.patch" (text/x-diff)]
# HG changeset patch
# User Kevin McCarthy <kevin@8t8.us>
# Date 1367104019 25200
# Branch HEAD
# Node ID 2b05229cd7ddfea64abf3a9217f98cd0ac82a511
# 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
@@ -40,24 +40,24 @@
static void init_history (struct history *h)
{
int i;
if(OldSize)
{
if (h->hist)
{
- for (i = 0 ; i < OldSize ; i ++)
+ 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] : "");
}
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic