Remove const args and const_casts where not required.

Introduce const/non-const versions of method where required.
Part of the war on const_cast<>. Tidy one expression to use []
instead of .data().

Change-Id: I41e45669c79eee242ff2244c7dc3afcf6386a433
Reviewed-on: https://pdfium-review.googlesource.com/39852
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp
index c8f9013..f3a6263 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -21,14 +21,14 @@
 
 CPDF_ImageLoader::~CPDF_ImageLoader() {}
 
-bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
+bool CPDF_ImageLoader::Start(CPDF_ImageObject* pImage,
                              CPDF_PageRenderCache* pCache,
                              bool bStdCS,
                              uint32_t GroupFamily,
                              bool bLoadMask,
                              CPDF_RenderStatus* pRenderStatus) {
   m_pCache = pCache;
-  m_pImageObject = const_cast<CPDF_ImageObject*>(pImage);
+  m_pImageObject = pImage;
   bool ret;
   if (pCache) {
     ret = pCache->StartGetCachedBitmap(m_pImageObject->GetImage(), bStdCS,
diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h
index a4f313f..629609d 100644
--- a/core/fpdfapi/render/cpdf_imageloader.h
+++ b/core/fpdfapi/render/cpdf_imageloader.h
@@ -23,7 +23,7 @@
   CPDF_ImageLoader();
   ~CPDF_ImageLoader();
 
-  bool Start(const CPDF_ImageObject* pImage,
+  bool Start(CPDF_ImageObject* pImage,
              CPDF_PageRenderCache* pCache,
              bool bStdCS,
              uint32_t GroupFamily,
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index eb9bdf8..f4bfa01 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -70,8 +70,8 @@
 }
 
 void CCodec_BmpModule::Input(Context* pContext,
-                             const uint8_t* src_buf,
+                             uint8_t* src_buf,
                              uint32_t src_size) {
   auto* ctx = static_cast<CFX_BmpContext*>(pContext);
-  ctx->m_Bmp.SetInputBuffer(const_cast<uint8_t*>(src_buf), src_size);
+  ctx->m_Bmp.SetInputBuffer(src_buf, src_size);
 }
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h
index 9eef886..ca2340d 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.h
+++ b/core/fxcodec/codec/ccodec_bmpmodule.h
@@ -34,7 +34,7 @@
 
   std::unique_ptr<Context> Start(Delegate* pDelegate);
   FX_FILESIZE GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr);
-  void Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size);
+  void Input(Context* pContext, uint8_t* src_buf, uint32_t src_size);
   int32_t ReadHeader(Context* pContext,
                      int32_t* width,
                      int32_t* height,
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 9d3923a..ad9a356 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -206,10 +206,11 @@
   return true;
 }
 
-PixelWeight* CStretchEngine::CWeightTable::GetPixelWeight(int pixel) const {
+const PixelWeight* CStretchEngine::CWeightTable::GetPixelWeight(
+    int pixel) const {
   ASSERT(pixel >= m_DestMin);
-  return reinterpret_cast<PixelWeight*>(const_cast<uint8_t*>(
-      m_WeightTables.data() + (pixel - m_DestMin) * m_ItemSize));
+  return reinterpret_cast<const PixelWeight*>(
+      &m_WeightTables[(pixel - m_DestMin) * m_ItemSize]);
 }
 
 int* CStretchEngine::CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index fa298f5..c9f11d6 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -46,7 +46,13 @@
               int src_min,
               int src_max,
               int flags);
-    PixelWeight* GetPixelWeight(int pixel) const;
+
+    const PixelWeight* GetPixelWeight(int pixel) const;
+    PixelWeight* GetPixelWeight(int pixel) {
+      return const_cast<PixelWeight*>(
+          static_cast<const CWeightTable*>(this)->GetPixelWeight(pixel));
+    }
+
     int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
     size_t GetPixelWeightSize() const;
 
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
index f977194..fd3a61e 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
@@ -304,10 +304,8 @@
 CXFA_FMToken CXFA_FMLexer::AdvanceForNumber() {
   // This will set end to the character after the end of the number.
   int32_t used_length = 0;
-  if (m_cursor) {
-    FXSYS_wcstof(const_cast<wchar_t*>(m_cursor), m_end - m_cursor,
-                 &used_length);
-  }
+  if (m_cursor)
+    FXSYS_wcstof(m_cursor, m_end - m_cursor, &used_length);
 
   const wchar_t* end = m_cursor + used_length;
   if (used_length == 0 || !end || FXSYS_iswalpha(*end)) {