Make the assumption on the minimum buffer size for GetLogLines explicit.
Review URL: http://codereview.chromium.org/799008 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4097 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
e5f27966dc
commit
c413105da7
@ -2421,6 +2421,14 @@ class V8EXPORT V8 {
|
||||
*/
|
||||
static int GetLogLines(int from_pos, char* dest_buf, int max_size);
|
||||
|
||||
/**
|
||||
* The minimum allowed size for a log lines buffer. If the size of
|
||||
* the buffer given will not be enough to hold a line of the maximum
|
||||
* length, an attempt to find a log line end in GetLogLines will
|
||||
* fail, and an empty result will be returned.
|
||||
*/
|
||||
static const int kMinimumSizeForLogLinesBuffer = 2048;
|
||||
|
||||
/**
|
||||
* Retrieve the V8 thread id of the calling thread.
|
||||
*
|
||||
|
@ -3580,6 +3580,7 @@ int V8::GetActiveProfilerModules() {
|
||||
|
||||
int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
ASSERT(max_size >= kMinimumSizeForLogLinesBuffer);
|
||||
return i::Logger::GetLogLines(from_pos, dest_buf, max_size);
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -196,6 +196,9 @@ int Log::GetLogLines(int from_pos, char* dest_buf, int max_size) {
|
||||
char* end_pos = dest_buf + actual_size - 1;
|
||||
while (end_pos >= dest_buf && *end_pos != '\n') --end_pos;
|
||||
actual_size = static_cast<int>(end_pos - dest_buf + 1);
|
||||
// If the assertion below is hit, it means that there was no line end
|
||||
// found --- something wrong has happened.
|
||||
ASSERT(actual_size > 0);
|
||||
ASSERT(actual_size <= max_size);
|
||||
return actual_size;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class Log : public AllStatic {
|
||||
}
|
||||
|
||||
// Size of buffer used for formatting log messages.
|
||||
static const int kMessageBufferSize = 2048;
|
||||
static const int kMessageBufferSize = v8::V8::kMinimumSizeForLogLinesBuffer;
|
||||
|
||||
private:
|
||||
typedef int (*WritePtr)(const char* msg, int length);
|
||||
|
@ -52,13 +52,9 @@ TEST(GetMessages) {
|
||||
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
|
||||
char log_lines[100];
|
||||
memset(log_lines, 0, sizeof(log_lines));
|
||||
// Requesting data size which is smaller than first log message length.
|
||||
CHECK_EQ(0, Logger::GetLogLines(0, log_lines, 3));
|
||||
// See Logger::StringEvent.
|
||||
const char* line_1 = "aaa,\"bbb\"\n";
|
||||
const int line_1_len = StrLength(line_1);
|
||||
// Still smaller than log message length.
|
||||
CHECK_EQ(0, Logger::GetLogLines(0, log_lines, line_1_len - 1));
|
||||
// The exact size.
|
||||
CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len));
|
||||
CHECK_EQ(line_1, log_lines);
|
||||
@ -72,8 +68,6 @@ TEST(GetMessages) {
|
||||
const int line_2_len = StrLength(line_2);
|
||||
// Now start with line_2 beginning.
|
||||
CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0));
|
||||
CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 3));
|
||||
CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, line_2_len - 1));
|
||||
CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len));
|
||||
CHECK_EQ(line_2, log_lines);
|
||||
memset(log_lines, 0, sizeof(log_lines));
|
||||
|
Loading…
Reference in New Issue
Block a user