summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-12-11 16:26:00 -0800
committerTom Sepez <tsepez@chromium.org>2015-12-11 16:26:00 -0800
commitf75bdb181576e4a4cf8291706a0db86c687e5fc3 (patch)
tree4440158d95c723b1ef02753b4dfa9d1a598e1a87 /xfa
parent74aa4e19a332436ff3bcf539c905e992b1d3ac4e (diff)
downloadpdfium-f75bdb181576e4a4cf8291706a0db86c687e5fc3.tar.xz
XFA: avoid multiplications in FX_Allocs
In some cases, we can use the safe FX_Alloc2D, in others there's an extra multiplication by the size of the type. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1519233002 .
Diffstat (limited to 'xfa')
-rw-r--r--xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp4
-rw-r--r--xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp2
-rw-r--r--xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp2
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp2
-rw-r--r--xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp4
-rw-r--r--xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp2
-rw-r--r--xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp2
-rw-r--r--xfa/src/fxfa/src/app/xfa_ffwidget.cpp2
-rw-r--r--xfa/src/fxgraphics/src/fx_graphics.cpp6
9 files changed, 12 insertions, 14 deletions
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp
index 0a0930d97c..ec2706b122 100644
--- a/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -34,7 +34,7 @@ void CBC_CommonBitMatrix::Init(int32_t dimension) {
m_height = dimension;
int32_t rowSize = (m_height + 31) >> 5;
m_rowSize = rowSize;
- m_bits = FX_Alloc(int32_t, m_rowSize * m_height);
+ m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
@@ -42,7 +42,7 @@ void CBC_CommonBitMatrix::Init(int32_t width, int32_t height) {
m_height = height;
int32_t rowSize = (width + 31) >> 5;
m_rowSize = rowSize;
- m_bits = FX_Alloc(int32_t, m_rowSize * m_height);
+ m_bits = FX_Alloc2D(int32_t, m_rowSize, m_height);
FXSYS_memset(m_bits, 0, m_rowSize * m_height * sizeof(int32_t));
}
CBC_CommonBitMatrix::~CBC_CommonBitMatrix() {
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp
index ee4eee26a9..d6208d41b5 100644
--- a/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp
+++ b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp
@@ -28,7 +28,7 @@ CBC_CommonByteMatrix::CBC_CommonByteMatrix(int32_t width, int32_t height) {
m_bytes = NULL;
}
void CBC_CommonByteMatrix::Init() {
- m_bytes = FX_Alloc(uint8_t, m_height * m_width);
+ m_bytes = FX_Alloc2D(uint8_t, m_height, m_width);
FXSYS_memset(m_bytes, 0xff, m_height * m_width);
}
CBC_CommonByteMatrix::~CBC_CommonByteMatrix() {
diff --git a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index 25438f389a..d2f2507729 100644
--- a/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -80,7 +80,7 @@ uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents,
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
outWidth = bytematrix->GetWidth();
outHeight = bytematrix->GetHeight();
- uint8_t* result = FX_Alloc(uint8_t, outWidth * outHeight);
+ uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight);
FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
delete bytematrix;
delete placement;
diff --git a/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index eef810ac44..a2e27faff8 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -159,7 +159,7 @@ uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString& contents,
CBC_OnedCodaBarReader CodaBarR;
CFX_ByteString data = m_chStart + contents + m_chEnd;
m_iContentLen = data.GetLength();
- uint8_t* result = FX_Alloc(uint8_t, m_iWideNarrRatio * 7 * data.GetLength());
+ uint8_t* result = FX_Alloc2D(uint8_t, m_iWideNarrRatio * 7, data.GetLength());
FX_CHAR ch;
int32_t position = 0;
for (int32_t index = 0; index < data.GetLength(); index++) {
diff --git a/xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp b/xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp
index af63d19bfe..ba822ce1d2 100644
--- a/xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp
+++ b/xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp
@@ -360,7 +360,7 @@ int32_t CBC_DecodedBitStreamPaser::byteCompaction(int32_t mode,
if (mode == BYTE_COMPACTION_MODE_LATCH) {
int32_t count = 0;
int64_t value = 0;
- FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD));
+ FX_WORD* decodedData = FX_Alloc(FX_WORD, 6);
CFX_Int32Array byteCompactedCodewords;
byteCompactedCodewords.SetSize(6);
FX_BOOL end = FALSE;
@@ -421,7 +421,7 @@ int32_t CBC_DecodedBitStreamPaser::byteCompaction(int32_t mode,
}
}
if ((count % 5 == 0) && (count > 0)) {
- FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD));
+ FX_WORD* decodedData = FX_Alloc(FX_WORD, 6);
int32_t j = 0;
for (; j < 6; ++j) {
decodedData[5 - j] = (FX_WORD)(value & 0xFF);
diff --git a/xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index 0fd275c4e6..b0518c6f2c 100644
--- a/xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -135,7 +135,7 @@ CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(
int32_t& e) {
int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e);
BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' ');
- FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k * sizeof(FX_WCHAR));
+ FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k);
FXSYS_memset(ech, 0, k * sizeof(FX_WCHAR));
int32_t sld = dataCodewords.GetLength();
for (int32_t i = 0; i < sld; i++) {
diff --git a/xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp b/xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp
index 457b30b750..d922889b3d 100644
--- a/xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -97,7 +97,7 @@ uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents,
outWidth = temp;
}
}
- uint8_t* result = (uint8_t*)FX_Alloc(uint8_t, outHeight * outWidth);
+ uint8_t* result = FX_Alloc2D(uint8_t, outHeight, outWidth);
FXSYS_memcpy(result, originalScale.GetData(), outHeight * outWidth);
return result;
}
diff --git a/xfa/src/fxfa/src/app/xfa_ffwidget.cpp b/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
index 801c66a8bc..a4015abe62 100644
--- a/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffwidget.cpp
@@ -903,7 +903,7 @@ FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len) {
FX_CHAR* out = NULL;
int i, j;
FX_DWORD limb;
- out = (FX_CHAR*)FX_Alloc(FX_CHAR, ((buf_len * 8 + 5) / 6) + 5);
+ out = FX_Alloc(FX_CHAR, ((buf_len * 8 + 5) / 6) + 5);
for (i = 0, j = 0, limb = 0; i + 2 < buf_len; i += 3, j += 4) {
limb = ((FX_DWORD)buf[i] << 16) | ((FX_DWORD)buf[i + 1] << 8) |
((FX_DWORD)buf[i + 2]);
diff --git a/xfa/src/fxgraphics/src/fx_graphics.cpp b/xfa/src/fxgraphics/src/fx_graphics.cpp
index 53d001e9d7..d983b5d6f8 100644
--- a/xfa/src/fxgraphics/src/fx_graphics.cpp
+++ b/xfa/src/fxgraphics/src/fx_graphics.cpp
@@ -534,8 +534,7 @@ FX_ERR CFX_Graphics::CalcTextRect(CFX_RectF& rect,
_FX_RETURN_VALUE_IF_FAIL(_renderDevice, FX_ERR_Property_Invalid);
int32_t length = text.GetLength();
FX_DWORD* charCodes = FX_Alloc(FX_DWORD, length);
- FXTEXT_CHARPOS* charPos =
- FX_Alloc(FXTEXT_CHARPOS, length * sizeof(FXTEXT_CHARPOS));
+ FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length);
CalcTextInfo(text, charCodes, charPos, rect);
FX_Free(charPos);
FX_Free(charCodes);
@@ -867,8 +866,7 @@ FX_ERR CFX_Graphics::RenderDeviceShowText(const CFX_PointF& point,
CFX_Matrix* matrix) {
int32_t length = text.GetLength();
FX_DWORD* charCodes = FX_Alloc(FX_DWORD, length);
- FXTEXT_CHARPOS* charPos =
- FX_Alloc(FXTEXT_CHARPOS, length * sizeof(FXTEXT_CHARPOS));
+ FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length);
CFX_RectF rect;
rect.Set(point.x, point.y, 0, 0);
CalcTextInfo(text, charCodes, charPos, rect);