Use DataVector<T> in core/fxcodec/.

Easier to write than std::vector<T, FxAllocAllocator<T>>.

Change-Id: I652763e014cc66dca8939b098fc2ea7db00aab0d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96670
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcodec/basic/basicmodule.cpp b/core/fxcodec/basic/basicmodule.cpp
index 6b57fe8..8ccecbc 100644
--- a/core/fxcodec/basic/basicmodule.cpp
+++ b/core/fxcodec/basic/basicmodule.cpp
@@ -4,11 +4,13 @@
 
 #include "core/fxcodec/basic/basicmodule.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <utility>
-#include <vector>
 
 #include "core/fxcodec/scanlinedecoder.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxcrt/fx_system.h"
@@ -41,7 +43,7 @@
   void GetNextOperator();
   void UpdateOperator(uint8_t used_bytes);
 
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_Scanline;
+  DataVector<uint8_t> m_Scanline;
   pdfium::span<const uint8_t> m_SrcBuf;
   size_t m_dwLineBytes = 0;
   size_t m_SrcOffset = 0;
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index b37c70d..2db8d57 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -6,13 +6,15 @@
 
 #include "core/fxcodec/bmp/cfx_bmpdecompressor.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <limits>
 #include <utility>
 
 #include "core/fxcodec/bmp/cfx_bmpcontext.h"
 #include "core/fxcodec/cfx_codec_memory.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxge/calculate_pitch.h"
@@ -295,7 +297,7 @@
     if (color_used_ != 0)
       pal_num_ = color_used_;
     size_t src_pal_size = pal_num_ * PaletteChannelCount();
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>> src_pal(src_pal_size);
+    DataVector<uint8_t> src_pal(src_pal_size);
     uint8_t* src_pal_data = src_pal.data();
     if (!ReadData(src_pal))
       return BmpDecoder::Status::kContinue;
@@ -366,7 +368,7 @@
 }
 
 BmpDecoder::Status CFX_BmpDecompressor::DecodeRGB() {
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> dest_buf(src_row_bytes_);
+  DataVector<uint8_t> dest_buf(src_row_bytes_);
   while (row_num_ < height_) {
     size_t idx = 0;
     if (!ReadData(dest_buf))
@@ -493,8 +495,7 @@
 
             size_t second_part_size =
                 first_part & 1 ? first_part + 1 : first_part;
-            std::vector<uint8_t, FxAllocAllocator<uint8_t>> second_part(
-                second_part_size);
+            DataVector<uint8_t> second_part(second_part_size);
             uint8_t* second_part_data = second_part.data();
             if (!ReadData(second_part))
               return BmpDecoder::Status::kContinue;
@@ -590,8 +591,7 @@
               first_part = avail_size - 1;
             }
             size_t second_part_size = size & 1 ? size + 1 : size;
-            std::vector<uint8_t, FxAllocAllocator<uint8_t>> second_part(
-                second_part_size);
+            DataVector<uint8_t> second_part(second_part_size);
             uint8_t* second_part_data = second_part.data();
             if (!ReadData(second_part))
               return BmpDecoder::Status::kContinue;
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index f135ff2..640c217 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -7,11 +7,13 @@
 #ifndef CORE_FXCODEC_BMP_CFX_BMPDECOMPRESSOR_H_
 #define CORE_FXCODEC_BMP_CFX_BMPDECOMPRESSOR_H_
 
+#include <stdint.h>
+
 #include <vector>
 
 #include "core/fxcodec/bmp/bmp_decoder.h"
 #include "core/fxcodec/bmp/fx_bmp.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/span.h"
@@ -70,7 +72,7 @@
   int PaletteChannelCount() const { return pal_type_ == PalType::kNew ? 4 : 3; }
 
   UnownedPtr<const CFX_BmpContext> const context_;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> out_row_buffer_;
+  DataVector<uint8_t> out_row_buffer_;
   std::vector<uint32_t> palette_;
   uint32_t header_offset_ = 0;
   uint32_t width_ = 0;
diff --git a/core/fxcodec/fax/faxmodule.cpp b/core/fxcodec/fax/faxmodule.cpp
index def5fdf..314ace5 100644
--- a/core/fxcodec/fax/faxmodule.cpp
+++ b/core/fxcodec/fax/faxmodule.cpp
@@ -6,14 +6,16 @@
 
 #include "core/fxcodec/fax/faxmodule.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <iterator>
 #include <memory>
-#include <vector>
 
 #include "build/build_config.h"
 #include "core/fxcodec/scanlinedecoder.h"
 #include "core/fxcrt/binary_buffer.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/stl_util.h"
 #include "core/fxge/calculate_pitch.h"
@@ -481,8 +483,8 @@
   const bool m_bEndOfLine;
   const bool m_bBlack;
   const pdfium::span<const uint8_t> m_SrcSpan;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_ScanlineBuf;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_RefBuf;
+  DataVector<uint8_t> m_ScanlineBuf;
+  DataVector<uint8_t> m_RefBuf;
 };
 
 FaxDecoder::FaxDecoder(pdfium::span<const uint8_t> src_span,
@@ -616,7 +618,7 @@
                            uint8_t* dest_buf) {
   DCHECK(pitch != 0);
 
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> ref_buf(pitch, 0xff);
+  DataVector<uint8_t> ref_buf(pitch, 0xff);
   int bitpos = starting_bitpos;
   for (int iRow = 0; iRow < height; ++iRow) {
     uint8_t* line_buf = dest_buf + iRow * pitch;
@@ -689,8 +691,8 @@
   const int m_Pitch;
   const uint8_t* m_pSrcBuf;
   BinaryBuffer m_DestBuf;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_RefLine;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_LineBuf;
+  DataVector<uint8_t> m_RefLine;
+  DataVector<uint8_t> m_LineBuf;
 };
 
 FaxEncoder::FaxEncoder(const uint8_t* src_buf, int width, int height, int pitch)
diff --git a/core/fxcodec/flate/flatemodule.cpp b/core/fxcodec/flate/flatemodule.cpp
index 1c5f4de..a97c4be 100644
--- a/core/fxcodec/flate/flatemodule.cpp
+++ b/core/fxcodec/flate/flatemodule.cpp
@@ -6,6 +6,7 @@
 
 #include "core/fxcodec/flate/flatemodule.h"
 
+#include <stdint.h>
 #include <string.h>
 
 #include <algorithm>
@@ -15,6 +16,7 @@
 #include <vector>
 
 #include "core/fxcodec/scanlinedecoder.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_safe_types.h"
@@ -616,7 +618,7 @@
  protected:
   std::unique_ptr<z_stream, FlateDeleter> m_pFlate;
   const pdfium::span<const uint8_t> m_SrcBuf;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_Scanline;
+  DataVector<uint8_t> m_Scanline;
 };
 
 FlateScanlineDecoder::FlateScanlineDecoder(pdfium::span<const uint8_t> src_span,
@@ -684,9 +686,9 @@
   int m_Columns = 0;
   uint32_t m_PredictPitch = 0;
   size_t m_LeftOver = 0;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_LastLine;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_PredictBuffer;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_PredictRaw;
+  DataVector<uint8_t> m_LastLine;
+  DataVector<uint8_t> m_PredictBuffer;
+  DataVector<uint8_t> m_PredictRaw;
 };
 
 FlatePredictorScanlineDecoder::FlatePredictorScanlineDecoder(
diff --git a/core/fxcodec/gif/cfx_gif.h b/core/fxcodec/gif/cfx_gif.h
index 97a7422..0a7fc5a 100644
--- a/core/fxcodec/gif/cfx_gif.h
+++ b/core/fxcodec/gif/cfx_gif.h
@@ -7,10 +7,12 @@
 #ifndef CORE_FXCODEC_GIF_CFX_GIF_H_
 #define CORE_FXCODEC_GIF_CFX_GIF_H_
 
+#include <stdint.h>
+
 #include <memory>
 #include <vector>
 
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 
 extern const char kGifSignature87[];
 extern const char kGifSignature89[];
@@ -115,7 +117,7 @@
 
   std::unique_ptr<CFX_GifGraphicControlExtension> image_GCE;
   std::vector<CFX_GifPalette> local_palettes;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> row_buffer;
+  DataVector<uint8_t> row_buffer;
   CFX_GifImageInfo image_info;
   uint8_t local_palette_exp;
   uint8_t code_exp;
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp
index 2a50d71..fe8d072 100644
--- a/core/fxcodec/gif/cfx_gifcontext.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext.cpp
@@ -6,11 +6,14 @@
 
 #include "core/fxcodec/gif/cfx_gifcontext.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <iterator>
 #include <utility>
 
 #include "core/fxcodec/cfx_codec_memory.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/stl_util.h"
 
@@ -210,7 +213,7 @@
   }
 
   uint8_t img_data_size;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> img_data;
+  DataVector<uint8_t> img_data;
   size_t read_marker = input_buffer_->GetPosition();
 
   // TODO(crbug.com/pdfium/1793): This logic can be simplified a lot, but it
diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
index f9de186..66cc760 100644
--- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
@@ -4,9 +4,12 @@
 
 #include "core/fxcodec/gif/cfx_gifcontext.h"
 
+#include <stdint.h>
+
 #include <utility>
 
 #include "core/fxcodec/cfx_codec_memory.h"
+#include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace fxcodec {
@@ -46,7 +49,7 @@
 }
 
 TEST(CFX_GifContext, ReadAllOrNone) {
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> dest_buffer;
+  DataVector<uint8_t> dest_buffer;
   uint8_t src_buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04,
                           0x05, 0x06, 0x07, 0x08, 0x09};
   CFX_GifContextForTest context;
diff --git a/core/fxcodec/gif/lzw_decompressor.h b/core/fxcodec/gif/lzw_decompressor.h
index b99b473..1f52fc1 100644
--- a/core/fxcodec/gif/lzw_decompressor.h
+++ b/core/fxcodec/gif/lzw_decompressor.h
@@ -7,11 +7,12 @@
 #ifndef CORE_FXCODEC_GIF_LZW_DECOMPRESSOR_H_
 #define CORE_FXCODEC_GIF_LZW_DECOMPRESSOR_H_
 
+#include <stdint.h>
+
 #include <memory>
-#include <vector>
 
 #include "core/fxcodec/gif/cfx_gif.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 
 namespace fxcodec {
 
@@ -42,9 +43,7 @@
     return ExtractData(dest_buf, dest_size);
   }
 
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>>* DecompressedForTest() {
-    return &decompressed_;
-  }
+  DataVector<uint8_t>* DecompressedForTest() { return &decompressed_; }
   size_t* DecompressedNextForTest() { return &decompressed_next_; }
 
  private:
@@ -63,7 +62,7 @@
   const uint16_t code_end_;
   uint16_t code_next_ = 0;
   uint8_t code_first_ = 0;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> decompressed_;
+  DataVector<uint8_t> decompressed_;
   size_t decompressed_next_ = 0;
   uint16_t code_old_ = 0;
   const uint8_t* next_in_ = nullptr;
diff --git a/core/fxcodec/gif/lzw_decompressor_unittest.cpp b/core/fxcodec/gif/lzw_decompressor_unittest.cpp
index fafe796..02def3f 100644
--- a/core/fxcodec/gif/lzw_decompressor_unittest.cpp
+++ b/core/fxcodec/gif/lzw_decompressor_unittest.cpp
@@ -9,6 +9,7 @@
 
 #include <iterator>
 
+#include "core/fxcrt/data_vector.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -28,8 +29,7 @@
 
   // Check that 0 length extract does nothing
   {
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>>* decompressed =
-        decompressor->DecompressedForTest();
+    DataVector<uint8_t>* decompressed = decompressor->DecompressedForTest();
     *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     *(decompressor->DecompressedNextForTest()) = decompressed->size();
     uint8_t dest_buf[20];
@@ -46,8 +46,7 @@
 
   // Check that less than decompressed size only gets the expected number
   {
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>>* decompressed =
-        decompressor->DecompressedForTest();
+    DataVector<uint8_t>* decompressed = decompressor->DecompressedForTest();
     *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     *(decompressor->DecompressedNextForTest()) = decompressed->size();
     uint8_t dest_buf[20];
@@ -67,8 +66,7 @@
 
   // Check that greater than decompressed size depletes the decompressor
   {
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>>* decompressed =
-        decompressor->DecompressedForTest();
+    DataVector<uint8_t>* decompressed = decompressor->DecompressedForTest();
     *decompressed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     *(decompressor->DecompressedNextForTest()) = decompressed->size();
     uint8_t dest_buf[20];
diff --git a/core/fxcodec/icc/icc_transform.cpp b/core/fxcodec/icc/icc_transform.cpp
index 3762e38..ad5909b 100644
--- a/core/fxcodec/icc/icc_transform.cpp
+++ b/core/fxcodec/icc/icc_transform.cpp
@@ -6,11 +6,12 @@
 
 #include "core/fxcodec/icc/icc_transform.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <memory>
-#include <vector>
 
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 #include "third_party/base/cxx17_backports.h"
 #include "third_party/base/notreached.h"
 #include "third_party/base/numerics/safe_conversions.h"
@@ -121,14 +122,12 @@
   // places which set transform to verify that only `pSrcValues.size()`
   // components are used.
   if (m_bLab) {
-    std::vector<double, FxAllocAllocator<double>> inputs(
-        std::max<size_t>(pSrcValues.size(), 16));
+    DataVector<double> inputs(std::max<size_t>(pSrcValues.size(), 16));
     for (uint32_t i = 0; i < pSrcValues.size(); ++i)
       inputs[i] = pSrcValues[i];
     cmsDoTransform(m_hTransform, inputs.data(), output, 1);
   } else {
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>> inputs(
-        std::max<size_t>(pSrcValues.size(), 16));
+    DataVector<uint8_t> inputs(std::max<size_t>(pSrcValues.size(), 16));
     for (size_t i = 0; i < pSrcValues.size(); ++i) {
       inputs[i] =
           pdfium::clamp(static_cast<int>(pSrcValues[i] * 255.0f), 0, 255);
diff --git a/core/fxcodec/jpeg/jpegmodule.cpp b/core/fxcodec/jpeg/jpegmodule.cpp
index 3585478..343893a 100644
--- a/core/fxcodec/jpeg/jpegmodule.cpp
+++ b/core/fxcodec/jpeg/jpegmodule.cpp
@@ -7,17 +7,17 @@
 #include "core/fxcodec/jpeg/jpegmodule.h"
 
 #include <setjmp.h>
+#include <stdint.h>
 #include <string.h>
 
 #include <memory>
 #include <utility>
-#include <vector>
 
 #include "build/build_config.h"
 #include "core/fxcodec/cfx_codec_memory.h"
 #include "core/fxcodec/jpeg/jpeg_common.h"
 #include "core/fxcodec/scanlinedecoder.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxge/dib/cfx_dibbase.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -158,7 +158,7 @@
   jpeg_error_mgr m_Jerr;
   jpeg_source_mgr m_Src;
   pdfium::span<const uint8_t> m_SrcSpan;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_ScanlineBuf;
+  DataVector<uint8_t> m_ScanlineBuf;
   bool m_bInited = false;
   bool m_bStarted = false;
   bool m_bJpegTransform = false;
@@ -264,7 +264,7 @@
     return false;
 
   CalcPitch();
-  m_ScanlineBuf = std::vector<uint8_t, FxAllocAllocator<uint8_t>>(m_Pitch);
+  m_ScanlineBuf = DataVector<uint8_t>(m_Pitch);
   m_nComps = m_Cinfo.num_components;
   m_bpc = 8;
   m_bStarted = false;
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 2798531..9a445d7 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -12,12 +12,11 @@
 
 #include <memory>
 #include <utility>
-#include <vector>
 
 #include "core/fxcodec/fx_codec_def.h"
 #include "core/fxcodec/jpeg/jpegmodule.h"
 #include "core/fxcodec/progressive_decoder_iface.h"
-#include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxge/dib/cstretchengine.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -138,7 +137,7 @@
     }
 
     int m_ItemSize;
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_pWeightTables;
+    DataVector<uint8_t> m_pWeightTables;
   };
 
   class VertTable {
@@ -152,7 +151,7 @@
                                             pixel * m_ItemSize);
     }
     int m_ItemSize;
-    std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_pWeightTables;
+    DataVector<uint8_t> m_pWeightTables;
   };
 
 #ifdef PDF_ENABLE_XFA_BMP
@@ -222,8 +221,8 @@
   RetainPtr<IFX_SeekableReadStream> m_pFile;
   RetainPtr<CFX_DIBitmap> m_pDeviceBitmap;
   RetainPtr<CFX_CodecMemory> m_pCodecMemory;
-  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_DecodeBuf;
-  std::vector<FX_ARGB, FxAllocAllocator<FX_ARGB>> m_SrcPalette;
+  DataVector<uint8_t> m_DecodeBuf;
+  DataVector<FX_ARGB> m_SrcPalette;
   std::unique_ptr<ProgressiveDecoderIface::Context> m_pJpegContext;
 #ifdef PDF_ENABLE_XFA_BMP
   std::unique_ptr<ProgressiveDecoderIface::Context> m_pBmpContext;