Commit 4c82e10045762bec77d02a545872e79125f89963

sammy 2010-05-23T20:46:45

Fix improper bound checks in FTGlyphContainer.

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;