-----------------------------------------------------------------------
                      [ENHANCED] VFP 9.0 FIX - CATCH THE INTERNAL CONSISTENCY ERROR
                               January 2024
                 -----------------------------------------------------------------------
                                     CCB



1. BUG:

     If we enable catching the internal consistency error in Visual FoxPro Advanced,
     when Visual FoxPro causes the internal consistency error (Error 1000),
     it will display a dialog box "Are you sure you want to exit Visual FoxPro?",
     if we select "Yes", it will display the error dialog box "Internal consistency error",
     and then it will display a dialog box "Do you want to save changes to ...?" if there are some unsaved files,
     and then exit Visual FoxPro,
     if we select "No", it will cause the error "There is not enough memory to complete this operation (Error 43)",
     and then it will return to Visual FoxPro, now we can do some important work, and then exit Visual FoxPro.
     It is the startup default for Visual FoxPro Advanced Interactive Development Environment (IDE).

     Please refer to the picture testinternalconsistencyerror.png:

     If we disable catching the internal consistency error in Visual FoxPro Advanced,
     when Visual FoxPro causes the internal consistency error (Error 1000),
     it will display the error dialog box "Internal consistency error",
     and then it will display a dialog box "Do you want to save changes to ...?" if there are some unsaved files,
     and then exit Visual FoxPro.
     It is the startup default for Visual FoxPro Advanced Runtime and Visual FoxPro Advanced Multi-threaded Runtime.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun544742 :: ; proc near
             push ebp                                                        ;0x00544742 :        55
             mov eax , 012F4h                                                ;0x00544743 :        b8f4120000
             lea ebp ,  dword ptr [ esp + 0FFFFEF0Ch ]                       ;0x00544748 :        8dac240cefffff
             call Fun42c118                                                  ;0x0054474f :        e8c479eeff
             mov eax ,  dword ptr [ Data937090 ]                             ;0x00544754 :        a190709300
             push ebx                                                        ;0x00544759 :        53
             mov  dword ptr [ ebp + 010F0h ] , eax                           ;0x0054475a :        8985f0100000
             push esi                                                        ;0x00544760 :        56
             mov eax , ecx                                                   ;0x00544761 :        8bc1


     ;
     ;                 ------------------------------------------------------------
     ;                      VFP 9.0 FIX - CATCH THE INTERNAL CONSISTENCY ERROR
     ;                                  June 2022
     ;                 ------------------------------------------------------------
     ;                                     CCB
     ;
     ; Catch the internal consistency error (Error 1000).
     ;
     ; 2022/6/13, by ccb
     ;

             cmp dword ptr vfpa_sys9101_data,00h
             je Label544763
             cmp eax , 00h
             jne Label544763
             xor esi , esi
             mov eax ,  dword ptr [ Data9370e8 ]
             mov  dl , byte ptr [ eax + 28 ]
             mov cl , 08h
             test cl , dl
             jne Label544762
     Label54475f ::
             mov  ecx , dword ptr [ Data937220 ]
             cmp ecx , esi
             je Label544761
             cmp  eax , dword ptr [ ecx + 72 ]
             jne Label544761
             cmp dword ptr vfpa_sys9101_data,02h
             je Label544760
             pushd 00h
             pushd 02h
             pushd 00h
             pushd 00h
             lea eax ,  byte ptr vfpa_sys9101_text
             push eax
             call Fun6da248
             cmp eax , 02h
             jne Label544761
     Label544760 ::
             mov ecx , 0B6h
             mov eax , ecx
             jmp Label544763
     Label544761 ::
             mov ecx , 00h
             mov eax , ecx
             jmp Label544763
     Label544762 ::
             mov  dl , byte ptr [ eax - 28 ]
             sub eax , 038h
             test cl , dl
             jne Label544762
             jmp Label54475f


     Label544763 ::
             mov  cx , word ptr [ Data937770 ]                               ;0x00544763 :        668b0d70779300
             xor esi , esi                                                   ;0x0054476a :        33f6
             cmp eax , 065h                                                  ;0x0054476c :        83f865
             push edi                                                        ;0x0054476f :        57
             mov  dword ptr [ Data939800 ] , esi                             ;0x00544770 :        893500989300
             je Label58ccb0                                                  ;0x00544776 :        0f8434850400

     Label54477c ::
             cmp eax , 0ABh                                                  ;0x0054477c :        3dab000000
             je Label58ccc1                                                  ;0x00544781 :        0f843a850400

     Label544787 ::
             cmp eax , 063h                                                  ;0x00544787 :        83f863
             mov ebx , eax                                                   ;0x0054478a :        8bd8
             mov  dword ptr [ ebp + 112 ] , ebx                              ;0x0054478c :        895d70
             je Label58cce0                                                  ;0x0054478f :        0f844b850400

     Label544795 ::
             mov eax , offset Data922b80                                              ;0x00544795 :        b8802b9200
             mov edi , edi                                                   ;0x0054479a :        8bff

     Label54479c ::
             movsx ecx ,word ptr [eax]                                       ;0x0054479c :        0fbf08
             cmp ecx , ebx                                                   ;0x0054479f :        3bcb
             je Label5447b3                                                  ;0x005447a1 :        7410
             add eax , 0Ch                                                   ;0x005447a3 :        83c00c
             cmp eax , offset Data925568                                              ;0x005447a6 :        3d68559200
             jnb Label58cd01                                                 ;0x005447ab :        0f8350850400
             jmp Label54479c                                                 ;0x005447b1 :        ebe9

     Label5447b3 ::
             cmp eax , esi                                                   ;0x005447b3 :        3bc6
             je Label58cd08                                                  ;0x005447b5 :        0f844d850400
             movzx eax ,byte ptr [ eax + 2 ]                                 ;0x005447bb :        0fb64002
             mov ecx , eax                                                   ;0x005447bf :        8bc8
             and ecx , 01h                                                   ;0x005447c1 :        83e101
             and eax , 04h                                                   ;0x005447c4 :        83e004
             mov edi , eax                                                   ;0x005447c7 :        8bf8

     Label5447c9 ::
             cmp ecx , esi                                                   ;0x005447c9 :        3bce
             mov  dword ptr [ ebp + 108 ] , edi                              ;0x005447cb :        897d6c
             mov  dword ptr [ ebp + 104 ] , ecx                              ;0x005447ce :        894d68
             jne Label58cd20                                                 ;0x005447d1 :        0f8549850400
             mov eax ,  dword ptr [ Data9370e8 ]                             ;0x005447d7 :        a1e8709300
             mov  dl , byte ptr [ eax + 28 ]                                 ;0x005447dc :        8a501c
             mov cl , 08h                                                    ;0x005447df :        b108
             test cl , dl                                                    ;0x005447e1 :        84d1
             jne Label58cd11                                                 ;0x005447e3 :        0f8528850400

     Label5447e9 ::
             mov  ecx , dword ptr [ Data937220 ]                             ;0x005447e9 :        8b0d20729300
             cmp ecx , esi                                                   ;0x005447ef :        3bce
             je Label4cec47                                                  ;0x005447f1 :        0f8450a4f8ff
             cmp  eax , dword ptr [ ecx + 72 ]                               ;0x005447f7 :        3b4148
             jne Label4cec47                                                 ;0x005447fa :        0f8547a4f8ff
             push ebx                                                        ;0x00544800 :        53
             call Fun543c69                                                  ;0x00544801 :        e863f4ffff


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


6. OTHER:

     For reference only, there is no guarantees.

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