summaryrefslogtreecommitdiff
path: root/testing/test_support.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-06 10:16:32 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-06 10:16:32 -0800
commit0aa3531a87dde44ffd90416f6d621b1828edaf22 (patch)
tree9b5f0e12a5e1aec13fd3d4f0242efcc6834d830e /testing/test_support.cpp
parentd483eb46d8920547d1b47351e65fa0299eaba191 (diff)
downloadpdfium-0aa3531a87dde44ffd90416f6d621b1828edaf22.tar.xz
Merge to XFA: Return unique_ptrs from test_support functions
Orignal Review URL: https://codereview.chromium.org/1563513002 . (cherry picked from commit aa326bd6b169dc1b5b9b83048c71799799ab34c6) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1564583004 .
Diffstat (limited to 'testing/test_support.cpp')
-rw-r--r--testing/test_support.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/testing/test_support.cpp b/testing/test_support.cpp
index c7ab10ee3c..ce143ae8e9 100644
--- a/testing/test_support.cpp
+++ b/testing/test_support.cpp
@@ -71,7 +71,8 @@ void InitializeV8Common(v8::Platform** platform) {
} // namespace
-char* GetFileContents(const char* filename, size_t* retlen) {
+std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename,
+ size_t* retlen) {
FILE* file = fopen(filename, "rb");
if (!file) {
fprintf(stderr, "Failed to open: %s\n", filename);
@@ -83,15 +84,15 @@ char* GetFileContents(const char* filename, size_t* retlen) {
return nullptr;
}
(void)fseek(file, 0, SEEK_SET);
- char* buffer = (char*)malloc(file_length);
+ std::unique_ptr<char, pdfium::FreeDeleter> buffer(
+ static_cast<char*>(malloc(file_length)));
if (!buffer) {
return nullptr;
}
- size_t bytes_read = fread(buffer, 1, file_length, file);
+ size_t bytes_read = fread(buffer.get(), 1, file_length, file);
(void)fclose(file);
if (bytes_read != file_length) {
fprintf(stderr, "Failed to read: %s\n", filename);
- free(buffer);
return nullptr;
}
*retlen = bytes_read;
@@ -114,9 +115,12 @@ std::wstring GetPlatformWString(FPDF_WIDESTRING wstr) {
return platform_string;
}
-FPDF_WIDESTRING GetFPDFWideString(const std::wstring& wstr) {
+std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString(
+ const std::wstring& wstr) {
size_t length = sizeof(uint16_t) * (wstr.length() + 1);
- unsigned char* ptr = static_cast<unsigned char*>(malloc(length));
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> result(
+ static_cast<unsigned short*>(malloc(length)));
+ char* ptr = reinterpret_cast<char*>(result.get());
size_t i = 0;
for (wchar_t w : wstr) {
ptr[i++] = w & 0xff;
@@ -124,7 +128,7 @@ FPDF_WIDESTRING GetFPDFWideString(const std::wstring& wstr) {
}
ptr[i++] = 0;
ptr[i] = 0;
- return reinterpret_cast<FPDF_WIDESTRING>(ptr);
+ return result;
}
#ifdef PDF_ENABLE_V8