Index: runtime/platform/assert.cc |
diff --git a/runtime/platform/assert.cc b/runtime/platform/assert.cc |
index e9d1c4fa301e66db915f676132275b292b21a5c6..c5b91e714f3bbb6c4a1ea6c73c56b562a38ffab4 100644 |
--- a/runtime/platform/assert.cc |
+++ b/runtime/platform/assert.cc |
@@ -4,9 +4,6 @@ |
#include "platform/assert.h" |
-#include <sstream> |
-#include <string> |
- |
#include "platform/globals.h" |
#include "vm/os.h" |
@@ -18,19 +15,27 @@ static void failed_exit(void) { |
} |
void DynamicAssertionHelper::Fail(const char* format, ...) { |
- std::ostringstream stream; |
- stream << file_ << ":" << line_ << ": error: "; |
+ // Take only the last 1KB of the file name if it is longer. |
+ const intptr_t file_len = strlen(file_); |
+ const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0; |
+ const char* file = file_ + file_offset; |
+ |
+ // Print the file and line number into the buffer. |
+ char buffer[4 * KB]; |
+ intptr_t file_and_line_length = |
+ snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_); |
+ // Print the error message into the buffer. |
va_list arguments; |
va_start(arguments, format); |
- char buffer[4 * KB]; |
- vsnprintf(buffer, sizeof(buffer), format, arguments); |
+ vsnprintf(buffer + file_and_line_length, |
+ sizeof(buffer) - file_and_line_length, |
+ format, |
+ arguments); |
va_end(arguments); |
- stream << buffer << std::endl; |
- // Get the message from the string stream and dump it on stderr. |
- std::string message = stream.str(); |
- fprintf(stderr, "%s", message.c_str()); |
+ // Print the buffer on stderr. |
+ fprintf(stderr, "%s\n", buffer); |
fflush(stderr); |
// In case of failed assertions, abort right away. Otherwise, wait |