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

Side by Side Diff: runtime/platform/json.cc

Issue 10800024: Fix Dart_GetClassInfo (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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 | runtime/vm/debugger_api_impl.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/json.h" 5 #include "platform/json.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 355 }
356 356
357 357
358 void TextBuffer::AddUTF8(uint32_t ch) { 358 void TextBuffer::AddUTF8(uint32_t ch) {
359 static const uint32_t kMaxOneByteChar = 0x7F; 359 static const uint32_t kMaxOneByteChar = 0x7F;
360 static const uint32_t kMaxTwoByteChar = 0x7FF; 360 static const uint32_t kMaxTwoByteChar = 0x7FF;
361 static const uint32_t kMaxThreeByteChar = 0xFFFF; 361 static const uint32_t kMaxThreeByteChar = 0xFFFF;
362 static const uint32_t kMaxFourByteChar = 0x10FFFF; 362 static const uint32_t kMaxFourByteChar = 0x10FFFF;
363 static const uint32_t kMask = ~(1 << 6); 363 static const uint32_t kMask = ~(1 << 6);
364 364
365 EnsureCapacity(sizeof(ch));
366 if (ch <= kMaxOneByteChar) { 365 if (ch <= kMaxOneByteChar) {
367 EnsureCapacity(1); 366 EnsureCapacity(1);
368 buf_[msg_len_++] = ch; 367 buf_[msg_len_++] = ch;
369 buf_[msg_len_] = '\0'; 368 buf_[msg_len_] = '\0';
370 return; 369 return;
371 } 370 }
372 if (ch <= kMaxTwoByteChar) { 371 if (ch <= kMaxTwoByteChar) {
373 EnsureCapacity(2); 372 EnsureCapacity(2);
374 buf_[msg_len_++] = 0xC0 | (ch >> 6); 373 buf_[msg_len_++] = 0xC0 | (ch >> 6);
375 buf_[msg_len_++] = 0x80 | (ch & kMask); 374 buf_[msg_len_++] = 0x80 | (ch & kMask);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 AddUTF8(cp); 454 AddUTF8(cp);
456 } 455 }
457 } 456 }
458 } 457 }
459 458
460 459
461 void TextBuffer::EnsureCapacity(intptr_t len) { 460 void TextBuffer::EnsureCapacity(intptr_t len) {
462 intptr_t remaining = buf_size_ - msg_len_; 461 intptr_t remaining = buf_size_ - msg_len_;
463 if (remaining <= len) { 462 if (remaining <= len) {
464 const int kBufferSpareCapacity = 64; // Somewhat arbitrary. 463 const int kBufferSpareCapacity = 64; // Somewhat arbitrary.
464 // TODO(turnidge): do we need to guard against overflow or other
465 // security issues here? Text buffers are used by the debugger
466 // to send user-controlled data (e.g. values of string variables) to
467 // the debugger front-end.
465 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity; 468 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity;
466 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); 469 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
467 ASSERT(new_buf != NULL); 470 ASSERT(new_buf != NULL);
468 buf_ = new_buf; 471 buf_ = new_buf;
469 buf_size_ = new_size; 472 buf_size_ = new_size;
470 } 473 }
471 } 474 }
472 475
473 } // namespace dart 476 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698