Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: runtime/platform/assert.cc

Issue 2383293003: - fix some cases where we are using uninitialized memory (Closed)
Patch Set: Fix lint issue. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/platform/assert.h ('k') | runtime/platform/memory_sanitizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #include "vm/os.h" 8 #include "vm/os.h"
9 #include "vm/profiler.h" 9 #include "vm/profiler.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 bool DynamicAssertionHelper::failed_ = false; 13 bool DynamicAssertionHelper::failed_ = false;
14 14
15 void DynamicAssertionHelper::Fail(const char* format, ...) { 15 void DynamicAssertionHelper::Fail(const char* format, ...) {
16 // Take only the last 1KB of the file name if it is longer. 16 // Take only the last 1KB of the file name if it is longer.
17 const intptr_t file_len = strlen(file_); 17 const intptr_t file_len = strlen(file_);
18 const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0; 18 const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0;
19 const char* file = file_ + file_offset; 19 const char* file = file_ + file_offset;
20 20
21 // Print the file and line number into the buffer. 21 // Print the file and line number into the buffer.
22 char buffer[4 * KB]; 22 char buffer[4 * KB];
23 MSAN_UNPOISON(buffer, sizeof(buffer));
23 intptr_t file_and_line_length = 24 intptr_t file_and_line_length =
24 snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_); 25 snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_);
25 26
26 // Print the error message into the buffer. 27 // Print the error message into the buffer.
27 va_list arguments; 28 va_list arguments;
28 va_start(arguments, format); 29 va_start(arguments, format);
29 vsnprintf(buffer + file_and_line_length, 30 vsnprintf(buffer + file_and_line_length,
30 sizeof(buffer) - file_and_line_length, 31 sizeof(buffer) - file_and_line_length,
31 format, 32 format,
32 arguments); 33 arguments);
33 va_end(arguments); 34 va_end(arguments);
34 35
35 // Print the buffer on stderr and/or syslog. 36 // Print the buffer on stderr and/or syslog.
36 OS::PrintErr("%s\n", buffer); 37 OS::PrintErr("%s\n", buffer);
37 38
38 // In case of failed assertions, abort right away. Otherwise, wait 39 // In case of failed assertions, abort right away. Otherwise, wait
39 // until the program is exiting before producing a non-zero exit 40 // until the program is exiting before producing a non-zero exit
40 // code through abort. 41 // code through abort.
41 if (kind_ == ASSERT) { 42 if (kind_ == ASSERT) {
42 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */)); 43 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */));
43 OS::Abort(); 44 OS::Abort();
44 } 45 }
45 failed_ = true; 46 failed_ = true;
46 } 47 }
47 48
48 } // namespace dart 49 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/platform/assert.h ('k') | runtime/platform/memory_sanitizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698