Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP *bug*
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00955565
Message ID:
00955705
Views:
12
>What would be the point in VFP allowing this:
>
>
>dimension TestArray(2)
>TestArray(1) = "ELEMENT A"
>TestArray(2) = "ELEMENT B"
>
>? TestArray(1, 1)
>? TestArray(2, 1)
>? TestArray(3, 1)
>? TestArray(4, 1)
>
>
>It prints:
>
>
>ELEMENT A
>ELEMENT A
>ELEMENT A
>ELEMENT A
>
>
>I just ran across it while testing and debugging some code and I was getting strange results. It took me a minute or two to realize I was refering to a one dimensional array with two dimensional syntax because in this code I'm also working with some two dimensional arrays, but I was a little surprised when I found that I could refer to a row that doesn't exist (similar to the sample above). Arrrggh. This would cause an error in other languages.
>
>Russell Campbell

For this example the bug it is not evident,
but a bug ( serious ) exists here.

VFP's array is a linear 1 dimension data structure, with 3 coefficients
- AL_ELEMENTS, AL_SUBSCRIPT1 ( i call R ), AL_SUBSCRIPT3 ( i call C ) ( see _Alen() ) where AL_ELEMENTS=AL_SUBSCRIPT1*AL_SUBSCRIPT3

If you declare:
dimension TestArray(R,C)
when you execute a TestArray(x,y)
VFP do:
- compute the 1 dimension subscript with this expression:
subscript = 1 + (x-1)*C+ (y-1)
- then check for a array subscript overflow
IF subscript > AL_ELEMENTS
  * FIRE A ERROR
ENDIF
THE BUG:
WHEN THE VFPT DEVELOPER implement this,
it have do a guess:
I can skip the check for x>AL_SUBSCRIPT1
because the subscript > AL_ELEMENTS it is sufficient
in order to cover this violation

BUT, it have do a error
IT DON'T CHECK FOR y > AL_SUBSCRIPT3 !!

Repro:
CLEAR
* dimension TestArray(R,C)
dimension TestArray(6) && =  TestArray(6,0)  1 row: zero columns !!!
TestArray(1) = "ELEMENT 1"
TestArray(2) = "ELEMENT 2"
TestArray(3) = "ELEMENT 3"
TestArray(4) = "ELEMENT 4"
TestArray(5) = "ELEMENT 5"
TestArray(6) = "ELEMENT 6"

* TestArray(x, y) = TestArray(1 + (x-1)*C+ (y-1)) = TestArray( (x-1)*C+ y )
? TestArray(1, 1),TestArray(1+ (1-1)*0+ (1-1))
? TestArray(2, 1),TestArray(1+ (2-1)*0+ (1-1))
? TestArray(3, 1),TestArray(1+ (3-1)*0+ (1-1))
? TestArray(4, 1),TestArray(1+ (4-1)*0+ (1-1))
? '*'

dimension TestArray(6,1)	&& this change the array coefficient, but not touch the array's data

? TestArray(1, 1),TestArray(1+(1-1)*1+ (1-1))
? TestArray(2, 1),TestArray(1+(2-1)*1+ (1-1))
? TestArray(3, 1),TestArray(1+(3-1)*1+ (1-1))

? '*'
dimension TestArray(3,2)	&& this change the array coefficient, but not touch the array's data

? TestArray(1, 1),TestArray(1+(1-1)*2+ (1-1))
? TestArray(2, 2),TestArray(1+(2-1)*2+ (2-1))
? TestArray(3, 2),TestArray(1+(3-1)*2+ (2-1))
? TestArray(2, 3),TestArray(1+(2-1)*2+ (3-1)) &&  <== !!!! this is a bug

* another bug: next don't fire a error and use only the first value
? TestArray(3, 2, 999, 500, 70000, 9000) && parser stop analisy after the first subscript
Fabio
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform