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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/bindings/lib/bindings_internal.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium 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 "mojo/public/bindings/lib/bindings.h" 5 #include "mojo/public/bindings/lib/bindings.h"
6 6
7 namespace mojo { 7 namespace mojo {
8 8
9 // static 9 // static
10 String SimilarityTraits<String, std::string>::CopyFrom(const std::string& input, 10 String SimilarityTraits<String, std::string>::CopyFrom(const std::string& input,
11 Buffer* buf) { 11 Buffer* buf) {
12 String::Builder result(input.size(), buf); 12 String::Builder result(input.size(), buf);
13 memcpy(&result[0], input.data(), input.size()); 13 if (!input.empty())
14 memcpy(&result[0], input.data(), input.size());
14 return result.Finish(); 15 return result.Finish();
15 } 16 }
16 // static 17 // static
17 std::string SimilarityTraits<String, std::string>::CopyTo(const String& input) { 18 std::string SimilarityTraits<String, std::string>::CopyTo(const String& input) {
18 return input.is_null() ? std::string() : 19 if (input.is_null() || input.size() == 0)
19 std::string(&input[0], &input[0] + input.size()); 20 return std::string();
21
22 return std::string(&input[0], &input[0] + input.size());
20 } 23 }
21 24
22 // static 25 // static
23 String SimilarityTraits<String, const char*>::CopyFrom(const char* input, 26 String SimilarityTraits<String, const char*>::CopyFrom(const char* input,
24 Buffer* buf) { 27 Buffer* buf) {
28 if (!input)
29 return String();
30
25 size_t size = strlen(input); 31 size_t size = strlen(input);
26 String::Builder result(size, buf); 32 String::Builder result(size, buf);
27 memcpy(&result[0], input, size); 33 if (size != 0)
34 memcpy(&result[0], input, size);
28 return result.Finish(); 35 return result.Finish();
29 } 36 }
30 37
31 } // namespace mojo 38 } // namespace mojo
OLDNEW
« 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