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

Side by Side Diff: src/conversions.cc

Issue 998213002: add 0 length guard in IsNonArrayIndexInteger (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: test Created 5 years, 9 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 | « no previous file | test/cctest/test-conversions.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <limits.h> 5 #include <limits.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 502 }
503 } 503 }
504 504
505 505
506 bool IsNonArrayIndexInteger(String* string) { 506 bool IsNonArrayIndexInteger(String* string) {
507 const int kBufferSize = 64; 507 const int kBufferSize = 64;
508 const int kUint32MaxChars = 11; 508 const int kUint32MaxChars = 11;
509 uint16_t buffer[kBufferSize]; 509 uint16_t buffer[kBufferSize];
510 int offset = 0; 510 int offset = 0;
511 const int length = string->length(); 511 const int length = string->length();
512 DCHECK_NE(0, length); 512 if (length == 0) return false;
513 // First iteration, check for minus, 0 followed by anything else, etc. 513 // First iteration, check for minus, 0 followed by anything else, etc.
514 int to = std::min(offset + kUint32MaxChars, length); 514 int to = std::min(offset + kUint32MaxChars, length);
515 { 515 {
516 String::WriteToFlat(string, buffer, offset, to); 516 String::WriteToFlat(string, buffer, offset, to);
517 bool negative = false; 517 bool negative = false;
518 if (buffer[offset] == '-') { 518 if (buffer[offset] == '-') {
519 negative = true; 519 negative = true;
520 ++offset; 520 ++offset;
521 if (offset == to) return false; // Just '-' is bad. 521 if (offset == to) return false; // Just '-' is bad.
522 } 522 }
(...skipping 24 matching lines...) Expand all
547 } 547 }
548 if (offset == length) break; 548 if (offset == length) break;
549 // Read next chunk. 549 // Read next chunk.
550 to = std::min(offset + kBufferSize, length); 550 to = std::min(offset + kBufferSize, length);
551 String::WriteToFlat(string, buffer, offset, to); 551 String::WriteToFlat(string, buffer, offset, to);
552 i = 0; 552 i = 0;
553 } 553 }
554 return true; 554 return true;
555 } 555 }
556 } } // namespace v8::internal 556 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698