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

Unified Diff: mojo/public/bindings/lib/bindings.cc

Issue 105133002: Add array bounds assertion and improve type conversion for empty strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak Created 7 years 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 | mojo/public/bindings/lib/bindings_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/lib/bindings.cc
diff --git a/mojo/public/bindings/lib/bindings.cc b/mojo/public/bindings/lib/bindings.cc
index 9f4d6fddc5f8921092cd78363de48c68eb08621a..a9d748f41c4b853507074e84bb1f9109016bd644 100644
--- a/mojo/public/bindings/lib/bindings.cc
+++ b/mojo/public/bindings/lib/bindings.cc
@@ -10,21 +10,28 @@ namespace mojo {
String SimilarityTraits<String, std::string>::CopyFrom(const std::string& input,
Buffer* buf) {
String::Builder result(input.size(), buf);
- memcpy(&result[0], input.data(), input.size());
+ if (!input.empty())
+ memcpy(&result[0], input.data(), input.size());
return result.Finish();
}
// static
std::string SimilarityTraits<String, std::string>::CopyTo(const String& input) {
- return input.is_null() ? std::string() :
- std::string(&input[0], &input[0] + input.size());
+ if (input.is_null() || input.size() == 0)
+ return std::string();
+
+ return std::string(&input[0], &input[0] + input.size());
}
// static
String SimilarityTraits<String, const char*>::CopyFrom(const char* input,
Buffer* buf) {
+ if (!input)
+ return String();
+
size_t size = strlen(input);
String::Builder result(size, buf);
- memcpy(&result[0], input, size);
+ if (size != 0)
+ memcpy(&result[0], input, size);
return result.Finish();
}
« no previous file with comments | « no previous file | mojo/public/bindings/lib/bindings_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698