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

Unified Diff: runtime/vm/object.cc

Issue 10823181: Account for '\0' string terminator in allocated buffers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index bedc5ba2aec7e32c14ac35294fad6f6e7cac37f1..842c6e87e6be48e09c9835c19d14a757d8c4673b 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -3936,7 +3936,7 @@ static intptr_t ConstructFunctionFullyQualifiedCString(const Function& function,
ASSERT(chars != NULL);
*chars = Isolate::Current()->current_zone()->Alloc<char>(reserve_len + 1);
written = OS::SNPrint(
- *chars, reserve_len, lib_class_format, library_name, class_name);
+ *chars, reserve_len + 1, lib_class_format, library_name, class_name);
} else {
written = ConstructFunctionFullyQualifiedCString(parent,
chars,
@@ -6933,13 +6933,13 @@ const char* DeoptInfo::ToCString() const {
return "No DeoptInfo";
}
// First compute the buffer size required.
- intptr_t len = 0;
+ intptr_t len = 1;
srdjan 2012/08/06 16:07:19 Add comment: // Trailing '\0'.
Kevin Millikin (Google) 2012/08/07 10:07:59 Done.
for (intptr_t i = 0; i < Length(); i++) {
len += OS::SNPrint(NULL, 0, "[%d(%d):%d]",
- Instruction(i), FromIndex(i), i);
+ Instruction(i), FromIndex(i), i);
}
// Allocate the buffer.
- char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
+ char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len);
// Layout the fields in the buffer.
intptr_t index = 0;
for (intptr_t i = 0; i < Length(); i++) {
@@ -7219,7 +7219,7 @@ uword Code::GetDeoptPcAtNodeId(intptr_t node_id) const {
const char* Code::ToCString() const {
const char* kFormat = "Code entry:0x%d";
- intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint());
+ intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1;
char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, EntryPoint());
return chars;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698