Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
#define LINENOISE_MAX_LINE 4096
static char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
static const char *unsupported_term[] = {"dumb","cons25","emacs",NULL};
static linenoiseCompletionCallback *completionCallback = NULL;
static linenoiseHintsCallback *hintsCallback = NULL;
static linenoiseFreeHintsCallback *freeHintsCallback = NULL;
Expand Down Expand Up @@ -905,7 +905,7 @@ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, ch
return 0;
}

char *linenoiseEditMore = "If you see this, you are misusing the API: when linenoiseEditFeed() is called, if it returns linenoiseEditMore the user is yet editing the line. See the README file for more information.";
const char *linenoiseEditMore = "If you see this, you are misusing the API: when linenoiseEditFeed() is called, if it returns linenoiseEditMore the user is yet editing the line. See the README file for more information.";

/* This function is part of the multiplexed API of linenoise, see the top
* comment on linenoiseEditStart() for more information. Call this function
Expand Down Expand Up @@ -933,6 +933,8 @@ char *linenoiseEditFeed(struct linenoiseState *l) {
char c;
int nread;
char seq[3];
char *local_linenoiseEditMore = (char *)malloc((strlen(linenoiseEditMore) + 1) * sizeof(char));
strcpy(local_linenoiseEditMore, linenoiseEditMore);

nread = read(l->ifd,&c,1);
if (nread <= 0) return NULL;
Expand All @@ -945,7 +947,7 @@ char *linenoiseEditFeed(struct linenoiseState *l) {
/* Return on errors */
if (c < 0) return NULL;
/* Read next character when 0 */
if (c == 0) return linenoiseEditMore;
if (c == 0) return local_linenoiseEditMore;
}

switch(c) {
Expand Down Expand Up @@ -1083,7 +1085,7 @@ char *linenoiseEditFeed(struct linenoiseState *l) {
linenoiseEditDeletePrevWord(l);
break;
}
return linenoiseEditMore;
return local_linenoiseEditMore;
}

/* This is part of the multiplexed linenoise API. See linenoiseEditStart()
Expand Down Expand Up @@ -1216,7 +1218,6 @@ char *linenoise(const char *prompt) {
* created with. Useful when the main program is using an alternative
* allocator. */
void linenoiseFree(void *ptr) {
if (ptr == linenoiseEditMore) return; // Protect from API misuse.
free(ptr);
}

Expand Down
2 changes: 1 addition & 1 deletion linenoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern "C" {

#include <stddef.h> /* For size_t. */

extern char *linenoiseEditMore;
extern const char *linenoiseEditMore;

/* The linenoiseState structure represents the state during line editing.
* We pass this state to functions implementing specific editing
Expand Down