]> git.saurik.com Git - cycript.git/commitdiff
Fixed a tokenization bug that caused blank lines a the console to crash horribly.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 20 Oct 2009 20:36:21 +0000 (20:36 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 20 Oct 2009 20:36:21 +0000 (20:36 +0000)
Console.cpp

index e09ea01fc764214a0ad541b5d475a3571878f022..c377db2abb3242ac64b4c879de99229e5568c080 100644 (file)
@@ -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<char *>(memchr(begin, '\n', end - begin))) {
+            *nl = '\0';
+            lines.push_back(begin);
+            begin = nl + 1;
+        }
+
+        lines.push_back(begin);
+
         free(line);
 
         std::string code;