From f75bdb181576e4a4cf8291706a0db86c687e5fc3 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 11 Dec 2015 16:26:00 -0800 Subject: 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 . --- xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp | 4 ++-- xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp | 2 +- xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp | 2 +- xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.cpp | 2 +- xfa/src/fxbarcode/pdf417/BC_PDF417DecodedBitStreamParser.cpp | 4 ++-- xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp | 2 +- xfa/src/fxbarcode/pdf417/BC_PDF417Writer.cpp | 2 +- xfa/src/fxfa/src/app/xfa_ffwidget.cpp | 2 +- xfa/src/fxgraphics/src/fx_graphics.cpp | 6 ++---- 9 files changed, 12 insertions(+), 14 deletions(-) (limited to 'xfa/src') 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); -- cgit v1.2.3