Skip to content

Commit 14dab9f

Browse files
authored
fix error in completion function
fixed two problems: * memory for completion string was allocated with new[] instead of malloc * not enough memory was alocated (strlen instead strlen + 1) these caused program crash on rapid Tab pressing
1 parent 47c0f62 commit 14dab9f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Console.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <unordered_map>
1010

1111
#include <cstdlib>
12+
#include <cstring>
1213
#include <readline/readline.h>
1314
#include <readline/history.h>
1415

@@ -195,9 +196,7 @@ namespace CppReadline {
195196
auto & command = it->first;
196197
++it;
197198
if ( command.find(text) != std::string::npos ) {
198-
char * completion = new char[command.size()];
199-
strcpy(completion, command.c_str());
200-
return completion;
199+
return strdup(command.c_str());
201200
}
202201
}
203202
return nullptr;

0 commit comments

Comments
 (0)