summaryrefslogtreecommitdiff
path: root/core/fxcrt/widestring_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-12 18:33:55 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 18:33:55 +0000
commit154e18f9a862975abecebe77b8f5fb418418d14c (patch)
tree18e9381c1a4324abcd98296e1e1714c2f926e006 /core/fxcrt/widestring_unittest.cpp
parent7f821c11081fe90346823333622253ec7949b583 (diff)
downloadpdfium-154e18f9a862975abecebe77b8f5fb418418d14c.tar.xz
Return pdfium::span<wchar_t> from WideString::GetBuffer().
Adds bounds checking "for free", but beware of span outliving a ReleaseBuffer() call. Scoping as such avoids the possibility of using an invalid span (and it is flagged as a lifetime issue). Change-Id: Ica63f4b1429823d0254ec6951aeaeb08160cb93c Reviewed-on: https://pdfium-review.googlesource.com/30310 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/widestring_unittest.cpp')
-rw-r--r--core/fxcrt/widestring_unittest.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index 473d59c491..ad91249c8e 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -813,20 +813,21 @@ TEST(WideString, Reserve) {
}
TEST(WideString, GetBuffer) {
+ WideString str1;
{
- WideString str;
- wchar_t* buffer = str.GetBuffer(12);
- wcscpy(buffer, L"clams");
- str.ReleaseBuffer(str.GetStringLength());
- EXPECT_EQ(L"clams", str);
+ pdfium::span<wchar_t> buffer = str1.GetBuffer(12);
+ wcscpy(buffer.data(), L"clams");
}
+ str1.ReleaseBuffer(str1.GetStringLength());
+ EXPECT_EQ(L"clams", str1);
+
+ WideString str2(L"cl");
{
- WideString str(L"cl");
- wchar_t* buffer = str.GetBuffer(12);
- wcscpy(buffer + 2, L"ams");
- str.ReleaseBuffer(str.GetStringLength());
- EXPECT_EQ(L"clams", str);
+ pdfium::span<wchar_t> buffer = str2.GetBuffer(12);
+ wcscpy(buffer.data() + 2, L"ams");
}
+ str2.ReleaseBuffer(str2.GetStringLength());
+ EXPECT_EQ(L"clams", str2);
}
TEST(WideString, ReleaseBuffer) {