bishop@dorsai (Julian Cowell) (06/13/91)
I have been getting some odd results with GetScrap. Using TC 4.0.5 the following code fragment produces system error id = 28 :- void FormEditApp::AdjustMenus() { int offset; long int len; . . . len = GetScrap(NIL_POINTER,'TEXT', &offset);/* NIL_POINTER 0L */ if ( len > 0 ) EnableItem(gEditMenu, E_PASTE_ITEM); . . } The asm equivalent (by TC compiler) is :- CLR.L -(A7) ;make space for result of _GetScrap CLR.L -(A7) ;push null pointer onto stack PEA $54455854 ;push 'TEXT' PEA -$0002(A6) ;push address of offset _GetScrap This all looks normal..so why does it crash ? I should mention that it does'nt crash immediatly, but right after the calling method tries to exit..then the stack over flows heap error appears (id = 28). So it seems that the ret address is lost. In desperation ('twas 5 a.m) I replaced PEA -$0002(A6) ;push address of offset ;with MOVE.L -$0002(A6),-(A7) ;???..this should'nt work and the program ran fine. So after hours more twiddling I tried this bit 'o code:- void FormEditApp::AdjustMenus() { int offset; long int len; . offset = NewPtr(sizeof(int)); len = GetScrap(NIL_POINTER,'TEXT', offset);/* NIL_POINTER 0L */ DisposPtr(offset); . } the compiler gives:- CLR.L -(A7) ;make space for result of _GetScrap CLR.L -(A7) ;push null pointer onto stack PEA $54455854 ;push 'TEXT' MOVE.L -$0004(A6),-(A7) ;push address of offset _GetScrap This works..as it should. Can anyone help? -Bishop