|
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: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 :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; }while (str[len] == '\n') into 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!
Derek -- *8^) 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_
[Prev in Thread] | Current Thread | [Next in Thread] |