summaryrefslogtreecommitdiffstats
path: root/net/proxy/proxy_resolver_v8.cc
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 15:44:59 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 15:44:59 +0000
commit11fe41a6b2cb4229f8ef3ff0bc22fd609fe838e4 (patch)
tree4d96de4a5d645b319425b2864f4d5700e39c0642 /net/proxy/proxy_resolver_v8.cc
parenta2d67740c562caea523f3650c063d75ee4c0a8ac (diff)
downloadchromium_src-11fe41a6b2cb4229f8ef3ff0bc22fd609fe838e4.zip
chromium_src-11fe41a6b2cb4229f8ef3ff0bc22fd609fe838e4.tar.gz
chromium_src-11fe41a6b2cb4229f8ef3ff0bc22fd609fe838e4.tar.bz2
WriteInto handles length_with_null values of 1 better.
In debug builds on VS2010, the old code triggered a debug assertion in xstring, since [0] was being accessed and the size of the array was 0. A |length_with_null| of 1 is considered a valid use of this function, so an alternate implementation is used which returns the data() pointer. BUG=None TEST=net_unittests --gtest_filter=*Digest* on debug on VS2010 works. Review URL: http://codereview.chromium.org/8143001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_resolver_v8.cc')
-rw-r--r--net/proxy/proxy_resolver_v8.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
index 5c3113d..1bd736c 100644
--- a/net/proxy/proxy_resolver_v8.cc
+++ b/net/proxy/proxy_resolver_v8.cc
@@ -138,8 +138,10 @@ const size_t kMaxStringBytesForCopy = 256;
// Converts a V8 String to a UTF8 std::string.
std::string V8StringToUTF8(v8::Handle<v8::String> s) {
+ int len = s->Length();
std::string result;
- s->WriteUtf8(WriteInto(&result, s->Length() + 1));
+ if (len > 0)
+ s->WriteUtf8(WriteInto(&result, len + 1));
return result;
}
@@ -149,7 +151,8 @@ string16 V8StringToUTF16(v8::Handle<v8::String> s) {
string16 result;
// Note that the reinterpret cast is because on Windows string16 is an alias
// to wstring, and hence has character type wchar_t not uint16_t.
- s->Write(reinterpret_cast<uint16_t*>(WriteInto(&result, len + 1)), 0, len);
+ if (len > 0)
+ s->Write(reinterpret_cast<uint16_t*>(WriteInto(&result, len + 1)), 0, len);
return result;
}