[llvm-branch-commits] [lldb] r199935 - Don't crash when our input file is closed when a lower IO handler is active.

Greg Clayton gclayton at apple.com
Thu Jan 23 13:17:57 PST 2014


Author: gclayton
Date: Thu Jan 23 15:17:56 2014
New Revision: 199935

URL: http://llvm.org/viewvc/llvm-project?rev=199935&view=rev
Log:
Don't crash when our input file is closed when a lower IO handler is active.


Modified:
    lldb/branches/iohandler/source/Core/IOHandler.cpp

Modified: lldb/branches/iohandler/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Core/IOHandler.cpp?rev=199935&r1=199934&r2=199935&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Core/IOHandler.cpp (original)
+++ lldb/branches/iohandler/source/Core/IOHandler.cpp Thu Jan 23 15:17:56 2014
@@ -369,47 +369,56 @@ IOHandlerEditline::GetLine (std::string
     }
     else
     {
-        if (m_interactive)
+        line.clear();
+
+        FILE *in = GetInputFILE();
+        if (in)
         {
-            const char *prompt = GetPrompt();
-            if (prompt && prompt[0])
+            if (m_interactive)
             {
-                FILE *out = GetOutputFILE();
-                if (out)
+                const char *prompt = GetPrompt();
+                if (prompt && prompt[0])
                 {
-                    ::fprintf(out, "%s", prompt);
-                    ::fflush(out);
+                    FILE *out = GetOutputFILE();
+                    if (out)
+                    {
+                        ::fprintf(out, "%s", prompt);
+                        ::fflush(out);
+                    }
                 }
             }
-        }
-        line.clear();
-        FILE *in = GetInputFILE();
-        char buffer[256];
-        bool done = false;
-        while (!done)
-        {
-            if (fgets(buffer, sizeof(buffer), in) == NULL)
-                done = true;
-            else
+            char buffer[256];
+            bool done = false;
+            while (!done)
             {
-                size_t buffer_len = strlen(buffer);
-                assert (buffer[buffer_len] == '\0');
-                char last_char = buffer[buffer_len-1];
-                if (last_char == '\r' || last_char == '\n')
-                {
+                if (fgets(buffer, sizeof(buffer), in) == NULL)
                     done = true;
-                    // Strip trailing newlines
-                    while (last_char == '\r' || last_char == '\n')
+                else
+                {
+                    size_t buffer_len = strlen(buffer);
+                    assert (buffer[buffer_len] == '\0');
+                    char last_char = buffer[buffer_len-1];
+                    if (last_char == '\r' || last_char == '\n')
                     {
-                        --buffer_len;
-                        if (buffer_len == 0)
-                            break;
-                        last_char = buffer[buffer_len-1];
+                        done = true;
+                        // Strip trailing newlines
+                        while (last_char == '\r' || last_char == '\n')
+                        {
+                            --buffer_len;
+                            if (buffer_len == 0)
+                                break;
+                            last_char = buffer[buffer_len-1];
+                        }
                     }
+                    line.append(buffer, buffer_len);
                 }
-                line.append(buffer, buffer_len);
             }
         }
+        else
+        {
+            // No more input file, we are done...
+            SetIsDone(true);
+        }
         return !line.empty();
     }
 }





More information about the llvm-branch-commits mailing list