gnupic: Re: Segmentation fault ... other locations of problem and different types of fixes
Subject:
Re: Segmentation fault ... other locations of problem and different types of fixes
From:
Robert Warner ####@####.####
Date:
30 May 2002 02:03:40 -0000
Message-Id: <02052917545809.03555@amdk62300>
This may or may not help. There were 2 additional locations. However each
required a different type of fix to solve it. Here they are
(btw, I do this at night ... so I don't get your mails 'til the next day)
Not to lecture (please do not take offense) ... from my days of teaching
ANSI/ISO C for embedded systems ... variables whether initaialized or not can
be used as indices for arrays. C does not check bounds on array access.
(Unlike Ada).
Example of problem #2
//BOOL get_hexbyte(BYTE *val)
BOOL get_hexbyte( BYTE *val, int *prxout)
{
BYTE b;
BOOL ok=0;
*val = 0;
// while (isxdigit(rxbuff[rxout]) && get_byte(&b)) //Segmentation Fault
// while (isxdigit(rxbuff[*prxout]) && get_byte(&b)) //no help
//Fixed with pointer arithmatic
while ( isxdigit( *((BYTE *)(rxbuff) + *prxout)) && get_byte(&b))
{
ok = 1;
*val <<= 4;
if (b <= '9')
*val += b - '0';
else
*val += (b-'A'+10) & 0xf;
}
return(ok);
}
Example of problem #3
//BYTE getch_slip(void)
BYTE getch_slip( int *prxout)
{
BYTE b=0;
slipend = rxout>=rxcount;
if (!slipend)
{
// b = rxbuff[rxout++]; //Segmentation Fault
b = *(((BYTE *)rxbuff) + *prxout++); //Fixed with pointer arithmatic
*prxout++;
check_byte(b);
}
return(b);
}
Hopefully this additional information helps
Thanks
Bob
On Wednesday 29 May 2002 09:30, Scott Dattalo wrote:
> On Tue, 28 May 2002, Robert Warner wrote:
> > Ok, after several compile/edit sequences I've come up with the
> > following. It appears an array indexed with a variable causes a problem.
>
> And this is undoubtedly a bug in SDCC. I'll look into this right now...
>
> Thanks for the report,
> Scott
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####