< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page

        

*** 310,329 **** stringStream::stringStream(size_t initial_size) : outputStream() { buffer_length = initial_size; buffer = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); buffer_pos = 0; buffer_fixed = false; - zero_terminate(); } // useful for output to fixed chunks of memory, such as performance counters stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() { buffer_length = fixed_buffer_size; buffer = fixed_buffer; buffer_pos = 0; buffer_fixed = true; - zero_terminate(); } void stringStream::write(const char* s, size_t len) { size_t write_len = len; // number of non-null bytes to write size_t end = buffer_pos + len + 1; // position after write and final '\0' --- 310,327 ----
*** 343,375 **** } } // invariant: buffer is always null-terminated guarantee(buffer_pos + write_len + 1 <= buffer_length, "stringStream oob"); if (write_len > 0) { memcpy(buffer + buffer_pos, s, write_len); buffer_pos += write_len; - zero_terminate(); } // Note that the following does not depend on write_len. // This means that position and count get updated // even when overflow occurs. update_position(s, len); } ! void stringStream::zero_terminate() { ! assert(buffer != NULL && ! buffer_pos < buffer_length, "sanity"); ! buffer[buffer_pos] = '\0'; ! } ! ! void stringStream::reset() { ! buffer_pos = 0; _precount = 0; _position = 0; ! zero_terminate(); ! } ! ! char* stringStream::as_string() const { char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1); strncpy(copy, buffer, buffer_pos); copy[buffer_pos] = 0; // terminating null return copy; } --- 341,362 ---- } } // invariant: buffer is always null-terminated guarantee(buffer_pos + write_len + 1 <= buffer_length, "stringStream oob"); if (write_len > 0) { + buffer[buffer_pos + write_len] = 0; memcpy(buffer + buffer_pos, s, write_len); buffer_pos += write_len; } // Note that the following does not depend on write_len. // This means that position and count get updated // even when overflow occurs. update_position(s, len); } ! char* stringStream::as_string() { char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1); strncpy(copy, buffer, buffer_pos); copy[buffer_pos] = 0; // terminating null return copy; }
< prev index next >