[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" <derek@ximbiot.com> wrote in message
news:mailman.555.1059273520.8231.bug-cvs@gnu.org...
> 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.