bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS update: MODIFIED: src ...


From: Paul Edwards
Subject: Re: CVS update: MODIFIED: src ...
Date: Sun, 27 Jul 2003 05:07:10 GMT

"Derek Robert Price" <address@hidden> wrote in message news:address@hidden
> Paul Edwards wrote:
>
> > Actually, on an empty string, the above code will try to
> >
> >access str[-1], which could cause a memory violation
> >(read, not write).
> >
> >And strlen() actually returns a size_t, ie normally an unsigned int,
> >so if you do it properly, you would actually go:
> >
> >strip_trailing_newlines (char *str)
> >{
> >    size_t len, origlen;
> >    len = origlen = strlen (str);
> >
> >    while (len > 0 && str[--len] == '\n' )
> >    {
> >        str[len] = '\0';
> >    }
> >    return len != origlen;
> >}
>
> Yeah, thanks.  I fixed that yesterday about 2 o'clock.  John pointed it
> out soon after the commit.

Actually, mine is wrong too.  Try this instead...

strip_trailing_newlines (char *str)
{
    size_t len, origlen;
    len = origlen = strlen (str);

    while (len > 0 && str[len-1] == '\n' )
    {
        str[--len] = '\0';
    }
    return len != origlen;
}

BFN.  Paul.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]