#633 bad pointer difference computing and one sigsegv as bonus

closed-fixed
5
2013-05-25
2003-11-12
No

Hi guys,
I found that the computing pointer difference in the following
example is incorrect . The result is divided by two, but either FLASH
array and fp pointer are pointers to unsigned char.

Creating this simple example I found a nice SIGSEGV :-)
Try uncomment the define :-)
The sigsegv can be verified only with --model-small. With
--model-large the linker reports undefined variable, that is not too
clear to understand. Uninitialized variable warning can be better, if
possible.

sdcc -v
SDCC :
mcs51/gbz80/z80/avr/ds390/pic14/pic16/TININative/xa51/ds400/hc
08 2.3.6 (Nov 11 2003) (UNIX)

------------------------------------------------------------------
//#define I_WANT_SEE_A_NICE_SIGSEGV // with --model-small
xdata unsigned char FLASH[0x6000];

int main()
{
unsigned int l, l2;
xdata unsigned char *fp;

#ifndef I_WANT_SEE_A_NICE_SIGSEGV
fp=&FLASH[0x4000];
#endif
l=&FLASH[0x6000]-fp; // this line is compiled incorrectly
l2=(unsigned int)&FLASH[0x6000]-(unsigned int)fp; // this is ok
return l+l2;
}

/* incorrect result:

;bug_array1.c:9: fp=&FLASH[0x4000];
;bug_array1.c:10: l=&FLASH[0x6000]-fp;
; genMinus
mov a,#(_FLASH + 0x6000)
clr c
subb a,#(_FLASH + 0x4000)
mov r2,a
mov a,#((_FLASH + 0x6000) >> 8)
subb a,#((_FLASH + 0x4000) >> 8)
mov r3,a
; genAssign
clr a
mov (__divsint_PARM_2 + 1),a
mov __divsint_PARM_2,#0x02
; genCall
mov dpl,r2
mov dph,r3
lcall __divsint
mov r2,dpl
mov r3,dph

*/

Discussion

  • Erik Petrich

    Erik Petrich - 2003-11-13
    • assigned_to: nobody --> epetrich
    • status: open --> pending
     
  • Erik Petrich

    Erik Petrich - 2003-11-14
    • labels: --> C-Front End
    • milestone: --> fixed
    • status: pending --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2003-11-14

    Logged In: YES
    user_id=635249

    Fixed with src/SDCCicode.c 1.175 (pointer difference
    problem) and src/SDCCopt.c 1.36 (SIGSEGV)

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks