Skip to content

Commit a4c0d46

Browse files
alexmvgitster
authored andcommitted
Make section_name_match start on '[', and return the length on success
Signed-off-by: Alex Vandiver <alex@chmrr.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 735c674 commit a4c0d46

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

config.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,9 @@ int git_config_set_multivar(const char *key, const char *value,
11741174
static int section_name_match (const char *buf, const char *name)
11751175
{
11761176
int i = 0, j = 0, dot = 0;
1177-
for (; buf[i] && buf[i] != ']'; i++) {
1177+
if (buf[i] != '[')
1178+
return 0;
1179+
for (i = 1; buf[i] && buf[i] != ']'; i++) {
11781180
if (!dot && isspace(buf[i])) {
11791181
dot = 1;
11801182
if (name[j++] != '.')
@@ -1195,7 +1197,17 @@ static int section_name_match (const char *buf, const char *name)
11951197
if (buf[i] != name[j++])
11961198
break;
11971199
}
1198-
return (buf[i] == ']' && name[j] == 0);
1200+
if (buf[i] == ']' && name[j] == 0) {
1201+
/*
1202+
* We match, now just find the right length offset by
1203+
* gobbling up any whitespace after it, as well
1204+
*/
1205+
i++;
1206+
for (; buf[i] && isspace(buf[i]); i++)
1207+
; /* do nothing */
1208+
return i;
1209+
}
1210+
return 0;
11991211
}
12001212

12011213
/* if new_name == NULL, the section is removed instead */
@@ -1229,7 +1241,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
12291241
; /* do nothing */
12301242
if (buf[i] == '[') {
12311243
/* it's a section */
1232-
if (section_name_match (&buf[i+1], old_name)) {
1244+
int offset = section_name_match(&buf[i], old_name);
1245+
if (offset > 0) {
12331246
ret++;
12341247
if (new_name == NULL) {
12351248
remove = 1;

0 commit comments

Comments
 (0)