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

Side by Side Diff: src/wasm/decoder.h

Issue 1877823003: Revert of Fix printf formats (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 | « src/utils.h ('k') | src/wasm/wasm-result.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_DECODER_H_ 5 #ifndef V8_WASM_DECODER_H_
6 #define V8_WASM_DECODER_H_ 6 #define V8_WASM_DECODER_H_
7 7
8 #include "src/base/compiler-specific.h"
9 #include "src/base/smart-pointers.h" 8 #include "src/base/smart-pointers.h"
10 #include "src/flags.h" 9 #include "src/flags.h"
11 #include "src/signature.h" 10 #include "src/signature.h"
12 #include "src/utils.h"
13 #include "src/wasm/wasm-result.h" 11 #include "src/wasm/wasm-result.h"
14 #include "src/zone-containers.h" 12 #include "src/zone-containers.h"
15 13
16 namespace v8 { 14 namespace v8 {
17 namespace internal { 15 namespace internal {
18 namespace wasm { 16 namespace wasm {
19 17
20 #if DEBUG 18 #if DEBUG
21 #define TRACE(...) \ 19 #define TRACE(...) \
22 do { \ 20 do { \
(...skipping 19 matching lines...) Expand all
42 limit_(end), 40 limit_(end),
43 end_(end), 41 end_(end),
44 error_pc_(nullptr), 42 error_pc_(nullptr),
45 error_pt_(nullptr) {} 43 error_pt_(nullptr) {}
46 44
47 virtual ~Decoder() {} 45 virtual ~Decoder() {}
48 46
49 inline bool check(const byte* base, int offset, int length, const char* msg) { 47 inline bool check(const byte* base, int offset, int length, const char* msg) {
50 DCHECK_GE(base, start_); 48 DCHECK_GE(base, start_);
51 if ((base + offset + length) > limit_) { 49 if ((base + offset + length) > limit_) {
52 error(base, base + offset, "%s", msg); 50 error(base, base + offset, msg);
53 return false; 51 return false;
54 } 52 }
55 return true; 53 return true;
56 } 54 }
57 55
58 // Reads a single 8-bit byte, reporting an error if out of bounds. 56 // Reads a single 8-bit byte, reporting an error if out of bounds.
59 inline uint8_t checked_read_u8(const byte* base, int offset, 57 inline uint8_t checked_read_u8(const byte* base, int offset,
60 const char* msg = "expected 1 byte") { 58 const char* msg = "expected 1 byte") {
61 return check(base, offset, 1, msg) ? base[offset] : 0; 59 return check(base, offset, 1, msg) ? base[offset] : 0;
62 } 60 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 error(pc_, nullptr, "reading %d bytes would underflow/overflow", size); 251 error(pc_, nullptr, "reading %d bytes would underflow/overflow", size);
254 return false; 252 return false;
255 } else if (pc_ < start_ || limit_ < (pc_ + size)) { 253 } else if (pc_ < start_ || limit_ < (pc_ + size)) {
256 error(pc_, nullptr, "expected %d bytes, fell off end", size); 254 error(pc_, nullptr, "expected %d bytes, fell off end", size);
257 return false; 255 return false;
258 } else { 256 } else {
259 return true; 257 return true;
260 } 258 }
261 } 259 }
262 260
263 void error(const char* msg) { error(pc_, nullptr, "%s", msg); } 261 void error(const char* msg) { error(pc_, nullptr, msg); }
264 262
265 void error(const byte* pc, const char* msg) { error(pc, nullptr, "%s", msg); } 263 void error(const byte* pc, const char* msg) { error(pc, nullptr, msg); }
266 264
267 // Sets internal error state. 265 // Sets internal error state.
268 void PRINTF_FORMAT(4, 5) 266 void error(const byte* pc, const byte* pt, const char* format, ...) {
269 error(const byte* pc, const byte* pt, const char* format, ...) {
270 if (ok()) { 267 if (ok()) {
271 #if DEBUG 268 #if DEBUG
272 if (FLAG_wasm_break_on_decoder_error) { 269 if (FLAG_wasm_break_on_decoder_error) {
273 base::OS::DebugBreak(); 270 base::OS::DebugBreak();
274 } 271 }
275 #endif 272 #endif
276 const int kMaxErrorMsg = 256; 273 const int kMaxErrorMsg = 256;
277 char* buffer = new char[kMaxErrorMsg]; 274 char* buffer = new char[kMaxErrorMsg];
278 va_list arguments; 275 va_list arguments;
279 va_start(arguments, format); 276 va_start(arguments, format);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 extra_bits_value = (static_cast<int8_t>(b << kExtraBits) >> 8) & 385 extra_bits_value = (static_cast<int8_t>(b << kExtraBits) >> 8) &
389 kExtraBitsMask & ~0x80; 386 kExtraBitsMask & ~0x80;
390 } else { 387 } else {
391 extra_bits_value = 0; 388 extra_bits_value = 0;
392 } 389 }
393 if (*length == kMaxLength && (b & kExtraBitsMask) != extra_bits_value) { 390 if (*length == kMaxLength && (b & kExtraBitsMask) != extra_bits_value) {
394 error(base, ptr, "extra bits in varint"); 391 error(base, ptr, "extra bits in varint");
395 return 0; 392 return 0;
396 } 393 }
397 if ((b & 0x80) != 0) { 394 if ((b & 0x80) != 0) {
398 error(base, ptr, "%s", msg); 395 error(base, ptr, msg);
399 return 0; 396 return 0;
400 } 397 }
401 } 398 }
402 return result; 399 return result;
403 } 400 }
404 }; 401 };
405 402
406 #undef TRACE 403 #undef TRACE
407 } // namespace wasm 404 } // namespace wasm
408 } // namespace internal 405 } // namespace internal
409 } // namespace v8 406 } // namespace v8
410 407
411 #endif // V8_WASM_DECODER_H_ 408 #endif // V8_WASM_DECODER_H_
OLDNEW
« no previous file with comments | « src/utils.h ('k') | src/wasm/wasm-result.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698