Protect sets in-error from further modication
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 3 Jan 2013 05:02:59 +0000 (23:02 -0600)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 3 Jan 2013 05:02:59 +0000 (23:02 -0600)
Fixes test-set.c

src/hb-set-private.hh

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