Skip to content

Commit 2b71595

Browse files
agrngitster
authored andcommitted
sequencer: changes in parse_insn_buffer()
This clears the number of items of a todo_list before parsing it to allow to parse the same list multiple times without issues. As its items are not dynamically allocated, or don’t need to allocate memory, no additionnal memory management is required here. Furthermore, if a line is invalid, the type of the corresponding command is set to a garbage value, and its argument is defined properly. This will allow to recreate the text of a todo list from its commands, even if one of them is incorrect. Signed-off-by: Alban Gruin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cde5554 commit 2b71595

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sequencer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,8 @@ static int parse_insn_buffer(struct repository *r, char *buf,
21412141
char *p = buf, *next_p;
21422142
int i, res = 0, fixup_okay = file_exists(rebase_path_done());
21432143

2144+
todo_list->current = todo_list->nr = 0;
2145+
21442146
for (i = 1; *p; i++, p = next_p) {
21452147
char *eol = strchrnul(p, '\n');
21462148

@@ -2154,7 +2156,10 @@ static int parse_insn_buffer(struct repository *r, char *buf,
21542156
if (parse_insn_line(r, item, p, eol)) {
21552157
res = error(_("invalid line %d: %.*s"),
21562158
i, (int)(eol - p), p);
2157-
item->command = TODO_NOOP;
2159+
item->command = TODO_COMMENT + 1;
2160+
item->arg = p;
2161+
item->arg_len = (int)(eol - p);
2162+
item->commit = NULL;
21582163
}
21592164

21602165
if (fixup_okay)

0 commit comments

Comments
 (0)