mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 17:20:22 +00:00
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>
This commit is contained in:
parent
908afb771a
commit
3b4835c25a
40
src/config.c
40
src/config.c
@ -163,6 +163,9 @@ static int is_linebreak(const char *pos)
|
|||||||
memcmp(pos - 2, LINEBREAK_WIN32, sizeof(LINEBREAK_WIN32)) == 0;
|
memcmp(pos - 2, LINEBREAK_WIN32, sizeof(LINEBREAK_WIN32)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read a line, but don't consume it
|
||||||
|
*/
|
||||||
static char *cfg_readline(git_config *cfg)
|
static char *cfg_readline(git_config *cfg)
|
||||||
{
|
{
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
@ -213,12 +216,41 @@ static char *cfg_readline(git_config *cfg)
|
|||||||
if (*line_end == '\0')
|
if (*line_end == '\0')
|
||||||
cfg->reader.eof = 1;
|
cfg->reader.eof = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
cfg->reader.line_number++;
|
cfg->reader.line_number++;
|
||||||
cfg->reader.read_ptr = line_end;
|
cfg->reader.read_ptr = line_end;
|
||||||
|
*/
|
||||||
|
|
||||||
return line;
|
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)
|
static inline int config_keychar(int c)
|
||||||
{
|
{
|
||||||
return isalnum(c) || c == '-';
|
return isalnum(c) || c == '-';
|
||||||
@ -388,17 +420,23 @@ static int config_parse(git_config *cfg_file)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': /* section header, new section begins */
|
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;
|
break;
|
||||||
|
|
||||||
default: /* assume variable declaration */
|
default: /* assume variable declaration */
|
||||||
error = parse_variable(cfg_file, current_section, line);
|
error = parse_variable(cfg_file, current_section, line);
|
||||||
|
cfg_consume_line(cfg_file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(current_section)
|
||||||
|
free(current_section);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user