| | 1 | // from Sean T Barrett - vector trash bug test case |
| | 2 | |
| | 3 | #include "tads.h" |
| | 4 | #include "t3.h" |
| | 5 | #include "vector.h" |
| | 6 | |
| | 7 | #define TEST_STRINGS // if you disable this, builds a vector of ints, |
| | 8 | // which doesn't memory trash |
| | 9 | |
| | 10 | #ifdef TEST_STRINGS |
| | 11 | #define VALUE(x) #@x |
| | 12 | #else |
| | 13 | #define VALUE(x) x |
| | 14 | #endif |
| | 15 | |
| | 16 | main(args) |
| | 17 | { |
| | 18 | local x = new Vector(1); // if you make this 3, it doesn't trash |
| | 19 | // (the vector will eventually have 3 elements) |
| | 20 | |
| | 21 | x.append(VALUE(1)); // append 1 or '1' |
| | 22 | x.append(VALUE(2)); // append 2 or '2' |
| | 23 | |
| | 24 | x[2] = x[2]; // this assignment doesn't trash x[1] or x[2] |
| | 25 | |
| | 26 | "<<x[1]>> <<x[2]>>\n"; |
| | 27 | |
| | 28 | x.append(VALUE(3)); // append 3 or '3' |
| | 29 | |
| | 30 | "<<x[1]>> <<x[2]>> <<x[3]>>\n"; |
| | 31 | |
| | 32 | x[3] = 3; // ERROR! this assignment trashes x[2] NOT x[3] |
| | 33 | // x[3] = x[3]; // this would trash too |
| | 34 | |
| | 35 | "<<x[1]>> <<x[2]>>\n"; // this line will fault on x[2] |
| | 36 | |
| | 37 | // convert it to a list and display it |
| | 38 | local y = x.toList(); |
| | 39 | "y = [<<y[1]>>, <<y[2]>>, <<y[3]>>]\n"; |
| | 40 | } |