From: Nguyễn Thái Ngọc Duy Date: Thu, 20 Aug 2009 13:47:00 +0000 (+0700) Subject: Avoid writing to buffer in add_excludes_from_file_1() X-Git-Tag: v1.7.0-rc0~103^2~19 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b5041c5;p=git.git Avoid writing to buffer in add_excludes_from_file_1() In the next patch, the buffer that is being used within add_excludes_from_file_1() comes from another function and does not have extra space to put \n at the end. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/dir.c b/dir.c index e05b850ac..1170d6467 100644 --- a/dir.c +++ b/dir.c @@ -229,10 +229,9 @@ static int add_excludes_from_file_1(const char *fname, if (buf_p) *buf_p = buf; - buf[size++] = '\n'; entry = buf; - for (i = 0; i < size; i++) { - if (buf[i] == '\n') { + for (i = 0; i <= size; i++) { + if (i == size || buf[i] == '\n') { if (entry != buf + i && entry[0] != '#') { buf[i - (i && buf[i-1] == '\r')] = 0; add_exclude(entry, base, baselen, which);