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

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

Issue 2383293003: - fix some cases where we are using uninitialized memory (Closed)
Patch Set: address self code review. 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
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 #ifndef PLATFORM_ASSERT_H_ 5 #ifndef PLATFORM_ASSERT_H_
6 #define PLATFORM_ASSERT_H_ 6 #define PLATFORM_ASSERT_H_
7 7
8 // TODO(5411406): include sstream for now, once we have a Utils::toString() 8 // TODO(5411406): include sstream for now, once we have a Utils::toString()
9 // implemented for all the primitive types we can replace the usage of 9 // implemented for all the primitive types we can replace the usage of
10 // sstream by Utils::toString() 10 // sstream by Utils::toString()
11 #if defined(TESTING) 11 #if defined(TESTING)
12 #include <sstream> 12 #include <sstream>
13 #include <string> 13 #include <string>
14 #endif 14 #endif
15 15
16 #include "platform/globals.h" 16 #include "platform/globals.h"
17 #include "platform/memory_sanitizer.h"
17 18
18 #if !defined(DEBUG) && !defined(NDEBUG) 19 #if !defined(DEBUG) && !defined(NDEBUG)
19 #error neither DEBUG nor NDEBUG defined 20 #error neither DEBUG nor NDEBUG defined
20 #elif defined(DEBUG) && defined(NDEBUG) 21 #elif defined(DEBUG) && defined(NDEBUG)
21 #error both DEBUG and NDEBUG defined 22 #error both DEBUG and NDEBUG defined
22 #endif 23 #endif
23 24
24 namespace dart { 25 namespace dart {
25 26
26 class DynamicAssertionHelper { 27 class DynamicAssertionHelper {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 tolss << tol; 136 tolss << tol;
136 std::string es = ess.str(), as = ass.str(), tols = tolss.str(); 137 std::string es = ess.str(), as = ass.str(), tols = tolss.str();
137 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", 138 Fail("expected: <%s> but was: <%s> (tolerance: <%s>)",
138 es.c_str(), 139 es.c_str(),
139 as.c_str(), 140 as.c_str(),
140 tols.c_str()); 141 tols.c_str());
141 } 142 }
142 143
143 144
144 template<typename E, typename A> 145 template<typename E, typename A>
146 NO_SANITIZE_MEMORY
145 void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) { 147 void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) {
146 std::ostringstream ess, ass; 148 std::ostringstream ess, ass;
147 ess << expected; 149 ess << expected;
148 ass << actual; 150 ass << actual;
149 std::string es = ess.str(), as = ass.str(); 151 std::string es = ess.str(), as = ass.str();
150 if (as == es) return; 152 if (as == es) return;
151 Fail("expected:\n<\"%s\">\nbut was:\n<\"%s\">", es.c_str(), as.c_str()); 153 Fail("expected:\n<\"%s\">\nbut was:\n<\"%s\">", es.c_str(), as.c_str());
152 } 154 }
153 155
154 156
155 template<typename E, typename A> 157 template<typename E, typename A>
158 NO_SANITIZE_MEMORY
156 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { 159 void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) {
157 std::ostringstream ess, ass; 160 std::ostringstream ess, ass;
158 ess << needle; 161 ess << needle;
159 ass << haystack; 162 ass << haystack;
160 std::string es = ess.str(), as = ass.str(); 163 std::string es = ess.str(), as = ass.str();
161 if (as.find(es) != std::string::npos) return; 164 if (as.find(es) != std::string::npos) return;
162 Fail("expected <\"%s\"> to be a substring of <\"%s\">", 165 Fail("expected <\"%s\"> to be a substring of <\"%s\">",
163 es.c_str(), as.c_str()); 166 es.c_str(), as.c_str());
164 } 167 }
165 168
166 169
167 template<typename E, typename A> 170 template<typename E, typename A>
171 NO_SANITIZE_MEMORY
168 void DynamicAssertionHelper::IsNotSubstring(const E& needle, 172 void DynamicAssertionHelper::IsNotSubstring(const E& needle,
169 const A& haystack) { 173 const A& haystack) {
170 std::ostringstream ess, ass; 174 std::ostringstream ess, ass;
171 ess << needle; 175 ess << needle;
172 ass << haystack; 176 ass << haystack;
173 std::string es = ess.str(), as = ass.str(); 177 std::string es = ess.str(), as = ass.str();
174 if (as.find(es) == std::string::npos) return; 178 if (as.find(es) == std::string::npos) return;
175 Fail("expected <\"%s\"> to not be a substring of <\"%s\">", 179 Fail("expected <\"%s\"> to not be a substring of <\"%s\">",
176 es.c_str(), as.c_str()); 180 es.c_str(), as.c_str());
177 } 181 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 370
367 #define FAIL1(format, p1) \ 371 #define FAIL1(format, p1) \
368 dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) 372 dart::Expect(__FILE__, __LINE__).Fail(format, (p1))
369 373
370 #define FAIL2(format, p1, p2) \ 374 #define FAIL2(format, p1, p2) \
371 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) 375 dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2))
372 376
373 #endif // defined(TESTING) 377 #endif // defined(TESTING)
374 378
375 #endif // PLATFORM_ASSERT_H_ 379 #endif // PLATFORM_ASSERT_H_
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/platform/assert.cc » ('j') | runtime/vm/native_entry.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698