Permalink
Browse files

Make UBSan happy in a few areas

  • Loading branch information...
1 parent 3d80c6b commit e7deaf90c9c8ca30116340419313af527fe90d78 @mhosken mhosken committed Mar 4, 2016
Showing with 26 additions and 25 deletions.
  1. +1 −1 src/Face.cpp
  2. +11 −11 src/GlyphFace.cpp
  3. +2 −1 src/Pass.cpp
  4. +10 −10 src/Slot.cpp
  5. +1 −1 src/inc/Face.h
  6. +1 −1 src/inc/GlyphFace.h
View
@@ -232,7 +232,7 @@ uint16 Face::findPseudo(uint32 uid) const
return (m_numSilf) ? m_silfs[0].findPseudo(uid) : 0;
}
-uint16 Face::getGlyphMetric(uint16 gid, uint8 metric) const
+int32 Face::getGlyphMetric(uint16 gid, uint8 metric) const
{
switch (metrics(metric))
{
View
@@ -29,20 +29,20 @@ of the License or (at your option) any later version.
using namespace graphite2;
-uint16 GlyphFace::getMetric(uint8 metric) const
+int32 GlyphFace::getMetric(uint8 metric) const
{
switch (metrics(metric))
{
- case kgmetLsb : return static_cast<uint16>(m_bbox.bl.x);
- case kgmetRsb : return static_cast<uint16>(m_advance.x - m_bbox.tr.x);
- case kgmetBbTop : return static_cast<uint16>(m_bbox.tr.y);
- case kgmetBbBottom : return static_cast<uint16>(m_bbox.bl.y);
- case kgmetBbLeft : return static_cast<uint16>(m_bbox.bl.x);
- case kgmetBbRight : return static_cast<uint16>(m_bbox.tr.x);
- case kgmetBbHeight : return static_cast<uint16>(m_bbox.tr.y - m_bbox.bl.y);
- case kgmetBbWidth : return static_cast<uint16>(m_bbox.tr.x - m_bbox.bl.x);
- case kgmetAdvWidth : return static_cast<uint16>(m_advance.x);
- case kgmetAdvHeight : return static_cast<uint16>(m_advance.y);
+ case kgmetLsb : return m_bbox.bl.x;
+ case kgmetRsb : return m_advance.x - m_bbox.tr.x;
+ case kgmetBbTop : return m_bbox.tr.y;
+ case kgmetBbBottom : return m_bbox.bl.y;
+ case kgmetBbLeft : return m_bbox.bl.x;
+ case kgmetBbRight : return m_bbox.tr.x;
+ case kgmetBbHeight : return m_bbox.tr.y - m_bbox.bl.y;
+ case kgmetBbWidth : return m_bbox.tr.x - m_bbox.bl.x;
+ case kgmetAdvWidth : return m_advance.x;
+ case kgmetAdvHeight : return m_advance.y;
default : return 0;
}
}
View
@@ -356,7 +356,8 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru
s->rules = begin;
s->rules_end = (end - begin <= FiniteStateMachine::MAX_RULES)? end :
begin + FiniteStateMachine::MAX_RULES;
- qsort(begin, end - begin, sizeof(RuleEntry), &cmpRuleEntry);
+ if (begin) // keep UBSan happy can't call qsort with null begin
+ qsort(begin, end - begin, sizeof(RuleEntry), &cmpRuleEntry);
}
return true;
View
@@ -165,25 +165,25 @@ int32 Slot::clusterMetric(const Segment *seg, uint8 metric, uint8 attrLevel, boo
switch (metrics(metric))
{
case kgmetLsb :
- return static_cast<uint32>(bbox.bl.x);
+ return bbox.bl.x;
case kgmetRsb :
- return static_cast<uint32>(res.x - bbox.tr.x);
+ return res.x - bbox.tr.x;
case kgmetBbTop :
- return static_cast<uint32>(bbox.tr.y);
+ return bbox.tr.y;
case kgmetBbBottom :
- return static_cast<uint32>(bbox.bl.y);
+ return bbox.bl.y;
case kgmetBbLeft :
- return static_cast<uint32>(bbox.bl.x);
+ return bbox.bl.x;
case kgmetBbRight :
- return static_cast<uint32>(bbox.tr.x);
+ return bbox.tr.x;
case kgmetBbWidth :
- return static_cast<uint32>(bbox.tr.x - bbox.bl.x);
+ return bbox.tr.x - bbox.bl.x;
case kgmetBbHeight :
- return static_cast<uint32>(bbox.tr.y - bbox.bl.y);
+ return bbox.tr.y - bbox.bl.y;
case kgmetAdvWidth :
- return static_cast<uint32>(res.x);
+ return res.x;
case kgmetAdvHeight :
- return static_cast<uint32>(res.y);
+ return res.y;
default :
return 0;
}
View
@@ -87,7 +87,7 @@ class Face
const FeatureRef * feature(uint16 index) const;
// Glyph related
- uint16 getGlyphMetric(uint16 gid, uint8 metric) const;
+ int32 getGlyphMetric(uint16 gid, uint8 metric) const;
uint16 findPseudo(uint32 uid) const;
// Errors
View
@@ -51,7 +51,7 @@ class GlyphFace
const Position & theAdvance() const;
const Rect & theBBox() const { return m_bbox; }
const sparse & attrs() const { return m_attrs; }
- uint16 getMetric(uint8 metric) const;
+ int32 getMetric(uint8 metric) const;
CLASS_NEW_DELETE;
private:

0 comments on commit e7deaf9

Please sign in to comment.