summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-04-27 11:36:43 -0700
committerJunio C Hamano <gitster@pobox.com>2011-04-27 11:36:43 -0700
commitc5a5f12e5a514d198f49a76d4e001c88570bf7d1 (patch)
treeb66c2a8a2596b27f922fd2b9aa476895037a8780 /config.c
parent2a2dbd2770b4dbda59b5b22e19fac973d08d0864 (diff)
parente96c19c50fb0807570b85cb5b8aae6dfcfa9b9ec (diff)
downloadgit-c5a5f12e5a514d198f49a76d4e001c88570bf7d1.tar.gz
Merge branch 'ef/maint-strbuf-init'
* ef/maint-strbuf-init: config: support values longer than 1023 bytes strbuf: make sure buffer is zero-terminated
Diffstat (limited to 'config.c')
-rw-r--r--config.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/config.c b/config.c
index d06fb19d51..5f9ec28945 100644
--- a/config.c
+++ b/config.c
@@ -133,23 +133,21 @@ static int get_next_char(void)
static char *parse_value(void)
{
- static char value[1024];
- int quote = 0, comment = 0, len = 0, space = 0;
+ static struct strbuf value = STRBUF_INIT;
+ int quote = 0, comment = 0, space = 0;
+ strbuf_reset(&value);
for (;;) {
int c = get_next_char();
- if (len >= sizeof(value) - 1)
- return NULL;
if (c == '\n') {
if (quote)
return NULL;
- value[len] = 0;
- return value;
+ return value.buf;
}
if (comment)
continue;
if (isspace(c) && !quote) {
- if (len)
+ if (value.len)
space++;
continue;
}
@@ -160,7 +158,7 @@ static char *parse_value(void)
}
}
for (; space; space--)
- value[len++] = ' ';
+ strbuf_addch(&value, ' ');
if (c == '\\') {
c = get_next_char();
switch (c) {
@@ -182,14 +180,14 @@ static char *parse_value(void)
default:
return NULL;
}
- value[len++] = c;
+ strbuf_addch(&value, c);
continue;
}
if (c == '"') {
quote = 1-quote;
continue;
}
- value[len++] = c;
+ strbuf_addch(&value, c);
}
}