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

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

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