diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2011-03-28 18:07:22 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@elego.de> | 2011-03-28 18:07:22 +0200 |
commit | 3b4835c25a41781d27a667dbd02ff03d54d221b9 (patch) | |
tree | 8b9f792ffbb02ae130ce670973d8e91dc4fe6339 /src | |
parent | 908afb771ad6a788dd250beede65dd129962da00 (diff) | |
download | libgit2-3b4835c25a41781d27a667dbd02ff03d54d221b9.tar.gz |
Correctly parse the section header
If cfg_readline consumes the line, then parse_section_header will read
past it and if we read a character, parse_variable won't have the full
name.
This solution is a bit hackish, but it's the simplest way to get the
code to parse correctly.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c index a3d7f8e73..f49620246 100644 --- a/src/config.c +++ b/src/config.c @@ -163,6 +163,9 @@ static int is_linebreak(const char *pos) memcmp(pos - 2, LINEBREAK_WIN32, sizeof(LINEBREAK_WIN32)) == 0; } +/* + * Read a line, but don't consume it + */ static char *cfg_readline(git_config *cfg) { char *line = NULL; @@ -213,12 +216,41 @@ static char *cfg_readline(git_config *cfg) if (*line_end == '\0') cfg->reader.eof = 1; + /* cfg->reader.line_number++; cfg->reader.read_ptr = line_end; + */ return line; } +/* + * Consume a line, without storing it anywhere + */ +void cfg_consume_line(git_config *cfg) +{ + char *line_start, *line_end; + int len; + + line_start = cfg->reader.read_ptr; + line_end = strchr(line_start, '\n'); + /* No newline at EOF */ + if(line_end == NULL){ + line_end = strchr(line_start, '\0'); + } + + len = line_end - line_start; + + if (*line_end == '\n') + line_end++; + + if (*line_end == '\0') + cfg->reader.eof = 1; + + cfg->reader.line_number++; + cfg->reader.read_ptr = line_end; +} + static inline int config_keychar(int c) { return isalnum(c) || c == '-'; @@ -388,17 +420,23 @@ static int config_parse(git_config *cfg_file) break; case '[': /* section header, new section begins */ - error = parse_section_header(¤t_section, line); + if (current_section) + free(current_section); + error = parse_section_header(cfg_file, ¤t_section, line); break; default: /* assume variable declaration */ error = parse_variable(cfg_file, current_section, line); + cfg_consume_line(cfg_file); break; } free(line); } + if(current_section) + free(current_section); + return error; } |