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

Side by Side Diff: src/runtime.cc

Issue 433463002: Avoid calling memchr with a zero range as this is undefined behavior. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/string-search.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 3585 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 char pattern, 3596 char pattern,
3597 ZoneList<int>* indices, 3597 ZoneList<int>* indices,
3598 unsigned int limit, 3598 unsigned int limit,
3599 Zone* zone) { 3599 Zone* zone) {
3600 ASSERT(limit > 0); 3600 ASSERT(limit > 0);
3601 // Collect indices of pattern in subject using memchr. 3601 // Collect indices of pattern in subject using memchr.
3602 // Stop after finding at most limit values. 3602 // Stop after finding at most limit values.
3603 const uint8_t* subject_start = subject.start(); 3603 const uint8_t* subject_start = subject.start();
3604 const uint8_t* subject_end = subject_start + subject.length(); 3604 const uint8_t* subject_end = subject_start + subject.length();
3605 const uint8_t* pos = subject_start; 3605 const uint8_t* pos = subject_start;
3606 while (limit > 0) { 3606 while ((limit > 0) && (subject_end > pos)) {
3607 pos = reinterpret_cast<const uint8_t*>( 3607 pos = reinterpret_cast<const uint8_t*>(
3608 memchr(pos, pattern, subject_end - pos)); 3608 memchr(pos, pattern, subject_end - pos));
3609 if (pos == NULL) return; 3609 if (pos == NULL) return;
3610 indices->Add(static_cast<int>(pos - subject_start), zone); 3610 indices->Add(static_cast<int>(pos - subject_start), zone);
3611 pos++; 3611 pos++;
3612 limit--; 3612 limit--;
3613 } 3613 }
3614 } 3614 }
3615 3615
3616 3616
(...skipping 11468 matching lines...) Expand 10 before | Expand all | Expand 10 after
15085 } 15085 }
15086 return NULL; 15086 return NULL;
15087 } 15087 }
15088 15088
15089 15089
15090 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15090 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15091 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15091 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15092 } 15092 }
15093 15093
15094 } } // namespace v8::internal 15094 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/string-search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698