Commit e5dee800f9aaa465d4e53c98dd17c56f147fe79c

antirez 2010-03-21T22:27:09

Fix for an history bug

diff --git a/README.markdown b/README.markdown
index 9f62ea6..edbf03f 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,6 +1,6 @@
 # Linenoise
 
-A minimal, zero-config, readline replacement.
+A minimal, zero-config, BSD licensed, readline replacement.
 
 ## Can a line editing library be 20k lines of code?
 
diff --git a/linenoise.c b/linenoise.c
index aebe398..386ab6c 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -308,7 +308,7 @@ int linenoiseHistoryAdd(char *line) {
     line = strdup(line);
     if (!line) return 0;
     if (history_len == history_max_len) {
-        memmove(history,history+sizeof(char*),sizeof(char*)*history_max_len-1);
+        memmove(history,history+1,sizeof(char*)*(history_max_len-1));
         history_len--;
     }
     history[history_len] = line;
@@ -326,7 +326,7 @@ int linenoiseHistorySetMaxLen(int len) {
         new = malloc(sizeof(char*)*len);
         if (new == NULL) return 0;
         if (len < tocopy) tocopy = len;
-        memcpy(new,history-sizeof(char*)*tocopy, sizeof(char*)*tocopy);
+        memcpy(new,history+(history_max_len-tocopy), sizeof(char*)*tocopy);
         free(history);
         history = new;
     }