< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page
rev 58808 : 8242485: Null _file checking in fileStream::flush()
Reviewed-by: dholmes, ysuenaga, iklam

@@ -531,12 +531,12 @@
 
 void fileStream::write(const char* s, size_t len) {
   if (_file != NULL)  {
     // Make an unused local variable to avoid warning from gcc compiler.
     size_t count = fwrite(s, 1, len, _file);
-  }
   update_position(s, len);
+  }
 }
 
 long fileStream::fileSize() {
   long size = -1;
   if (_file != NULL) {

@@ -549,13 +549,16 @@
   }
   return size;
 }
 
 char* fileStream::readln(char *data, int count ) {
-  char * ret = ::fgets(data, count, _file);
+  char * ret = NULL;
+  if (_file != NULL) {
+    ret = ::fgets(data, count, _file);
   //Get rid of annoying \n char
   data[::strlen(data)-1] = '\0';
+  }
   return ret;
 }
 
 fileStream::~fileStream() {
   if (_file != NULL) {

@@ -563,19 +566,21 @@
     _file      = NULL;
   }
 }
 
 void fileStream::flush() {
+  if (_file != NULL) {
   fflush(_file);
+  }
 }
 
 void fdStream::write(const char* s, size_t len) {
   if (_fd != -1) {
     // Make an unused local variable to avoid warning from gcc compiler.
     size_t count = ::write(_fd, s, (int)len);
-  }
   update_position(s, len);
+  }
 }
 
 defaultStream* defaultStream::instance = NULL;
 int defaultStream::_output_fd = 1;
 int defaultStream::_error_fd  = 2;
< prev index next >