From: Jay Freeman (saurik) Date: Tue, 20 Oct 2009 20:36:21 +0000 (+0000) Subject: Fixed a tokenization bug that caused blank lines a the console to crash horribly. X-Git-Tag: v0.9.432~305 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/e818f0e07214ed24416c7aedf63d2972e42b9ca4 Fixed a tokenization bug that caused blank lines a the console to crash horribly. --- 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;