Author: sewardj
Date: 2007-10-05 11:08:46 +0100 (Fri, 05 Oct 2007)
New Revision: 6957

Log:
Common up and strengthen checks which ensure that a given lockset is a
member of the correct lockset-universe.

Modified:
   branches/THRCHECK/thrcheck/tc_wordset.c


Modified: branches/THRCHECK/thrcheck/tc_wordset.c
===================================================================
--- branches/THRCHECK/thrcheck/tc_wordset.c     2007-10-05 10:07:38 UTC (rev 
6956)
+++ branches/THRCHECK/thrcheck/tc_wordset.c     2007-10-05 10:08:46 UTC (rev 
6957)
@@ -231,14 +231,23 @@
    wsu->ix2vec_size = new_sz;
 }
 
-/* Index into a WordSetU, doing the obvious range check. */
+/* Index into a WordSetU, doing the obvious range check.  Failure of
+   the assertions marked XXX and YYY is an indication of passing the
+   wrong WordSetU* in the public API of this module. */
 static WordVec* do_ix2vec ( WordSetU* wsu, WordSet ws )
 {
+   WordVec* wv;
    tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size);
    if (wsu->ix2vec_used > 0)
       tl_assert(wsu->ix2vec);
+   /* If this assertion fails, it may mean you supplied a 'ws'
+      that does not come from the 'wsu' universe. */
    tl_assert(ws < wsu->ix2vec_used);
-   return wsu->ix2vec[ws];
+   wv = wsu->ix2vec[ws];
+   /* Make absolutely sure that 'ws' is a member of 'wsu'. */
+   tl_assert(wv);
+   tl_assert(wv->owner == wsu);
+   return wv;
 }
 
 /* See if wv is contained within wsu.  If so, deallocate wv and return
@@ -321,7 +330,6 @@
 {
    WordVec* wv = do_ix2vec( wsu, ws );
    wsu->n_isEmpty++;
-   tl_assert(wv->owner == wsu);
    if (wv->size == 0) {
       tl_assert(ws == wsu->empty);
       return True;
@@ -337,7 +345,6 @@
    tl_assert(wsu);
    wsu->n_isSingleton++;
    wv = do_ix2vec( wsu, ws );
-   tl_assert(wv->owner == wsu);
    return (Bool)(wv->size == 1 && wv->words[0] == w);
 }
 
@@ -346,7 +353,6 @@
    WordVec* wv;
    tl_assert(wsu);
    wv = do_ix2vec( wsu, ws );
-   tl_assert(wv->owner == wsu);
    tl_assert(wv->size >= 0);
    return wv->size;
 }
@@ -357,7 +363,6 @@
    tl_assert(wsu);
    wsu->n_anyElementOf++;
    wv = do_ix2vec( wsu, ws );
-   tl_assert(wv->owner == wsu);
    tl_assert(wv->size >= 1);
    return wv->words[0];
 }
@@ -374,7 +379,6 @@
    WordVec* wv;
    tl_assert(wsu);
    wv = do_ix2vec( wsu, ws );
-   tl_assert(wv->owner == wsu);
    tl_assert(wv->size >= 0);
    *nWords = wv->size;
    *words  = wv->words;
@@ -396,6 +400,7 @@
    if (ws < 0 || ws >= wsu->ix2vec_used)
       return False;
    wv = do_ix2vec( wsu, ws );
+   /* can never happen .. do_ix2vec will assert instead.  Oh well. */
    if (wv->owner != wsu) return False;
    if (wv->size < 0) return False;
    if (wv->size > 0) {
@@ -458,7 +463,6 @@
    WordVec* wv;
    tl_assert(wsu);
    wv = do_ix2vec( wsu, ws );
-   tl_assert(wv);
    VG_(printf)("{");
    for (i = 0; i < wv->size; i++) {
       VG_(printf)("%p", (void*)wv->words[i]);
@@ -587,8 +591,6 @@
    WordVec* wv1 = do_ix2vec( wsu, ws1 );
    WordVec* wv2 = do_ix2vec( wsu, ws2 );
    wsu->n_union++;
-   tl_assert(wv1->owner == wsu);
-   tl_assert(wv2->owner == wsu);
    sz = 0;
    i1 = i2 = 0;
    while (1) {
@@ -678,8 +680,6 @@
 
    wv1 = do_ix2vec( wsu, ws1 );
    wv2 = do_ix2vec( wsu, ws2 );
-   tl_assert(wv1->owner == wsu);
-   tl_assert(wv2->owner == wsu);
    sz = 0;
    i1 = i2 = 0;
    while (1) {
@@ -749,8 +749,6 @@
 
    wv1 = do_ix2vec( wsu, ws1 );
    wv2 = do_ix2vec( wsu, ws2 );
-   tl_assert(wv1->owner == wsu);
-   tl_assert(wv2->owner == wsu);
    sz = 0;
    i1 = i2 = 0;
    while (1) {


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Valgrind-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to