BLT 2.3: Vector bug fix 
Author Message
 BLT 2.3: Vector bug fix

There is a bug in the function ResizeVector() which causes corruption
of the vector structure and whatever follows it in memory.  the
problem occurs when a large vecot is being replaced by a vector which
is small enough (ie < 64 doubles) to fit in the staticSpace buffer.

For example,
vector rx   x

for {set i 0} {$i < 1000} {incr i} {

    set rx(++end) $i


x set rx                ;# No problemo

x set { 0.0 }           ;# Core dump


This is caused by some code which tries to zero any unused elements in
the staticSpace array but does not use the size of the staticSpace
array - instead it is using the size of the potentially much larger
old array.

My fix is as follows in BltVector.c, function Resizevector()

/* Clear any unused trailing slots in the array */

#if 0

    if (newSize < vPtr->numValues) {

        memset( (char *)newArr + newSize, 0,
                sizeof(double) * (vPtr->numValues - newSize) );


    if (newArr == vPtr->staticSpace) {

        memset( (char *)newArr + (length * sizeof(double)), 0,
                sizeof(double) * (DEF_ARRAY_SIZE - length) );

The above seems to be OK in the simple tests I've made.  I believe the
problem only occurs with the staticSpace because either:

1) The old array is the same size as the new one so no blanking is re

2)  The old array was not big enough so calloc'd memory (ie zero'd) is
being used.

This is perhaps as assumption  for George to confirm   ?

Hope this helps
Julian H J Loaring

One more dried frog pill won't hurt, they're not at all {*filter*}ive

Sun, 09 Apr 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. BUG: BLT 2.3 needs prodding to see vectors

2. bug fix for BLT 2.1 vector handling

3. Blt 2.3: One Bug, One Feature, Two Solutions :)

4. Serious BLT 2.3 bug (long)

5. Mops 2.3 bug fixed

6. Blt bug : [ 651993 ] vectors inside namespace (2.4z)

7. BLT::vector problems (bug?)

8. BLT vector creation: creation time grows as number of vectors created grows

9. BLT 2.3

10. BLT 2.3 under AIX

11. BLT 2.3 for AIX

12. BLT 2.3 for Tcl/Tk 8.0


Powered by phpBB® Forum Software