Update of /cvsroot/monetdb/MonetDB/src/gdk
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6953/src/gdk

Modified Files:
        gdk.mx gdk_bat.mx gdk_batop.mx gdk_rangejoin.mx 
Log Message:
bug fix in BATcopy, it didn't set the capacity correct, leading to out of
bound writes. Propcheck now checks for incorrect set capacities.
This found a similar problem in BATslice, which is also corrected now.

bandjoin now uses the new bound bit arguments


Index: gdk.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk.mx,v
retrieving revision 1.245
retrieving revision 1.246
diff -u -d -r1.245 -r1.246
--- gdk.mx      30 Dec 2007 18:04:00 -0000      1.245
+++ gdk.mx      4 Jan 2008 18:02:32 -0000       1.246
@@ -1374,6 +1374,8 @@
 @item size_t
 @tab BATcount (BAT *b)
 @item void
[EMAIL PROTECTED] BATsetcapacity (BAT *b, size_t cnt)
[EMAIL PROTECTED] void
 @tab BATsetcount (BAT *b, size_t cnt)
 @item size_t
 @tab BATbuncount (BAT *b)
@@ -1439,6 +1441,7 @@
 gdk_export str BATrename(BAT *b, str nme);
 gdk_export size_t BATcount(BAT *b);
 gdk_export size_t BATcount_no_nil(BAT *b);
+gdk_export void BATsetcapacity(BAT *b, size_t cnt);
 gdk_export void BATsetcount(BAT *b, size_t cnt);
 gdk_export size_t BATbuncount(BAT *b);
 gdk_export size_t BATguess(BAT *b);

Index: gdk_bat.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_bat.mx,v
retrieving revision 1.183
retrieving revision 1.184
diff -u -d -r1.183 -r1.184
--- gdk_bat.mx  23 Dec 2007 22:21:51 -0000      1.183
+++ gdk_bat.mx  4 Jan 2008 18:02:32 -0000       1.184
@@ -700,8 +700,8 @@
 
                        if (isVIEWCOMBINE(b) || /* oops, mirror view! */
                            /* reduced slice view: do not copy too much garbage 
*/
-                           (hp != 0 && BATcount(BBP_cache(hp)) > cnt + cnt) ||
-                           (tp != 0 && BATcount(BBP_cache(tp)) > cnt + cnt))
+                           (hp != 0 && BATcapacity(BBP_cache(hp)) > cnt + cnt) 
||
+                           (tp != 0 && BATcapacity(BBP_cache(tp)) > cnt + cnt))
                                bunstocopy = cnt;
                }
 
@@ -720,6 +720,7 @@
                        int tremap = remap && BATtrestricted(b) != BAT_WRITE && 
tt != TYPE_void;
                        int hvremap = hremap && ATOMstorage(ht) == TYPE_str && 
!GDK_ELIMDOUBLES(b->H->vheap);
                        int tvremap = tremap && ATOMstorage(tt) == TYPE_str && 
!GDK_ELIMDOUBLES(b->T->vheap);
+                       size_t hcap = 0, tcap = 0;
                        Heap bhhp, bthp, hhp, thp;
                        memset(&bhhp, 0, sizeof(Heap));
                        memset(&bthp, 0, sizeof(Heap));
@@ -747,10 +748,15 @@
                        if (bn->T->vheap)
                                heapfree(bn->T->vheap, &thp);
 
-                       if (bn->htype)
-                               bn->U->capacity = 
bn->H->heap.size>>bn->H->shift;
-                       else if (bn->ttype)
-                               bn->U->capacity = 
bn->T->heap.size>>bn->T->shift;
+                       /* make sure we use the correct capacity */
+                       hcap = (bn->htype)?bn->H->heap.size>>bn->H->shift:0;
+                       tcap = (bn->ttype)?bn->T->heap.size>>bn->T->shift:0;
+                       if (hcap && tcap)
+                               bn->U->capacity = MIN(hcap,tcap);
+                       else if (hcap)
+                               bn->U->capacity = hcap;
+                       else
+                               bn->U->capacity = tcap;
 
 
                        /* first/inserted must point equally far into the heap 
as in the source */
@@ -1966,6 +1972,13 @@
 }
 
 void
+BATsetcapacity(BAT *b, size_t cnt)
+{
+       b->U->capacity = cnt;                   
+       assert(b->batCount <= cnt);
+}
+
+void
 BATsetcount(BAT *b, size_t cnt)
 {
        b->batCount = cnt;                      
@@ -2796,7 +2809,9 @@
                     ((b->H->heap.size > b->H->heap.maxsize) << 13) |
                     (((b->H->heap.free > b->H->heap.size) & (b->htype != 
TYPE_void)) |
                      ((b->T->heap.free > b->T->heap.size) & (b->ttype != 
TYPE_void))) << 14 | 
-                    (((xx - yy) != BATcount(b)) << 15);
+                    (((xx - yy) != BATcount(b)) << 15) |
+                       ((b->H->type && (b->U->capacity > 
(b->H->heap.size>>b->H->shift))) |
+                       (b->T->type && (b->U->capacity > 
(b->T->heap.size>>b->T->shift)))) << 16;
 
                if (zz) {
                        GDKfatal("BATpropcheck: BAT %s(%d) has inconsistent 
descriptor %d (%o)\n", BATgetId(b), b->batCacheid, zz, zz);

Index: gdk_batop.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_batop.mx,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- gdk_batop.mx        23 Dec 2007 20:54:05 -0000      1.147
+++ gdk_batop.mx        4 Jan 2008 18:02:32 -0000       1.148
@@ -542,6 +542,7 @@
                bn->H->heap.maxsize = bn->H->heap.size = headsize(bn, cnt);
                bn->T->heap.maxsize = bn->T->heap.size = tailsize(bn, cnt);
                BATsetcount(bn, cnt);
+               BATsetcapacity(bn, cnt);
 @-
 We have to do it: create a new BAT and put everything into it.
 @c

Index: gdk_rangejoin.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB/src/gdk/gdk_rangejoin.mx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gdk_rangejoin.mx    30 Dec 2007 18:04:00 -0000      1.2
+++ gdk_rangejoin.mx    4 Jan 2008 18:02:32 -0000       1.3
@@ -146,8 +146,6 @@
        ERRORcheck(l == NULL, "BATbandjoin: invalid left operand");
        ERRORcheck(r == NULL, "BATbandjoin: invalid right operand");
        ERRORcheck(TYPEerror(l->ttype, r->htype), "BATbandjoin: type 
conflict\n");
-       (void)li;
-       (void)hi;
        bn = BATnew(BAThtype(l), BAThtype(r), MIN(BATcount(l), BATcount(r)));
        if (bn == NULL) 
                return bn;
@@ -186,7 +184,7 @@
 Choice point is to determine the status of the NULL values in the final
 result.
 @{
[EMAIL PROTECTED] bandjoin
[EMAIL PROTECTED] bandjoin_
 {
        BATiter li = bat_iterator(l);
        BATiter ri = bat_iterator(r);
@@ -199,8 +197,8 @@
                x1 = (@1 *) BUNtloc(li, p);
                BATloop(r, v, w) {
                        x2 = (@1 *) BUNhloc(ri, v);
-                       if ((*x1 >= *x2 -  *(@1 *) c1) &&
-                           (*x1 <= *x2 + *(@1 *) c2)) {
+                       if ((*x1 @2 *x2 -  *(@1 *) c1) &&
+                           (*x1 @3 *x2 + *(@1 *) c2)) {
                                if (BUNfastins(bn, BUNhead(li, p), BUNtail(ri, 
v)) == NULL) {
                                        BBPreclaim(bn);
                                        return NULL;
@@ -208,7 +206,17 @@
                        }
                }
        }
-       break;
 }
+
[EMAIL PROTECTED] bandjoin
+if (li && hi)
+       @:bandjoin_(@1,>=,<=)
+else if (li && !hi)
+       @:bandjoin_(@1,>=,<)
+else if (!li && hi)
+       @:bandjoin_(@1,>,<=)
+else
+       @:bandjoin_(@1,>,<)
+break;
 @
 @}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to