Avoid some two-arg make_span() calls via extern spans. Specifying an explicit length to make_span() should be treated as an unsafe operation. -- move arrays themselves into anonymous namespaces. Change-Id: I9f32dd25de20784f7061618a09221e0b5b3bd611 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/118150 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Thomas Sepez <tsepez@google.com> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp index 18a1970..13488fc 100644 --- a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp +++ b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp
@@ -6,9 +6,8 @@ #include "core/fpdfapi/cmaps/CNS1/cmaps_cns1.h" -#include <iterator> - namespace fxcmap { +namespace { const CMap kCNS1_cmaps[] = { {"B5pc-H", kB5pc_H_0, nullptr, 247, 0, CMap::Type::kRange, 0}, @@ -32,6 +31,8 @@ -1}, }; -const size_t kCNS1_cmaps_size = std::size(kCNS1_cmaps); +} // namespace + +const pdfium::span<const CMap> kCNS1_cmaps_span{kCNS1_cmaps}; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.h b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.h index 75b31cb..eac3f22 100644 --- a/core/fpdfapi/cmaps/CNS1/cmaps_cns1.h +++ b/core/fpdfapi/cmaps/CNS1/cmaps_cns1.h
@@ -7,10 +7,10 @@ #ifndef CORE_FPDFAPI_CMAPS_CNS1_CMAPS_CNS1_H_ #define CORE_FPDFAPI_CMAPS_CNS1_CMAPS_CNS1_H_ -#include <stddef.h> #include <stdint.h> #include "core/fpdfapi/cmaps/fpdf_cmaps.h" +#include "core/fxcrt/span.h" namespace fxcmap { @@ -30,8 +30,8 @@ extern const uint16_t kUniCNS_UCS2_V_3[]; extern const uint16_t kUniCNS_UTF16_H_0[]; extern const uint16_t kCNS1CID2Unicode_5[19088]; -extern const CMap kCNS1_cmaps[]; -extern const size_t kCNS1_cmaps_size; + +extern const pdfium::span<const CMap> kCNS1_cmaps_span; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp index facf123..bc23333 100644 --- a/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp +++ b/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp
@@ -6,9 +6,8 @@ #include "core/fpdfapi/cmaps/GB1/cmaps_gb1.h" -#include <iterator> - namespace fxcmap { +namespace { const CMap kGB1_cmaps[] = { {"GB-EUC-H", kGB_EUC_H_0, nullptr, 90, 0, CMap::Type::kRange, 0}, @@ -29,6 +28,8 @@ {"UniGB-UTF16-V", kUniGB_UCS2_V_4, nullptr, 24, 0, CMap::Type::kRange, -1}, }; -const size_t kGB1_cmaps_size = std::size(kGB1_cmaps); +} // namespace + +const pdfium::span<const CMap> kGB1_cmaps_span{kGB1_cmaps}; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/GB1/cmaps_gb1.h b/core/fpdfapi/cmaps/GB1/cmaps_gb1.h index a226266..61382e6 100644 --- a/core/fpdfapi/cmaps/GB1/cmaps_gb1.h +++ b/core/fpdfapi/cmaps/GB1/cmaps_gb1.h
@@ -7,10 +7,10 @@ #ifndef CORE_FPDFAPI_CMAPS_GB1_CMAPS_GB1_H_ #define CORE_FPDFAPI_CMAPS_GB1_CMAPS_GB1_H_ -#include <stddef.h> #include <stdint.h> #include "core/fpdfapi/cmaps/fpdf_cmaps.h" +#include "core/fxcrt/span.h" namespace fxcmap { @@ -28,8 +28,8 @@ extern const uint16_t kUniGB_UCS2_H_4[]; extern const uint16_t kUniGB_UCS2_V_4[]; extern const uint16_t kGB1CID2Unicode_5[30284]; -extern const CMap kGB1_cmaps[]; -extern const size_t kGB1_cmaps_size; + +extern const pdfium::span<const CMap> kGB1_cmaps_span; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp index 9475854..1624aad 100644 --- a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp +++ b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp
@@ -6,9 +6,8 @@ #include "core/fpdfapi/cmaps/Japan1/cmaps_japan1.h" -#include <iterator> - namespace fxcmap { +namespace { const CMap kJapan1_cmaps[] = { {"83pv-RKSJ-H", k83pv_RKSJ_H_1, nullptr, 222, 0, CMap::Type::kRange, 0}, @@ -39,6 +38,8 @@ -1}, }; -const size_t kJapan1_cmaps_size = std::size(kJapan1_cmaps); +} // namespace + +const pdfium::span<const CMap> kJapan1_cmaps_span{kJapan1_cmaps}; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.h b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.h index 45df22d..84f3855 100644 --- a/core/fpdfapi/cmaps/Japan1/cmaps_japan1.h +++ b/core/fpdfapi/cmaps/Japan1/cmaps_japan1.h
@@ -7,10 +7,10 @@ #ifndef CORE_FPDFAPI_CMAPS_JAPAN1_CMAPS_JAPAN1_H_ #define CORE_FPDFAPI_CMAPS_JAPAN1_CMAPS_JAPAN1_H_ -#include <stddef.h> #include <stdint.h> #include "core/fpdfapi/cmaps/fpdf_cmaps.h" +#include "core/fxcrt/span.h" namespace fxcmap { @@ -36,8 +36,8 @@ extern const uint16_t kUniJIS_UTF16_H_0_DWord[]; extern const uint16_t kUniJIS_UTF16_V_0[]; extern const uint16_t kJapan1CID2Unicode_4[15444]; -extern const CMap kJapan1_cmaps[]; -extern const size_t kJapan1_cmaps_size; + +extern const pdfium::span<const CMap> kJapan1_cmaps_span; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp index 2109e04..8311d55 100644 --- a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp +++ b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp
@@ -6,9 +6,8 @@ #include "core/fpdfapi/cmaps/Korea1/cmaps_korea1.h" -#include <iterator> - namespace fxcmap { +namespace { const CMap kKorea1_cmaps[] = { {"KSC-EUC-H", kKSC_EUC_H_0, nullptr, 467, 0, CMap::Type::kRange, 0}, @@ -27,6 +26,8 @@ {"UniKS-UTF16-V", kUniKS_UCS2_V_1, nullptr, 18, 0, CMap::Type::kRange, -1}, }; -const size_t kKorea1_cmaps_size = std::size(kKorea1_cmaps); +} // namespace + +const pdfium::span<const CMap> kKorea1_cmaps_span{kKorea1_cmaps}; } // namespace fxcmap
diff --git a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.h b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.h index f75ded9..a561eec 100644 --- a/core/fpdfapi/cmaps/Korea1/cmaps_korea1.h +++ b/core/fpdfapi/cmaps/Korea1/cmaps_korea1.h
@@ -7,10 +7,10 @@ #ifndef CORE_FPDFAPI_CMAPS_KOREA1_CMAPS_KOREA1_H_ #define CORE_FPDFAPI_CMAPS_KOREA1_CMAPS_KOREA1_H_ -#include <stddef.h> #include <stdint.h> #include "core/fpdfapi/cmaps/fpdf_cmaps.h" +#include "core/fxcrt/span.h" namespace fxcmap { @@ -25,8 +25,8 @@ extern const uint16_t kUniKS_UCS2_V_1[]; extern const uint16_t kUniKS_UTF16_H_0[]; extern const uint16_t kKorea1CID2Unicode_2[18352]; -extern const CMap kKorea1_cmaps[]; -extern const size_t kKorea1_cmaps_size; + +extern const pdfium::span<const CMap> kKorea1_cmaps_span; } // namespace fxcmap
diff --git a/core/fpdfapi/font/cpdf_fontglobals.cpp b/core/fpdfapi/font/cpdf_fontglobals.cpp index 2d70225..0f563d3 100644 --- a/core/fpdfapi/font/cpdf_fontglobals.cpp +++ b/core/fpdfapi/font/cpdf_fontglobals.cpp
@@ -89,28 +89,22 @@ } void CPDF_FontGlobals::LoadEmbeddedGB1CMaps() { - SetEmbeddedCharset(CIDSET_GB1, pdfium::make_span(fxcmap::kGB1_cmaps, - fxcmap::kGB1_cmaps_size)); + SetEmbeddedCharset(CIDSET_GB1, fxcmap::kGB1_cmaps_span); SetEmbeddedToUnicode(CIDSET_GB1, fxcmap::kGB1CID2Unicode_5); } void CPDF_FontGlobals::LoadEmbeddedCNS1CMaps() { - SetEmbeddedCharset(CIDSET_CNS1, pdfium::make_span(fxcmap::kCNS1_cmaps, - fxcmap::kCNS1_cmaps_size)); + SetEmbeddedCharset(CIDSET_CNS1, fxcmap::kCNS1_cmaps_span); SetEmbeddedToUnicode(CIDSET_CNS1, fxcmap::kCNS1CID2Unicode_5); } void CPDF_FontGlobals::LoadEmbeddedJapan1CMaps() { - SetEmbeddedCharset( - CIDSET_JAPAN1, - pdfium::make_span(fxcmap::kJapan1_cmaps, fxcmap::kJapan1_cmaps_size)); + SetEmbeddedCharset(CIDSET_JAPAN1, fxcmap::kJapan1_cmaps_span); SetEmbeddedToUnicode(CIDSET_JAPAN1, fxcmap::kJapan1CID2Unicode_4); } void CPDF_FontGlobals::LoadEmbeddedKorea1CMaps() { - SetEmbeddedCharset( - CIDSET_KOREA1, - pdfium::make_span(fxcmap::kKorea1_cmaps, fxcmap::kKorea1_cmaps_size)); + SetEmbeddedCharset(CIDSET_KOREA1, fxcmap::kKorea1_cmaps_span); SetEmbeddedToUnicode(CIDSET_KOREA1, fxcmap::kKorea1CID2Unicode_2); }