OLD | NEW |
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 #include "src/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 364 |
365 TreeResult result = | 365 TreeResult result = |
366 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, | 366 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, |
367 start_ + function->code_end_offset); | 367 start_ + function->code_end_offset); |
368 if (result.failed()) { | 368 if (result.failed()) { |
369 // Wrap the error message from the function decoder. | 369 // Wrap the error message from the function decoder. |
370 std::ostringstream str; | 370 std::ostringstream str; |
371 str << "in function #" << func_num << ": "; | 371 str << "in function #" << func_num << ": "; |
372 // TODO(titzer): add function name for the user? | 372 // TODO(titzer): add function name for the user? |
373 str << result; | 373 str << result; |
374 const char* raw = str.str().c_str(); | 374 std::string strval = str.str(); |
| 375 const char* raw = strval.c_str(); |
375 size_t len = strlen(raw); | 376 size_t len = strlen(raw); |
376 char* buffer = new char[len]; | 377 char* buffer = new char[len]; |
377 strncpy(buffer, raw, len); | 378 strncpy(buffer, raw, len); |
378 buffer[len - 1] = 0; | 379 buffer[len - 1] = 0; |
379 | 380 |
380 // Copy error code and location. | 381 // Copy error code and location. |
381 result_.CopyFrom(result); | 382 result_.CopyFrom(result); |
382 result_.error_msg.Reset(buffer); | 383 result_.error_msg.Reset(buffer); |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 // Reads a single 32-bit unsigned integer interpreted as an offset, checking | 387 // Reads a single 32-bit unsigned integer interpreted as an offset, checking |
387 // the offset is within bounds and advances. | 388 // the offset is within bounds and advances. |
388 uint32_t offset(const char* name = nullptr) { | 389 uint32_t offset(const char* name = nullptr) { |
389 uint32_t offset = u32(name ? name : "offset"); | 390 uint32_t offset = u32(name ? name : "offset"); |
390 if (offset > (limit_ - start_)) { | 391 if (offset > static_cast<uint32_t>(limit_ - start_)) { |
391 error(pc_ - sizeof(uint32_t), "offset out of bounds of module"); | 392 error(pc_ - sizeof(uint32_t), "offset out of bounds of module"); |
392 } | 393 } |
393 return offset; | 394 return offset; |
394 } | 395 } |
395 | 396 |
396 // Reads a single 32-bit unsigned integer interpreted as an offset into the | 397 // Reads a single 32-bit unsigned integer interpreted as an offset into the |
397 // data and validating the string there and advances. | 398 // data and validating the string there and advances. |
398 uint32_t string(const char* name = nullptr) { | 399 uint32_t string(const char* name = nullptr) { |
399 return offset(name ? name : "string"); // TODO(titzer): validate string | 400 return offset(name ? name : "string"); // TODO(titzer): validate string |
400 } | 401 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 if (function_start > function_end) return FunctionError("start > end"); | 524 if (function_start > function_end) return FunctionError("start > end"); |
524 if (size > kMaxFunctionSize) | 525 if (size > kMaxFunctionSize) |
525 return FunctionError("size > maximum function size"); | 526 return FunctionError("size > maximum function size"); |
526 WasmFunction* function = new WasmFunction(); | 527 WasmFunction* function = new WasmFunction(); |
527 ModuleDecoder decoder(zone, function_start, function_end, false); | 528 ModuleDecoder decoder(zone, function_start, function_end, false); |
528 return decoder.DecodeSingleFunction(module_env, function); | 529 return decoder.DecodeSingleFunction(module_env, function); |
529 } | 530 } |
530 } // namespace wasm | 531 } // namespace wasm |
531 } // namespace internal | 532 } // namespace internal |
532 } // namespace v8 | 533 } // namespace v8 |
OLD | NEW |