X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=strbuf.c;h=9d9d8bed915483abbc2ebb340e0881ae4e296bd4;hb=fd7e9fb7ae206a64b87c7faecfc88716e98a7577;hp=dac945c7c8ec3ca14791e472fd19a47cc07dcd15;hpb=d1df5743809614241883ecad51876607cf432034;p=git.git diff --git a/strbuf.c b/strbuf.c index dac945c7..9d9d8bed 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,9 +1,10 @@ #include #include #include "strbuf.h" +#include "cache.h" void strbuf_init(struct strbuf *sb) { - sb->buf = 0; + sb->buf = NULL; sb->eof = sb->alloc = sb->len = 0; } @@ -15,7 +16,7 @@ static void strbuf_begin(struct strbuf *sb) { static void inline strbuf_add(struct strbuf *sb, int ch) { if (sb->alloc <= sb->len) { sb->alloc = sb->alloc * 3 / 2 + 16; - sb->buf = realloc(sb->buf, sb->alloc); + sb->buf = xrealloc(sb->buf, sb->alloc); } sb->buf[sb->len++] = ch; } @@ -36,7 +37,7 @@ void read_line(struct strbuf *sb, FILE *fp, int term) { break; strbuf_add(sb, ch); } - if (sb->len == 0) + if (ch == EOF && sb->len == 0) sb->eof = 1; strbuf_end(sb); }