[sanitize] Protect against an underflow

This commit is contained in:
Behdad Esfahbod 2023-03-02 11:35:42 -07:00
parent 08784baf10
commit fe83736e26
1 changed files with 8 additions and 4 deletions

View File

@ -229,11 +229,15 @@ struct hb_sanitize_context_t :
unsigned get_edit_count () { return edit_count; } unsigned get_edit_count () { return edit_count; }
bool check_ops(int count) bool check_ops(unsigned count)
{ {
// Manually decrements the ops counter. Used when the automatic op /* Avoid underflow */
// counting needs adjustment. if (unlikely (this->max_ops < 0 || count >= (unsigned) this->max_ops))
return (this->max_ops -= count) > 0; {
this->max_ops = -1;
return false;
}
return (this->max_ops -= (int) count) > 0;
} }
bool check_range (const void *base, bool check_range (const void *base,