fixes #3720
This commit is contained in:
parent
f02701c0b0
commit
b4d6346bae
1 changed files with 13 additions and 13 deletions
|
|
@ -417,10 +417,10 @@ void linenoiseAddCompletion(linenoiseCompletions *lc, const char *str) {
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
char *copy, **cvec;
|
char *copy, **cvec;
|
||||||
|
|
||||||
copy = malloc(len+1);
|
copy = (char*)malloc(len+1);
|
||||||
if (copy == NULL) return;
|
if (copy == NULL) return;
|
||||||
memcpy(copy,str,len+1);
|
memcpy(copy,str,len+1);
|
||||||
cvec = realloc(lc->cvec,sizeof(char*)*(lc->len+1));
|
cvec = (char**)realloc(lc->cvec,sizeof(char*)*(lc->len+1));
|
||||||
if (cvec == NULL) {
|
if (cvec == NULL) {
|
||||||
free(copy);
|
free(copy);
|
||||||
return;
|
return;
|
||||||
|
|
@ -446,11 +446,11 @@ static void abInit(struct abuf *ab) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void abAppend(struct abuf *ab, const char *s, int len) {
|
static void abAppend(struct abuf *ab, const char *s, int len) {
|
||||||
char *new = realloc(ab->b,ab->len+len);
|
char *neww = (char*)realloc(ab->b,ab->len+len);
|
||||||
|
|
||||||
if (new == NULL) return;
|
if (neww == NULL) return;
|
||||||
memcpy(new+ab->len,s,len);
|
memcpy(neww+ab->len,s,len);
|
||||||
ab->b = new;
|
ab->b = neww;
|
||||||
ab->len += len;
|
ab->len += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1016,7 +1016,7 @@ int linenoiseHistoryAdd(const char *line) {
|
||||||
|
|
||||||
/* Initialization on first call. */
|
/* Initialization on first call. */
|
||||||
if (history == NULL) {
|
if (history == NULL) {
|
||||||
history = malloc(sizeof(char*)*history_max_len);
|
history = (char**)malloc(sizeof(char*)*history_max_len);
|
||||||
if (history == NULL) return 0;
|
if (history == NULL) return 0;
|
||||||
memset(history,0,(sizeof(char*)*history_max_len));
|
memset(history,0,(sizeof(char*)*history_max_len));
|
||||||
}
|
}
|
||||||
|
|
@ -1043,14 +1043,14 @@ int linenoiseHistoryAdd(const char *line) {
|
||||||
* just the latest 'len' elements if the new history length value is smaller
|
* just the latest 'len' elements if the new history length value is smaller
|
||||||
* than the amount of items already inside the history. */
|
* than the amount of items already inside the history. */
|
||||||
int linenoiseHistorySetMaxLen(int len) {
|
int linenoiseHistorySetMaxLen(int len) {
|
||||||
char **new;
|
char **neww;
|
||||||
|
|
||||||
if (len < 1) return 0;
|
if (len < 1) return 0;
|
||||||
if (history) {
|
if (history) {
|
||||||
int tocopy = history_len;
|
int tocopy = history_len;
|
||||||
|
|
||||||
new = malloc(sizeof(char*)*len);
|
neww = (char**)malloc(sizeof(char*)*len);
|
||||||
if (new == NULL) return 0;
|
if (neww == NULL) return 0;
|
||||||
|
|
||||||
/* If we can't copy everything, free the elements we'll not use. */
|
/* If we can't copy everything, free the elements we'll not use. */
|
||||||
if (len < tocopy) {
|
if (len < tocopy) {
|
||||||
|
|
@ -1059,10 +1059,10 @@ int linenoiseHistorySetMaxLen(int len) {
|
||||||
for (j = 0; j < tocopy-len; j++) free(history[j]);
|
for (j = 0; j < tocopy-len; j++) free(history[j]);
|
||||||
tocopy = len;
|
tocopy = len;
|
||||||
}
|
}
|
||||||
memset(new,0,sizeof(char*)*len);
|
memset(neww,0,sizeof(char*)*len);
|
||||||
memcpy(new,history+(history_len-tocopy), sizeof(char*)*tocopy);
|
memcpy(neww,history+(history_len-tocopy), sizeof(char*)*tocopy);
|
||||||
free(history);
|
free(history);
|
||||||
history = new;
|
history = neww;
|
||||||
}
|
}
|
||||||
history_max_len = len;
|
history_max_len = len;
|
||||||
if (history_len > history_max_len)
|
if (history_len > history_max_len)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue