mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/linenoise_stack_alloc' into 'master'
console: linenoise: move allocations from stack to heap, fix calloc result checking (Github PR) Merges https://github.com/espressif/esp-idf/pull/5161 Closes IDFGH-3144 See merge request espressif/esp-idf!8612
This commit is contained in:
commit
a97cd645ad
@ -979,6 +979,9 @@ static void sanitize(char* src) {
|
||||
char *linenoise(const char *prompt) {
|
||||
char *buf = calloc(1, LINENOISE_MAX_LINE);
|
||||
int count = 0;
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!dumbmode) {
|
||||
count = linenoiseRaw(buf, LINENOISE_MAX_LINE, prompt);
|
||||
} else {
|
||||
@ -1105,9 +1108,15 @@ int linenoiseHistorySave(const char *filename) {
|
||||
* on error -1 is returned. */
|
||||
int linenoiseHistoryLoad(const char *filename) {
|
||||
FILE *fp = fopen(filename,"r");
|
||||
char buf[LINENOISE_MAX_LINE];
|
||||
if (fp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fp == NULL) return -1;
|
||||
char *buf = calloc(1, LINENOISE_MAX_LINE);
|
||||
if (buf == NULL) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buf,LINENOISE_MAX_LINE,fp) != NULL) {
|
||||
char *p;
|
||||
@ -1117,6 +1126,9 @@ int linenoiseHistoryLoad(const char *filename) {
|
||||
if (p) *p = '\0';
|
||||
linenoiseHistoryAdd(buf);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user