#1483 Bug in strcspn causes hang

closed-fixed
5
2013-05-25
2008-10-01
No

SDCC Version
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.4 #5
242 (Sep 25 2008) (MINGW32)

Bug:
When calling strcspn("ABCD", "DE") strcspn goes into infinite loop

Cause:
strcspn implementation located at $SDCC\lib\src\_strcspn.c does not increment string pointer correctly.

Original Code
-------------
int strcspn (
char * string ,
char * control
)
{
register int count = 0 ;
register char ch ;

while (ch = *string) {
if (strchr(control,ch))
break;
else
count++ ;
}

return count ;
}

Proposed Fix
------------
add string++ statement.

Propsoed Fix Code
-----------------
int strcspn (
char * string ,
char * control
)
{
register int count = 0 ;
register char ch ;

while (ch = *string) {
if (strchr(control,ch))
break;
else
count++ ;
>>>>>>>>>>>>>>>>string++;<<<<<<<<<<<<<<<<<<<<
}

return count ;
}

If this looks correct, could someone with write permissions check this in? Thanks!

Discussion

  • Maarten Brock

    Maarten Brock - 2008-10-09

    Applied in SDCC 2.8.4 #5250.
    Thanks

     
  • Maarten Brock

    Maarten Brock - 2008-10-09
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks