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 <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alban Gruin committed
Dec 29, 2018 at 17:03 UTC
2b71595d47a75031346d7bc0125da39a9bb10126
1 file changed
+6
-1
sequencer.c
+6
-1
@@ -2141,6 +2141,8 @@ static int parse_insn_buffer(struct repository *r, char *buf,
2141
char *p = buf, *next_p;
2142
int i, res = 0, fixup_okay = file_exists(rebase_path_done());
2143
2144
+ todo_list->current = todo_list->nr = 0;
2145
+
2146
for (i = 1; *p; i++, p = next_p) {
2147
char *eol = strchrnul(p, '\n');
2148
@@ -2154,7 +2156,10 @@ static int parse_insn_buffer(struct repository *r, char *buf,
2156
if (parse_insn_line(r, item, p, eol)) {
2157
res = error(_("invalid line %d: %.*s"),
2158
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;
2163
}
2164
2165
if (fixup_okay)