------------------------------------------------------------
                        [BUG/PRB.] VFP 9.0 FIX - SYS(2017) FUNCTION
                                January 2024
                 ------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 and vfp8, sometimes vfp will crash when calling the SYS(2017) function with a memo field.

     There is a test program:

     *PROC testsys2017function

     SELE 0
     CREATE CURSOR tmp1 (fld1 m)
     APPEND BLANK
     REPL fld1 WITH "aaa"
     ?INLIST("123","a","b","c",SYS(2017,fld1))
     WAIT

     RETURN

     * END OF PROC TESTSYS2017FUNCTION.

     We think it will display .F., but vfp will crash.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun4a487b :: ; proc near
             push ebp                                                        ;0x004a487b :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFBC0h ]                       ;0x004a487c :        8dac24c0fbffff
             sub esp , 04C0h                                                 ;0x004a4883 :        81ecc0040000
             test  byte ptr [ ebp + 0450h ] , 01h                            ;0x004a4889 :        f6855004000001
             mov eax ,  dword ptr [ Data937090 ]                             ;0x004a4890 :        a190709300
             push ebx                                                        ;0x004a4895 :        53
             mov  ebx , dword ptr [ ebp + 0448h ]                            ;0x004a4896 :        8b9d48040000
             push esi                                                        ;0x004a489c :        56
             mov  esi , dword ptr [ ebp + 044Ch ]                            ;0x004a489d :        8bb54c040000
             mov  dword ptr [ ebp + 043Ch ] , eax                            ;0x004a48a3 :        89853c040000
             push edi                                                        ;0x004a48a9 :        57
             jne Label5a64c1                                                 ;0x004a48aa :        0f85111c1000
             pushd 08h                                                       ;0x004a48b0 :        6a08
             call Fun437a96                                                  ;0x004a48b2 :        e8df31f9ff
             test esi , esi                                                  ;0x004a48b7 :        85f6
             pop ecx                                                         ;0x004a48b9 :        59
             jne Label5a64e0                                                 ;0x004a48ba :        0f85201c1000
             test eax , eax                                                  ;0x004a48c0 :        85c0
             je Label4a4925                                                  ;0x004a48c2 :        7461
             mov  dword ptr [eax] , offset DataPtr91fbe0                                 ;0x004a48c4 :        c700e0fb9100
             or  word ptr [ eax + 4 ] , 0FFFFFFFFh                           ;0x004a48ca :        66834804ff

     Label4a48cf ::
             mov  dword ptr [ ebp + 16 ] , eax                               ;0x004a48cf :        894510

     Label4a48d2 ::
             test  byte ptr [ ebp + 0450h ] , 080h                           ;0x004a48d2 :        f6855004000080
             jne Label5a6544                                                 ;0x004a48d9 :        0f85651c1000
             mov  al , byte ptr [ebx]                                        ;0x004a48df :        8a03
             cmp al , 04Dh                                                   ;0x004a48e1 :        3c4d
             je Label4a492b                                                  ;0x004a48e3 :        7446
             cmp al , 057h                                                   ;0x004a48e5 :        3c57
             je Label4a492b                                                  ;0x004a48e7 :        7442
             push  dword ptr [ ebx + 8 ]                                     ;0x004a48e9 :        ff7308
             mov  edx , dword ptr [ ebx + 32 ]                               ;0x004a48ec :        8b5320
             mov  ecx , dword ptr [ ebp + 16 ]                               ;0x004a48ef :        8b4d10
             push  dword ptr [edx]                                           ;0x004a48f2 :        ff32
             mov  eax , dword ptr [ecx]                                      ;0x004a48f4 :        8b01
             call  dword ptr [eax]                                           ;0x004a48f6 :        ff10

     Label4a48f8 ::
             mov  edi , dword ptr [ ebp + 16 ]                               ;0x004a48f8 :        8b7d10
             mov  eax , dword ptr [edi]                                      ;0x004a48fb :        8b07
             mov ecx , edi                                                   ;0x004a48fd :        8bcf
             call  dword ptr [ eax + 4 ]                                     ;0x004a48ff :        ff5004
             push edi                                                        ;0x004a4902 :        57
             mov esi , eax                                                   ;0x004a4903 :        8bf0
             call Fun43d8b4                                                  ;0x004a4905 :        e8aa8ff9ff
             pop ecx                                                         ;0x004a490a :        59
             mov eax , esi                                                   ;0x004a490b :        8bc6

     Label4a490d ::
             mov  ecx , dword ptr [ ebp + 043Ch ]                            ;0x004a490d :        8b8d3c040000
             call Fun42bf1d                                                  ;0x004a4913 :        e80576f8ff
             pop edi                                                         ;0x004a4918 :        5f
             pop esi                                                         ;0x004a4919 :        5e
             pop ebx                                                         ;0x004a491a :        5b
             add ebp , 0440h                                                 ;0x004a491b :        81c540040000
             leave                                                           ;0x004a4921 :        c9
             ret 0Ch                                                         ;0x004a4922 :        c20c00

     Label5a6544 ::


     ;
     ;                 -------------------------------------------------
     ;                        VFP 9.0 FIX - SYS(2017) FUNCTION
     ;                                  March 2021
     ;                 -------------------------------------------------
     ;                                     CCB
     ;
     ; Sometimes vfp will crash when calling the SYS(2017) function with a memo field.
     ;
     ; 2021/3/28, by ccb
     ;

             xor eax , eax
             xor esi , esi
             cmp ebx , esi
             je Label4a490d
             mov  al , byte ptr [ebx]
             cmp al , 04Dh
             je Label4a48f8


             pushd 0Bh                                                       ;0x005a6544 :        6a0b
             xor eax , eax                                                   ;0x005a6546 :        33c0
             xor esi , esi                                                   ;0x005a6548 :        33f6
             cmp ebx , esi                                                   ;0x005a654a :        3bde
             pop ecx                                                         ;0x005a654c :        59
             lea edi ,  dword ptr [ ebp - 44 ]                               ;0x005a654d :        8d7dd4
             rep stosd                                                       ;0x005a6550 :        f3ab
             je Label5a657a                                                  ;0x005a6552 :        7426
             mov  edi , dword ptr [ ebx + 8 ]                                ;0x005a6554 :        8b7b08
             mov eax , 0100h                                                 ;0x005a6557 :        b800010000
             cmp edi , eax                                                   ;0x005a655c :        3bf8
             jbe Label5a6562                                                 ;0x005a655e :        7602
             mov edi , eax                                                   ;0x005a6560 :        8bf8

     Label5a6562 ::
             mov  eax , dword ptr [ ebx + 32 ]                               ;0x005a6562 :        8b4320
             push edi                                                        ;0x005a6565 :        57
             push  dword ptr [eax]                                           ;0x005a6566 :        ff30
             lea eax ,  dword ptr [ ebp + 013Ch ]                            ;0x005a6568 :        8d853c010000
             push eax                                                        ;0x005a656e :        50
             call  dword ptr [ Data9392b8 ]                                  ;0x005a656f :        ff15b8929300
             add esp , 0Ch                                                   ;0x005a6575 :        83c40c
             jmp Label5a657c                                                 ;0x005a6578 :        eb02


4. APPLIES TO:

     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_vfpsysfunctions.asp


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.