[Top][All Lists]

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

Re: CVS update: MODIFIED: src ...

From: Derek Robert Price
Subject: Re: CVS update: MODIFIED: src ...
Date: Fri, 25 Jul 2003 13:28:45 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1

John Tytgat wrote:

dprice@cvshome.org wrote:

  strip_trailing_newlines (char *str)
 -    int len;
 -    len = strlen (str) - 1;
 +    int len, origlen;
 +    len = origlen = strlen (str) - 1;
        while (str[len] == '\n')
      str[len--] = '\0';
 +    return len != origlen;

What if str points in the middle of a zero terminated char array full of '\n' chars ? len will go negative. I admit it is unlikely but I would change :

while (str[len] == '\n')


while (str[len] == '\n' && len >= 0)

Well, the only three locations in CVS that strip_trailing_newlines is currently being called are all passing in strings received from getnline, so they can have at most one EOL on the end of them, but I checked in your suggestion anyhow in case someone tries to trust and use the function in the future.

Hrm. I guess an empty line, with only a newline, could have attempted to walk back into unknown memory space before the string anyhow. Thanks!



Email: derek@ximbiot.com

Get CVS support at <http://ximbiot.com>!
I will not belch the National Anthem.
I will not belch the National Anthem.
I will not belch the National Anthem...

         - Bart Simpson on chalkboard, _The Simpsons_

reply via email to

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