Move try_set to sanitize context

This commit is contained in:
Behdad Esfahbod 2014-06-04 18:42:32 -04:00
parent 500737e8e1
commit 51f563579b
2 changed files with 11 additions and 13 deletions

View File

@ -266,6 +266,15 @@ struct hb_sanitize_context_t
return TRACE_RETURN (this->writable);
}
template <typename Type, typename ValueType>
inline bool try_set (Type *obj, const ValueType &v) {
if (this->may_edit (obj, obj->static_size)) {
obj->set (v);
return true;
}
return false;
}
mutable unsigned int debug_depth;
const char *start, *end;
bool writable;
@ -722,20 +731,9 @@ struct GenericOffsetTo : OffsetType
return TRACE_RETURN (likely (obj.sanitize (c, user_data)) || neuter (c));
}
inline bool try_set (hb_sanitize_context_t *c, const OffsetType &v) {
if (c->may_edit (this, this->static_size)) {
this->set (v);
return true;
}
return false;
}
/* Set the offset to Null */
inline bool neuter (hb_sanitize_context_t *c) {
if (c->may_edit (this, this->static_size)) {
this->set (0); /* 0 is Null offset */
return true;
}
return false;
return c->try_set (this, 0);
}
};
template <typename Base, typename OffsetType, typename Type>

View File

@ -519,7 +519,7 @@ struct Feature
/* Check that it did not overflow. */
new_offset.set (new_offset_int);
if (new_offset == new_offset_int &&
featureParams.try_set (c, new_offset) &&
c->try_set (&featureParams, new_offset) &&
!featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE))
return TRACE_RETURN (false);
}