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

Side by Side Diff: pdf/pdfium/pdfium_api_string_buffer_adapter.h

Issue 848073003: PDF: Yet another stab at getting WriteInto() buffer sizes correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: document Created 5 years, 11 months 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
6 #define PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
7
8 #include "base/basictypes.h"
9
10 namespace chrome_pdf {
11
12 // Helper to deal with the fact that many PDFium APIs write the null-terminator
13 // into string buffers that are passed to them, but the PDF plugin likes to pass
14 // in std::strings / base::string16s, where one should not count on the internal
15 // string buffers to be null-terminated.
16
17 template <typename STRING_TYPE>
18 class PDFiumAPIStringBufferAdapter {
19 public:
20 // |str| is the string to write into.
21 // |expected_size| is the number of characters the PDFium API will write,
22 // including the null-terminator. It should be at least 1.
23 // |check_expected_size| whether to check the actual number of characters
24 // written into |str| against |expected_size| when calling Close().
25 PDFiumAPIStringBufferAdapter(STRING_TYPE* str,
26 size_t expected_size,
27 bool check_expected_size);
28 ~PDFiumAPIStringBufferAdapter();
29
30 // Returns a pointer to |str_|'s buffer. The buffer's size is large enough to
31 // hold |expected_size_| + 1 characters, so teh PDFium API that uses the
raymes 2015/01/15 04:33:24 nit: teh->the
32 // pointer has space to write a null-terminator.
33 void* GetData();
34
35 // Resizes |str_| to |actual_size| - 1 characters, thereby removing the extra
36 // null-terminator. This must be called prior to the adapter's destruction.
37 // The pointer returned by GetData() should be considered invalid.
38 void Close(int actual_size);
39 void Close(size_t actual_size);
40
41 private:
42 STRING_TYPE* const str_;
43 void* const data_;
44 const size_t expected_size_;
45 const bool check_expected_size_;
46 bool is_closed_;
47
48 DISALLOW_COPY_AND_ASSIGN(PDFiumAPIStringBufferAdapter);
49 };
50
51 } // namespace chrome_pdf
52
53 #endif // PDF_PDFIUM_PDFIUM_API_STRING_BUFFER_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698