Permalink
Browse files

Fix some off by 1 errors

  • Loading branch information...
1 parent 3832e9e commit 92e0add6083b2e360e30854cbfceedecaac0d3ad @mhosken mhosken committed Mar 1, 2016
Showing with 5 additions and 3 deletions.
  1. +4 −2 src/GlyphCache.cpp
  2. +1 −1 src/TtfUtil.cpp
View
@@ -116,8 +116,10 @@ class GlyphCache::Loader
GlyphCache::GlyphCache(const Face & face, const uint32 face_options)
: _glyph_loader(new Loader(face, bool(face_options & gr_face_dumbRendering))),
- _glyphs(_glyph_loader && *_glyph_loader ? grzeroalloc<const GlyphFace *>(_glyph_loader->num_glyphs()) : 0),
- _boxes(_glyph_loader && _glyph_loader->has_boxes() ? grzeroalloc<GlyphBox *>(_glyph_loader->num_glyphs()) : 0),
+ _glyphs(_glyph_loader && *_glyph_loader && _glyph_loader->num_glyphs()
+ ? grzeroalloc<const GlyphFace *>(_glyph_loader->num_glyphs()) : 0),
+ _boxes(_glyph_loader && _glyph_loader->has_boxes() && _glyph_loader->num_glyphs()
+ ? grzeroalloc<GlyphBox *>(_glyph_loader->num_glyphs()) : 0),
_num_glyphs(_glyphs ? _glyph_loader->num_glyphs() : 0),
_num_attrs(_glyphs ? _glyph_loader->num_attrs() : 0),
_upem(_glyphs ? _glyph_loader->units_per_em() : 0)
View
@@ -1004,7 +1004,7 @@ gid16 CmapSubtable4Lookup(const void * pCmapSubtabel4, unsigned int nUnicodeId,
// Look up value in glyphIdArray
const ptrdiff_t offset = (nUnicodeId - chStart) + (idRangeOffset >> 1) +
(pMid - reinterpret_cast<const uint16 *>(pTable));
- if (offset * 2 >= be::swap<uint16>(pTable->length))
+ if (offset * 2 + 1 >= be::swap<uint16>(pTable->length))
return 0;
gid16 nGlyphId = be::peek<uint16>(reinterpret_cast<const uint16 *>(pTable)+offset);
// If this value is 0, return 0. Else add the idDelta

0 comments on commit 92e0add

Please sign in to comment.