summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode.cpp45
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp50
-rw-r--r--core/fxcrt/bytestring.cpp36
-rw-r--r--core/fxcrt/bytestring.h6
-rw-r--r--core/fxcrt/bytestring_unittest.cpp21
-rw-r--r--core/fxcrt/widestring.cpp21
-rw-r--r--core/fxge/cfx_folderfontinfo.cpp14
-rw-r--r--core/fxge/win32/fx_win32_dib.cpp62
9 files changed, 118 insertions, 154 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index b10134611c..ec826dc5ed 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -200,16 +200,13 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
pCS->AddNew<CPDF_Name>("DeviceRGB");
pCS->AddNew<CPDF_Number>(1);
ByteString ct;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> pBuf = ct.GetBuffer(6);
- pBuf[0] = (char)reset_r;
- pBuf[1] = (char)reset_g;
- pBuf[2] = (char)reset_b;
- pBuf[3] = (char)set_r;
- pBuf[4] = (char)set_g;
- pBuf[5] = (char)set_b;
- }
+ char* pBuf = ct.GetBuffer(6);
+ pBuf[0] = (char)reset_r;
+ pBuf[1] = (char)reset_g;
+ pBuf[2] = (char)reset_b;
+ pBuf[3] = (char)set_r;
+ pBuf[4] = (char)set_g;
+ pBuf[5] = (char)set_b;
ct.ReleaseBuffer(6);
pCS->AddNew<CPDF_String>(ct, true);
}
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 2fdc4daa49..90dca2edcb 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -469,22 +469,20 @@ ByteString PDF_EncodeText(const wchar_t* pString, int len) {
if (len == -1)
len = wcslen(pString);
- int i;
ByteString result;
- {
- pdfium::span<char> dest_buf = result.GetBuffer(len);
- for (i = 0; i < len; ++i) {
- int code;
- for (code = 0; code < 256; ++code) {
- if (PDFDocEncoding[code] == pString[i])
- break;
- }
-
- if (code == 256)
+ char* dest_buf1 = result.GetBuffer(len);
+ int i;
+ for (i = 0; i < len; ++i) {
+ int code;
+ for (code = 0; code < 256; ++code) {
+ if (PDFDocEncoding[code] == pString[i])
break;
-
- dest_buf[i] = code;
}
+
+ if (code == 256)
+ break;
+
+ dest_buf1[i] = code;
}
result.ReleaseBuffer(i);
if (i == len)
@@ -495,18 +493,15 @@ ByteString PDF_EncodeText(const wchar_t* pString, int len) {
return result;
}
- size_t dest_index = 0;
- size_t encLen = len * 2 + 2;
- {
- pdfium::span<char> cspan = result.GetBuffer(encLen);
- auto dest_buf = pdfium::make_span(reinterpret_cast<uint8_t*>(cspan.data()),
- cspan.size());
- dest_buf[dest_index++] = 0xfe;
- dest_buf[dest_index++] = 0xff;
- for (int j = 0; j < len; ++j) {
- dest_buf[dest_index++] = pString[j] >> 8;
- dest_buf[dest_index++] = static_cast<uint8_t>(pString[j]);
- }
+ int encLen = len * 2 + 2;
+
+ uint8_t* dest_buf2 = reinterpret_cast<uint8_t*>(result.GetBuffer(encLen));
+ dest_buf2[0] = 0xfe;
+ dest_buf2[1] = 0xff;
+ dest_buf2 += 2;
+ for (int j = 0; j < len; ++j) {
+ *dest_buf2++ = pString[j] >> 8;
+ *dest_buf2++ = static_cast<uint8_t>(pString[j]);
}
result.ReleaseBuffer(encLen);
return result;
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index b6b94aa84e..c486a76706 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -93,23 +93,20 @@ ByteString PDF_NameDecode(const ByteStringView& bstr) {
if (!bstr.Contains('#'))
return ByteString(bstr);
- size_t src_size = bstr.GetLength();
- size_t out_index = 0;
+ int size = bstr.GetLength();
ByteString result;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> pDest = result.GetBuffer(src_size);
- for (size_t i = 0; i < src_size; i++) {
- if (bstr[i] == '#' && i < src_size - 2) {
- pDest[out_index++] = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
- FXSYS_HexCharToInt(bstr[i + 2]);
- i += 2;
- } else {
- pDest[out_index++] = bstr[i];
- }
+ char* pDestStart = result.GetBuffer(size);
+ char* pDest = pDestStart;
+ for (int i = 0; i < size; i++) {
+ if (bstr[i] == '#' && i < size - 2) {
+ *pDest++ = FXSYS_HexCharToInt(bstr[i + 1]) * 16 +
+ FXSYS_HexCharToInt(bstr[i + 2]);
+ i += 2;
+ } else {
+ *pDest++ = bstr[i];
}
}
- result.ReleaseBuffer(out_index);
+ result.ReleaseBuffer(static_cast<size_t>(pDest - pDestStart));
return result;
}
@@ -131,23 +128,20 @@ ByteString PDF_NameEncode(const ByteString& orig) {
return orig;
ByteString res;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> dest_buf = res.GetBuffer(dest_len);
- dest_len = 0;
- for (i = 0; i < src_len; i++) {
- uint8_t ch = src_buf[i];
- if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
- PDFCharIsDelimiter(ch)) {
- dest_buf[dest_len++] = '#';
- FXSYS_IntToTwoHexChars(ch, &dest_buf[dest_len]);
- dest_len += 2;
- continue;
- }
+ char* dest_buf = res.GetBuffer(dest_len);
+ dest_len = 0;
+ for (i = 0; i < src_len; i++) {
+ uint8_t ch = src_buf[i];
+ if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
+ PDFCharIsDelimiter(ch)) {
+ dest_buf[dest_len++] = '#';
+ FXSYS_IntToTwoHexChars(ch, dest_buf + dest_len);
+ dest_len += 2;
+ } else {
dest_buf[dest_len++] = ch;
}
- dest_buf[dest_len] = 0;
}
+ dest_buf[dest_len] = 0;
res.ReleaseBuffer(res.GetStringLength());
return res;
}
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 872de065ba..f5687c591e 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -18,7 +18,6 @@
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/string_pool_template.h"
#include "third_party/base/numerics/safe_math.h"
-#include "third_party/base/span.h"
#include "third_party/base/stl_util.h"
template class fxcrt::StringDataTemplate<char>;
@@ -82,12 +81,9 @@ ByteString GetByteString(uint16_t codepage, const WideStringView& wstr) {
return ByteString();
ByteString bstr;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> dest_buf = bstr.GetBuffer(dest_len);
- FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len,
- dest_buf.data(), dest_len, nullptr, nullptr);
- }
+ char* dest_buf = bstr.GetBuffer(dest_len);
+ FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len,
+ dest_buf, dest_len, nullptr, nullptr);
bstr.ReleaseBuffer(dest_len);
return bstr;
}
@@ -124,21 +120,19 @@ ByteString ByteString::FormatV(const char* pFormat, va_list argList) {
va_end(argListCopy);
if (nMaxLen <= 0)
- return ByteString();
+ return "";
ByteString ret;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> buf = ret.GetBuffer(nMaxLen);
-
+ char* buf = ret.GetBuffer(nMaxLen);
+ if (buf) {
// In the following two calls, there's always space in the buffer for
// a terminating NUL that's not included in nMaxLen.
- memset(buf.data(), 0, nMaxLen + 1);
+ memset(buf, 0, nMaxLen + 1);
va_copy(argListCopy, argList);
- vsnprintf(buf.data(), nMaxLen + 1, pFormat, argListCopy);
+ vsnprintf(buf, nMaxLen + 1, pFormat, argListCopy);
va_end(argListCopy);
+ ret.ReleaseBuffer(ret.GetStringLength());
}
- ret.ReleaseBuffer(ret.GetStringLength());
return ret;
}
@@ -425,29 +419,29 @@ void ByteString::Reserve(size_t len) {
GetBuffer(len);
}
-pdfium::span<char> ByteString::GetBuffer(size_t nMinBufLength) {
+char* ByteString::GetBuffer(size_t nMinBufLength) {
if (!m_pData) {
if (nMinBufLength == 0)
- return pdfium::span<char>();
+ return nullptr;
m_pData.Reset(StringData::Create(nMinBufLength));
m_pData->m_nDataLength = 0;
m_pData->m_String[0] = 0;
- return pdfium::span<char>(m_pData->m_String, m_pData->m_nAllocLength);
+ return m_pData->m_String;
}
if (m_pData->CanOperateInPlace(nMinBufLength))
- return pdfium::span<char>(m_pData->m_String, m_pData->m_nAllocLength);
+ return m_pData->m_String;
nMinBufLength = std::max(nMinBufLength, m_pData->m_nDataLength);
if (nMinBufLength == 0)
- return pdfium::span<char>();
+ return nullptr;
RetainPtr<StringData> pNewData(StringData::Create(nMinBufLength));
pNewData->CopyContents(*m_pData);
pNewData->m_nDataLength = m_pData->m_nDataLength;
m_pData.Swap(pNewData);
- return pdfium::span<char>(m_pData->m_String, m_pData->m_nAllocLength);
+ return m_pData->m_String;
}
size_t ByteString::Delete(size_t index, size_t count) {
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index 247238573d..ccb539b2ef 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -17,7 +17,6 @@
#include "core/fxcrt/string_data_template.h"
#include "core/fxcrt/string_view_template.h"
#include "third_party/base/optional.h"
-#include "third_party/base/span.h"
namespace fxcrt {
@@ -154,10 +153,7 @@ class ByteString {
size_t Delete(size_t index, size_t count = 1);
void Reserve(size_t len);
-
- // Note: any modification of the string (including ReleaseBuffer()) may
- // invalidate the span, which must not outlive its buffer.
- pdfium::span<char> GetBuffer(size_t len);
+ char* GetBuffer(size_t len);
void ReleaseBuffer(size_t len);
ByteString Mid(size_t first, size_t count) const;
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp
index d030535edd..f7e1559af9 100644
--- a/core/fxcrt/bytestring_unittest.cpp
+++ b/core/fxcrt/bytestring_unittest.cpp
@@ -843,23 +843,22 @@ TEST(ByteString, Reserve) {
}
TEST(ByteString, GetBuffer) {
- ByteString str1;
{
- pdfium::span<char> buffer = str1.GetBuffer(12);
+ ByteString str;
+ char* buffer = str.GetBuffer(12);
// NOLINTNEXTLINE(runtime/printf)
- strcpy(buffer.data(), "clams");
+ strcpy(buffer, "clams");
+ str.ReleaseBuffer(str.GetStringLength());
+ EXPECT_EQ("clams", str);
}
- str1.ReleaseBuffer(str1.GetStringLength());
- EXPECT_EQ("clams", str1);
-
- ByteString str2("cl");
{
- pdfium::span<char> buffer = str2.GetBuffer(12);
+ ByteString str("cl");
+ char* buffer = str.GetBuffer(12);
// NOLINTNEXTLINE(runtime/printf)
- strcpy(&buffer[2], "ams");
+ strcpy(buffer + 2, "ams");
+ str.ReleaseBuffer(str.GetStringLength());
+ EXPECT_EQ("clams", str);
}
- str2.ReleaseBuffer(str2.GetStringLength());
- EXPECT_EQ("clams", str2);
}
TEST(ByteString, ReleaseBuffer) {
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 25f253ea11..a3525593ee 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -667,21 +667,18 @@ ByteString WideString::UTF8Encode() const {
}
ByteString WideString::UTF16LE_Encode() const {
- if (!m_pData)
+ if (!m_pData) {
return ByteString("\0\0", 2);
-
- ByteString result;
+ }
int len = m_pData->m_nDataLength;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> buffer = result.GetBuffer(len * 2 + 2);
- for (int i = 0; i < len; i++) {
- buffer[i * 2] = m_pData->m_String[i] & 0xff;
- buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
- }
- buffer[len * 2] = 0;
- buffer[len * 2 + 1] = 0;
+ ByteString result;
+ char* buffer = result.GetBuffer(len * 2 + 2);
+ for (int i = 0; i < len; i++) {
+ buffer[i * 2] = m_pData->m_String[i] & 0xff;
+ buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
}
+ buffer[len * 2] = 0;
+ buffer[len * 2 + 1] = 0;
result.ReleaseBuffer(len * 2 + 2);
return result;
}
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index b39c57637f..532824d248 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -44,15 +44,11 @@ const struct {
};
ByteString FPDF_ReadStringFromFile(FILE* pFile, uint32_t size) {
- ByteString result;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> buffer = result.GetBuffer(size);
- if (!fread(buffer.data(), size, 1, pFile))
- return ByteString();
- }
- result.ReleaseBuffer(size);
- return result;
+ ByteString buffer;
+ if (!fread(buffer.GetBuffer(size), size, 1, pFile))
+ return ByteString();
+ buffer.ReleaseBuffer(size);
+ return buffer;
}
ByteString FPDF_LoadTableFromTT(FILE* pFile,
diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp
index b6bed7a987..452d033f64 100644
--- a/core/fxge/win32/fx_win32_dib.cpp
+++ b/core/fxge/win32/fx_win32_dib.cpp
@@ -13,45 +13,41 @@
ByteString CFX_WindowsDIB::GetBitmapInfo(
const RetainPtr<CFX_DIBitmap>& pBitmap) {
+ ByteString result;
int len = sizeof(BITMAPINFOHEADER);
- if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8)
+ if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
len += sizeof(DWORD) * (int)(1 << pBitmap->GetBPP());
-
- ByteString result;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<char> cspan = result.GetBuffer(len);
- BITMAPINFOHEADER* pbmih = reinterpret_cast<BITMAPINFOHEADER*>(cspan.data());
- memset(pbmih, 0, sizeof(BITMAPINFOHEADER));
- pbmih->biSize = sizeof(BITMAPINFOHEADER);
- pbmih->biBitCount = pBitmap->GetBPP();
- pbmih->biCompression = BI_RGB;
- pbmih->biHeight = -(int)pBitmap->GetHeight();
- pbmih->biPlanes = 1;
- pbmih->biWidth = pBitmap->GetWidth();
- if (pBitmap->GetBPP() == 8) {
- uint32_t* pPalette = (uint32_t*)(pbmih + 1);
- if (pBitmap->GetPalette()) {
- for (int i = 0; i < 256; i++) {
- pPalette[i] = pBitmap->GetPalette()[i];
- }
- } else {
- for (int i = 0; i < 256; i++) {
- pPalette[i] = i * 0x010101;
- }
+ }
+ BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)result.GetBuffer(len);
+ memset(pbmih, 0, sizeof(BITMAPINFOHEADER));
+ pbmih->biSize = sizeof(BITMAPINFOHEADER);
+ pbmih->biBitCount = pBitmap->GetBPP();
+ pbmih->biCompression = BI_RGB;
+ pbmih->biHeight = -(int)pBitmap->GetHeight();
+ pbmih->biPlanes = 1;
+ pbmih->biWidth = pBitmap->GetWidth();
+ if (pBitmap->GetBPP() == 8) {
+ uint32_t* pPalette = (uint32_t*)(pbmih + 1);
+ if (pBitmap->GetPalette()) {
+ for (int i = 0; i < 256; i++) {
+ pPalette[i] = pBitmap->GetPalette()[i];
}
- }
- if (pBitmap->GetBPP() == 1) {
- uint32_t* pPalette = (uint32_t*)(pbmih + 1);
- if (pBitmap->GetPalette()) {
- pPalette[0] = pBitmap->GetPalette()[0];
- pPalette[1] = pBitmap->GetPalette()[1];
- } else {
- pPalette[0] = 0;
- pPalette[1] = 0xffffff;
+ } else {
+ for (int i = 0; i < 256; i++) {
+ pPalette[i] = i * 0x010101;
}
}
}
+ if (pBitmap->GetBPP() == 1) {
+ uint32_t* pPalette = (uint32_t*)(pbmih + 1);
+ if (pBitmap->GetPalette()) {
+ pPalette[0] = pBitmap->GetPalette()[0];
+ pPalette[1] = pBitmap->GetPalette()[1];
+ } else {
+ pPalette[0] = 0;
+ pPalette[1] = 0xffffff;
+ }
+ }
result.ReleaseBuffer(len);
return result;
}