---------------------------------------------------------------
[BUG/PRB.] VFP 9.0 FIX - ADIR() FUNCTION
January 2026
---------------------------------------------------------------
CCB
1. BUG:
In vfp9 (and vfp6, vfp7, vfp8), the ADIR() function can only return file size information when the file size < 2 GB,
now the ADIR() function can return file size information when the file size > 2 GB.
There is a test program from Mr. Luiz Carlos:
*PROC testadirfunction
SET STEP OFF
SET ECHO OFF
SET DEBUG OFF
SET ESCAPE OFF
SET TALK OFF
SET SAFETY OFF
PRIVATE m.q_file
m.q_file="TMP"+REPL("1234567890",5)+".TMP"
PRIVATE m.q_hand
m.q_hand=FCREATE(m.q_file)
=FCHSIZE(m.q_hand,2147483647) && 2^31-1
=FCLOSE(m.q_hand)
=ADIR(afiles,m.q_file)
DISPLAY MEMO LIKE afiles
WAIT
? afiles(1,2) && size with very strange zeros
? INT(afiles(1,2)) && returns wrong size
? 2147484160 = afiles(1,2) && the Fox prints .t. Why?
WAIT
IF FILE(m.q_file)
DELETE FILE (m.q_file)
ENDI
RETURN
* END OF PROC TESTADIRFUNCTION.
We think 2147484160 != afiles(1,2), but sometimes vfp displays the result to true (.T.).
2. CAUSE:
In vfp6, vfp7 and vfp8, for the ADIR() function,
when the file size < 2 GB, there is no problem,
when the file size between 2 GB and 4GB, it returns the file size to a negative number,
when the file size >= 4 GB, it returns the file size to MOD(filesize,4GB).
In vfp9, for the ADIR() function,
when the file size < 2 GB - 1, there is no problem,
when the file size >= 2 GB - 1, it returns the file size to a positive number,
but the file size is a Numeric data with decimal places.
For example, the length of the file name is 50,
the file size is 2147483647.00000000000000000000000000000000000000000000000000.
Please refer to the SET DECIMALS Command,
the maximum number of decimal places is 18 (in fact, the maximum number of decimal places is 22 for vfp internal using).
If the number of decimal places > 22, the value of a Numeric data is incorrect.
In Visual FoxPro Advanced, for the ADIR() function,
when the file size < 2 GB - 1, it returns the file size to a Integer data,
when the file size >= 2 GB - 1, it returns the file size to a Numeric data without decimal places (N(15,0)),
so there is no any problem.
There are some BUGs in the following code.
3. RESOLUTION:
We can write some code to fix the BUG.
Fun4a7736 :: ; proc near
push ebp ;0x004a7736 : 55
lea ebp , dword ptr [ esp - 116 ] ;0x004a7737 : 8d6c248c
sub esp , 014Ch ;0x004a773b : 81ec4c010000
mov eax , dword ptr [ Data937090 ] ;0x004a7741 : a190709300
and dword ptr [ ebp + 0FFFFFF34h ] , 00h ;0x004a7746 : 83a534ffffff00
push ebx ;0x004a774d : 53
push edi ;0x004a774e : 57
pushd 04Bh ;0x004a774f : 6a4b
mov dword ptr [ ebp + 112 ] , eax ;0x004a7751 : 894570
xor eax , eax ;0x004a7754 : 33c0
pop ecx ;0x004a7756 : 59
lea edi , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a7757 : 8dbd38ffffff
rep stosd ;0x004a775d : f3ab
mov edi , dword ptr [ ebp + 124 ] ;0x004a775f : 8b7d7c
test byte ptr [ edi + 011Ah ] , 010h ;0x004a7762 : f6871a01000010
jne Label563657 ;0x004a7769 : 0f85e8be0b00
Label4a776f ::
and dword ptr [ ebp + 0FFFFFF3Ch ] , 00h ;0x004a776f : 83a53cffffff00
mov ebx , 0100h ;0x004a7776 : bb00010000
lea ecx , dword ptr [ edi + 0128h ] ;0x004a777b : 8d8f28010000
mov edx , ebx ;0x004a7781 : 8bd3
lea eax , dword ptr [ ebp + 0FFFFFF64h ] ;0x004a7783 : 8d8564ffffff
mov byte ptr [ ebp + 0FFFFFF38h ] , 043h ;0x004a7789 : c68538ffffff43
call Fun42c33e ;0x004a7790 : e8a94bf8ff
mov edx , ebx ;0x004a7795 : 8bd3
lea ecx , dword ptr [ ebp + 0FFFFFF64h ] ;0x004a7797 : 8d8d64ffffff
call Fun41b81c ;0x004a779d : e87a40f7ff
xor ebx , ebx ;0x004a77a2 : 33db
push ebx ;0x004a77a4 : 53
mov edx , esi ;0x004a77a5 : 8bd6
lea ecx , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a77a7 : 8d8d38ffffff
mov dword ptr [ ebp + 0FFFFFF40h ] , eax ;0x004a77ad : 898540ffffff
call Fun52bf26 ;0x004a77b3 : e86e470800
inc dword ptr [ esi + 12 ] ;0x004a77b8 : ff460c
cmp dword ptr [ ebp + 0FFFFFF34h ] , ebx ;0x004a77bb : 399d34ffffff
mov byte ptr [ ebp + 0FFFFFF38h ] , 049h ;0x004a77c1 : c68538ffffff49
mov dword ptr [ ebp + 0FFFFFF3Ch ] , 0Ah ;0x004a77c8 : c7853cffffff0a000000
jne Label563666 ;0x004a77d2 : 0f858ebe0b00
mov eax , dword ptr [ edi + 0124h ] ;0x004a77d8 : 8b8724010000
cmp eax , ebx ;0x004a77de : 3bc3
jne Label563671 ;0x004a77e0 : 0f858bbe0b00
mov ecx , dword ptr [ edi + 0120h ] ;0x004a77e6 : 8b8f20010000
cmp ecx , 07FFFFFFFh ;0x004a77ec : 81f9ffffff7f
jnb Label563671 ;0x004a77f2 : 0f8379be0b00
mov dword ptr [ ebp + 0FFFFFF44h ] , ecx ;0x004a77f8 : 898d44ffffff
Label4a77fe ::
push ebx ;0x004a77fe : 53
mov edx , esi ;0x004a77ff : 8bd6
lea ecx , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a7801 : 8d8d38ffffff
call Fun52bf26 ;0x004a7807 : e81a470800
inc dword ptr [ esi + 12 ] ;0x004a780c : ff460c
mov eax , dword ptr [ edi + 011Ch ] ;0x004a780f : 8b871c010000
mov dword ptr [ ebp + 124 ] , eax ;0x004a7815 : 89457c
movzx eax ,word ptr [ ebp + 126 ] ;0x004a7818 : 0fb7457e
mov ecx , eax ;0x004a781c : 8bc8
mov ebx , eax ;0x004a781e : 8bd8
shr ecx , 09h ;0x004a7820 : c1e909
shr eax , 05h ;0x004a7823 : c1e805
add ecx , 07BCh ;0x004a7826 : 81c1bc070000
and ebx , 01Fh ;0x004a782c : 83e31f
and eax , 0Fh ;0x004a782f : 83e00f
call Fun425db9 ;0x004a7832 : e882e5f7ff
xor ebx , ebx ;0x004a7837 : 33db
push ebx ;0x004a7839 : 53
fstp qword ptr [ ebp + 0FFFFFF48h ] ;0x004a783a : dd9d48ffffff
mov edx , esi ;0x004a7840 : 8bd6
lea ecx , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a7842 : 8d8d38ffffff
mov byte ptr [ ebp + 0FFFFFF38h ] , 044h ;0x004a7848 : c68538ffffff44
call Fun52bf26 ;0x004a784f : e8d2460800
mov eax , dword ptr [ ebp + 124 ] ;0x004a7854 : 8b457c
xor ecx , ecx ;0x004a7857 : 33c9
mov cl , al ;0x004a7859 : 8ac8
inc dword ptr [ esi + 12 ] ;0x004a785b : ff460c
and ecx , 01Fh ;0x004a785e : 83e11f
shl ecx , 1 ;0x004a7861 : d1e1
movsx ecx , cx ;0x004a7863 : 0fbfc9
push ecx ;0x004a7866 : 51
mov ecx , eax ;0x004a7867 : 8bc8
shr ax , 0Bh ;0x004a7869 : 66c1e80b
shr ecx , 05h ;0x004a786d : c1e905
movsx eax , ax ;0x004a7870 : 0fbfc0
and ecx , 03Fh ;0x004a7873 : 83e13f
push ecx ;0x004a7876 : 51
push eax ;0x004a7877 : 50
lea eax , dword ptr [ ebp + 0FFFFFF64h ] ;0x004a7878 : 8d8564ffffff
pushd offset Data920a9c ;0x004a787e : 689c0a9200
push eax ;0x004a7883 : 50
call Fun43089c ;0x004a7884 : e81390f8ff
add esp , 014h ;0x004a7889 : 83c414
push ebx ;0x004a788c : 53
mov edx , esi ;0x004a788d : 8bd6
lea ecx , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a788f : 8d8d38ffffff
mov byte ptr [ ebp + 0FFFFFF38h ] , 043h ;0x004a7895 : c68538ffffff43
mov dword ptr [ ebp + 0FFFFFF3Ch ] , ebx ;0x004a789c : 899d3cffffff
mov dword ptr [ ebp + 0FFFFFF40h ] , 08h ;0x004a78a2 : c78540ffffff08000000
call Fun52bf26 ;0x004a78ac : e875460800
inc dword ptr [ esi + 12 ] ;0x004a78b1 : ff460c
mov al , byte ptr [ edi + 011Ah ] ;0x004a78b4 : 8a871a010000
mov dl , al ;0x004a78ba : 8ad0
and dl , 01h ;0x004a78bc : 80e201
neg dl ;0x004a78bf : f6da
sbb dl , dl ;0x004a78c1 : 1ad2
and dl , 024h ;0x004a78c3 : 80e224
mov cl , 02Eh ;0x004a78c6 : b12e
add dl , cl ;0x004a78c8 : 02d1
mov byte ptr [ ebp + 0FFFFFF64h ] , dl ;0x004a78ca : 889564ffffff
mov dl , al ;0x004a78d0 : 8ad0
and dl , 020h ;0x004a78d2 : 80e220
neg dl ;0x004a78d5 : f6da
sbb dl , dl ;0x004a78d7 : 1ad2
and dl , 013h ;0x004a78d9 : 80e213
add dl , cl ;0x004a78dc : 02d1
mov byte ptr [ ebp + 0FFFFFF65h ] , dl ;0x004a78de : 889565ffffff
mov dl , al ;0x004a78e4 : 8ad0
and dl , 04h ;0x004a78e6 : 80e204
neg dl ;0x004a78e9 : f6da
sbb dl , dl ;0x004a78eb : 1ad2
and dl , 025h ;0x004a78ed : 80e225
and al , 02h ;0x004a78f0 : 2402
add dl , cl ;0x004a78f2 : 02d1
neg al ;0x004a78f4 : f6d8
sbb al , al ;0x004a78f6 : 1ac0
and al , 01Ah ;0x004a78f8 : 241a
mov byte ptr [ ebp + 0FFFFFF38h ] , 043h ;0x004a78fa : c68538ffffff43
mov dword ptr [ ebp + 0FFFFFF3Ch ] , ebx ;0x004a7901 : 899d3cffffff
mov byte ptr [ ebp + 0FFFFFF66h ] , dl ;0x004a7907 : 889566ffffff
add al , cl ;0x004a790d : 02c1
cmp dword ptr [ ebp + 0FFFFFF34h ] , ebx ;0x004a790f : 399d34ffffff
mov byte ptr [ ebp + 0FFFFFF67h ] , al ;0x004a7915 : 888567ffffff
sete al ;0x004a791b : 0f94c0
dec al ;0x004a791e : fec8
and al , 016h ;0x004a7920 : 2416
add al , cl ;0x004a7922 : 02c1
push ebx ;0x004a7924 : 53
mov edx , esi ;0x004a7925 : 8bd6
lea ecx , dword ptr [ ebp + 0FFFFFF38h ] ;0x004a7927 : 8d8d38ffffff
mov byte ptr [ ebp + 0FFFFFF68h ] , al ;0x004a792d : 888568ffffff
mov byte ptr [ ebp + 0FFFFFF69h ] , bl ;0x004a7933 : 889d69ffffff
mov dword ptr [ ebp + 0FFFFFF40h ] , 05h ;0x004a7939 : c78540ffffff05000000
call Fun52bf26 ;0x004a7943 : e8de450800
mov ecx , dword ptr [ ebp + 112 ] ;0x004a7948 : 8b4d70
inc dword ptr [ esi + 12 ] ;0x004a794b : ff460c
call Fun42bf1d ;0x004a794e : e8ca45f8ff
pop edi ;0x004a7953 : 5f
pop ebx ;0x004a7954 : 5b
add ebp , 074h ;0x004a7955 : 83c574
leave ;0x004a7958 : c9
ret 04h ;0x004a7959 : c20400
Label563657 ::
mov dword ptr [ ebp + 0FFFFFF34h ] , 01h ;0x00563657 : c78534ffffff01000000
jmp Label4a776f ;0x00563661 : e90941f4ff
Label563666 ::
mov dword ptr [ ebp + 0FFFFFF44h ] , ebx ;0x00563666 : 899d44ffffff
jmp Label4a77fe ;0x0056366c : e98d41f4ff
Label563671 ::
pushd 01h ;0x00563671 : 6a01
push ebx ;0x00563673 : 53
push ebx ;0x00563674 : 53
push eax ;0x00563675 : 50
mov byte ptr [ ebp + 0FFFFFF38h ] , 04Eh ;0x00563676 : c68538ffffff4e
;
; ----------------------------------------------------
; VFP 9.0 FIX - ADIR() FUNCTION
; November 2021
; ----------------------------------------------------
; CCB
;
; In vfp9, the ADIR() function can only return file size information when the file size < 2 GB,
; now the ADIR() function can return file size information when the file size > 2 GB.
;
; 2021/11/23, by ccb
;
mov dword ptr [ ebp + 0FFFFFF38h + 4 ] , 0Fh
mov dword ptr [ ebp + 0FFFFFF38h + 8 ] , 00h
call Fun4351c6 ;0x0056367d : e8441bedff
mov ecx , dword ptr [ edi + 0120h ] ;0x00563682 : 8b8f20010000
xor ebx , ebx ;0x00563688 : 33db
add eax , ecx ;0x0056368a : 03c1
adc edx , ebx ;0x0056368c : 13d3
mov dword ptr [ ebp + 0FFFFFF28h ] , eax ;0x0056368e : 898528ffffff
mov dword ptr [ ebp + 0FFFFFF2Ch ] , edx ;0x00563694 : 89952cffffff
fild qword ptr [ ebp + 0FFFFFF28h ] ;0x0056369a : dfad28ffffff
fstp qword ptr [ ebp + 0FFFFFF48h ] ;0x005636a0 : dd9d48ffffff
jmp Label4a77fe ;0x005636a6 : e95341f4ff
4. APPLIES TO:
VFP 6.0.8167.0
VFP 6.0.8961.0 (SP5)
VFP 7.0.0.9262
VFP 7.0.0.9465 (SP1)
VFP 8.0.0.2521
VFP 8.0.0.3117 (SP1)
VFP 9.0.0.2412
VFP 9.0.0.3504 (SP1)
VFP 9.0.0.4611 (SP2)
VFP 9.0.0.5015 (SP2)
VFP 9.0.0.5411 (SP2)
VFP 9.0.0.5721 (SP2)
VFP 9.0.0.5815 (SP2)
VFP 9.0.0.6303 (SP2)
VFP 9.0.0.6602 (SP2)
VFP 9.0.0.7423 (SP2)
The bug has been fixed in VFP Advanced.
5. REFERENCE WEBSITES:
1, baiyujia.com:
http://www.baiyujia.com
http://www.baiyujia.com/vfpdocuments/f_vfp9fix101.asp
6. OTHER:
For reference only, there is no guarantees.
Any questions or suggestions, please send me an email at ccb2000@163.com.
|