Thread (191 messages) flat view 191 messages, 12 authors, 2022-02-03

Re: [PATCH v3 03/10] progress.c tests: make start/stop verbs on stdin

From: Taylor Blau <hidden>
Date: 2021-10-22 22:14:38

On Fri, Oct 22, 2021 at 04:18:16PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
quoted
 	progress_testing = 1;
-	progress = start_progress(title, total);
 	while (strbuf_getline(&line, stdin) != EOF) {
 		char *end;

-		if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
+		if (skip_prefix(line.buf, "start ", (const char **) &end)) {
+			uint64_t total = strtoull(end, &end, 10);
+			if (*end == '\0') {
+				progress = start_progress(default_title, total);
+			} else if (*end == ' ') {
+				item = string_list_insert(&list, end + 1);
+				progress = start_progress(item->string, total);
Why is it necessary to use a string_list here?  This is the only place
where it is used, so I don't understand why we should store anything
in it.
The progress.c API doesn't xstrdup() the title you give it, so you can't
free() it after while it's alive.

Here we're re-setting the same strbuf in a loop, so if we hand a "title"
to progress.c we need to keep it around, when we later add a BUG
assertion in 10/10:

+	if (global_progress)
+		BUG("'%s' progress still active when trying to start '%s'",
+		    global_progress->title, progress->title);
+	global_progress = progress;

The "old" title would point to already-free'd or to a nonsensical value
if we didn't do that.
*nod*. I figured as much, but a comment indicating that may be helpful
for reviewers and future readers of this code.

Thanks,
Taylor
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help