Fix improper bound checks in FTGlyphContainer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/src/FTGlyphContainer.cpp b/src/FTGlyphContainer.cpp
index 88a24e7..8ca36c9 100644
--- a/src/FTGlyphContainer.cpp
+++ b/src/FTGlyphContainer.cpp
@@ -79,10 +79,8 @@ void FTGlyphContainer::Add(FTGlyph* tempGlyph, const unsigned int charCode)
const FTGlyph* const FTGlyphContainer::Glyph(const unsigned int charCode) const
{
unsigned int index = charMap->GlyphListIndex(charCode);
- if (index > glyphs.size()) {
- return NULL;
- }
- return glyphs[index];
+
+ return (index < glyphs.size()) ? glyphs[index] : NULL;
}
@@ -98,9 +96,9 @@ float FTGlyphContainer::Advance(const unsigned int charCode,
unsigned int left = charMap->FontIndex(charCode);
unsigned int right = charMap->FontIndex(nextCharCode);
const FTGlyph *glyph = Glyph(charCode);
- if (!glyph) {
+
+ if (!glyph)
return 0.0f;
- }
return face->KernAdvance(left, right).Xf() + glyph->Advance();
}
@@ -118,9 +116,8 @@ FTPoint FTGlyphContainer::Render(const unsigned int charCode,
if(!face->Error())
{
unsigned int index = charMap->GlyphListIndex(charCode);
- if (index <= glyphs.size()) {
+ if (index < glyphs.size())
kernAdvance += glyphs[index]->Render(penPosition, renderMode);
- }
}
return kernAdvance;