Bug 1249896 - Part 8: Remove unreachable code from GetLine. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Tue, 23 Feb 2016 23:45:48 +0900
changeset 321496 38683766636ad43d13fe2f1bb81bbdafbe288d4b
parent 321495 39d4cf16c55451b2eb7b1aa8cdf8891c48077ddb
child 321497 b76de3f353b8e84dd404f3e8080d0f0c85efbca2
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1249896
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1249896 - Part 8: Remove unreachable code from GetLine. r=jwalden
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -354,17 +354,17 @@ GetLine(FILE* file, const char * prompt)
     }
 
     size_t size = 80;
     char* buffer = static_cast<char*>(malloc(size));
     if (!buffer)
         return nullptr;
 
     char* current = buffer;
-    while (true) {
+    do {
         while (true) {
             if (fgets(current, size - len, file))
                 break;
             if (errno != EINTR) {
                 free(buffer);
                 return nullptr;
             }
         }
@@ -382,21 +382,17 @@ GetLine(FILE* file, const char * prompt)
             char* tmp = static_cast<char*>(realloc(buffer, size));
             if (!tmp) {
                 free(buffer);
                 return nullptr;
             }
             buffer = tmp;
         }
         current = buffer + len;
-    }
-
-    if (len && !ferror(file))
-        return buffer;
-    free(buffer);
+    } while (true);
     return nullptr;
 }
 
 /* State to store as JSContext private. */
 struct JSShellContextData {
     /* Creation timestamp, used by the elapsed() shell builtin. */
     int64_t startTime;
 };