Make charcode variables unsigned in various places in font code.
Values are never negative, and sometimes only in the range [0, 256).
Change-Id: I87668503b67fbcdef001df71c838ca6b3911b4d8
Reviewed-on: https://pdfium-review.googlesource.com/c/48152
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 03ade0e..7867a79 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -349,8 +349,8 @@
const char* CPDF_Font::GetAdobeCharName(
int iBaseEncoding,
const std::vector<ByteString>& charnames,
- int charcode) {
- if (charcode < 0 || charcode >= 256)
+ uint32_t charcode) {
+ if (charcode >= 256)
return nullptr;
if (!charnames.empty() && !charnames[charcode].IsEmpty())
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index 3fd9489..5ffbceb 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -95,7 +95,7 @@
static bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
static const char* GetAdobeCharName(int iBaseEncoding,
const std::vector<ByteString>& charnames,
- int charcode);
+ uint32_t charcode);
virtual bool Load() = 0;
diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp
index 16978f1..d84e857 100644
--- a/core/fpdfapi/font/cpdf_truetypefont.cpp
+++ b/core/fpdfapi/font/cpdf_truetypefont.cpp
@@ -96,7 +96,7 @@
}
}
bool bToUnicode = m_pFontDict->KeyExist("ToUnicode");
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const char* name = GetAdobeCharName(baseEncoding, m_CharNames, charcode);
if (!name) {
m_GlyphIndex[charcode] =
@@ -163,7 +163,7 @@
}
if (bFound) {
if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(baseEncoding, m_CharNames, charcode);
if (name)
@@ -194,7 +194,7 @@
if (FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0) {
bool bFound = false;
const uint16_t* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
if (m_pFontFile) {
m_Encoding.m_Unicodes[charcode] = charcode;
} else {
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 7fb7ce6..410dbde 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -138,7 +138,7 @@
if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) {
if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) {
bool bGotOne = false;
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
for (int j = 0; j < 4; j++) {
uint16_t unicode = prefix[j] * 256 + charcode;
@@ -165,7 +165,7 @@
if (m_BaseEncoding == 0)
m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
if (!name)
@@ -195,7 +195,7 @@
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
if (bCoreText) {
if (FontStyleIsSymbolic(m_Flags)) {
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
if (name) {
@@ -227,7 +227,7 @@
bool bUnicode =
FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0;
- for (int charcode = 0; charcode < 256; charcode++) {
+ for (uint32_t charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
if (!name)
@@ -320,7 +320,7 @@
}
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
-void CPDF_Type1Font::SetExtGID(const char* name, int charcode) {
+void CPDF_Type1Font::SetExtGID(const char* name, uint32_t charcode) {
CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
m_ExtGID[charcode] =
@@ -329,7 +329,7 @@
CFRelease(name_ct);
}
-void CPDF_Type1Font::CalcExtGID(int charcode) {
+void CPDF_Type1Font::CalcExtGID(uint32_t charcode) {
char name_glyph[256];
FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], name_glyph,
256);
diff --git a/core/fpdfapi/font/cpdf_type1font.h b/core/fpdfapi/font/cpdf_type1font.h
index 0fdfa80..86a9812 100644
--- a/core/fpdfapi/font/cpdf_type1font.h
+++ b/core/fpdfapi/font/cpdf_type1font.h
@@ -33,8 +33,8 @@
void LoadGlyphMap() override;
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
- void SetExtGID(const char* name, int charcode);
- void CalcExtGID(int charcode);
+ void SetExtGID(const char* name, uint32_t charcode);
+ void CalcExtGID(uint32_t charcode);
uint16_t m_ExtGID[256];
#endif