diff options
author | Erik Faye-Lund <kusmabite@gmail.com> | 2011-04-10 22:54:18 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-04-11 14:10:06 -0700 |
commit | e96c19c50fb0807570b85cb5b8aae6dfcfa9b9ec (patch) | |
tree | 27fa8b42fe693cb101c83c5269f763f1e68ab7de /config.c | |
parent | 5e7a5d97f8a74181634a70e0e7b1464855c5af2d (diff) | |
download | git-e96c19c50fb0807570b85cb5b8aae6dfcfa9b9ec.tar.gz |
config: support values longer than 1023 bytes
parse_value in config.c has a static buffer of 1024 bytes that it
parse the value into. This can sometimes be a problem when a
config file contains very long values.
It's particularly amusing that git-config already is able to write
such files, so it should probably be able to read them as well.
Fix this by using a strbuf instead of a fixed-size buffer.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -46,23 +46,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; } @@ -73,7 +71,7 @@ static char *parse_value(void) } } for (; space; space--) - value[len++] = ' '; + strbuf_addch(&value, ' '); if (c == '\\') { c = get_next_char(); switch (c) { @@ -95,14 +93,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); } } |