Protect sets in-error from further modication

Fixes test-set.c
This commit is contained in:
Behdad Esfahbod 2013-01-02 23:02:59 -06:00
parent 8165f2765b
commit 7b1b720a8d
1 changed files with 13 additions and 0 deletions

View File

@ -146,6 +146,9 @@ struct hb_set_t
inline void fini (void) { inline void fini (void) {
} }
inline void clear (void) { inline void clear (void) {
if (unlikely (hb_object_is_inert (this)))
return;
in_error = false;
memset (elts, 0, sizeof elts); memset (elts, 0, sizeof elts);
} }
inline bool is_empty (void) const { inline bool is_empty (void) const {
@ -156,23 +159,27 @@ struct hb_set_t
} }
inline void add (hb_codepoint_t g) inline void add (hb_codepoint_t g)
{ {
if (unlikely (in_error)) return;
if (unlikely (g == SENTINEL)) return; if (unlikely (g == SENTINEL)) return;
if (unlikely (g > MAX_G)) return; if (unlikely (g > MAX_G)) return;
elt (g) |= mask (g); elt (g) |= mask (g);
} }
inline void add_range (hb_codepoint_t a, hb_codepoint_t b) inline void add_range (hb_codepoint_t a, hb_codepoint_t b)
{ {
if (unlikely (in_error)) return;
/* TODO Speedup */ /* TODO Speedup */
for (unsigned int i = a; i < b + 1; i++) for (unsigned int i = a; i < b + 1; i++)
add (i); add (i);
} }
inline void del (hb_codepoint_t g) inline void del (hb_codepoint_t g)
{ {
if (unlikely (in_error)) return;
if (unlikely (g > MAX_G)) return; if (unlikely (g > MAX_G)) return;
elt (g) &= ~mask (g); elt (g) &= ~mask (g);
} }
inline void del_range (hb_codepoint_t a, hb_codepoint_t b) inline void del_range (hb_codepoint_t a, hb_codepoint_t b)
{ {
if (unlikely (in_error)) return;
/* TODO Speedup */ /* TODO Speedup */
for (unsigned int i = a; i < b + 1; i++) for (unsigned int i = a; i < b + 1; i++)
del (i); del (i);
@ -202,31 +209,37 @@ struct hb_set_t
} }
inline void set (const hb_set_t *other) inline void set (const hb_set_t *other)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] = other->elts[i]; elts[i] = other->elts[i];
} }
inline void union_ (const hb_set_t *other) inline void union_ (const hb_set_t *other)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] |= other->elts[i]; elts[i] |= other->elts[i];
} }
inline void intersect (const hb_set_t *other) inline void intersect (const hb_set_t *other)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] &= other->elts[i]; elts[i] &= other->elts[i];
} }
inline void subtract (const hb_set_t *other) inline void subtract (const hb_set_t *other)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] &= ~other->elts[i]; elts[i] &= ~other->elts[i];
} }
inline void symmetric_difference (const hb_set_t *other) inline void symmetric_difference (const hb_set_t *other)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] ^= other->elts[i]; elts[i] ^= other->elts[i];
} }
inline void invert (void) inline void invert (void)
{ {
if (unlikely (in_error)) return;
for (unsigned int i = 0; i < ELTS; i++) for (unsigned int i = 0; i < ELTS; i++)
elts[i] = ~elts[i]; elts[i] = ~elts[i];
} }