From e818f0e07214ed24416c7aedf63d2972e42b9ca4 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 20 Oct 2009 20:36:21 +0000 Subject: [PATCH] Fixed a tokenization bug that caused blank lines a the console to crash horribly. --- Console.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Console.cpp b/Console.cpp index e09ea01..c377db2 100644 --- a/Console.cpp +++ b/Console.cpp @@ -221,8 +221,16 @@ static void Console(int socket) { } command += line; - for (char *state, *token(apr_strtok(line, "\n", &state)); token != NULL; token = apr_strtok(NULL, "\n", &state)) - lines.push_back(token); + + char *begin(line), *end(line + strlen(line)); + while (char *nl = reinterpret_cast(memchr(begin, '\n', end - begin))) { + *nl = '\0'; + lines.push_back(begin); + begin = nl + 1; + } + + lines.push_back(begin); + free(line); std::string code; -- 2.45.2