git/t/helper
Jeff King f8535596aa bug_fl(): correctly initialize trace2 va_list
The code added 0cc05b044f (usage.c: add a non-fatal bug() function to go
with BUG(), 2022-06-02) sets up two va_list variables: one to output to
stderr, and one to trace2. But the order of initialization is wrong:

  va_list ap, cp;
  va_copy(cp, ap);
  va_start(ap, fmt);

We copy the contents of "ap" into "cp" before it is initialized, meaning
it is full of garbage. The two should be swapped.

However, there's another bug, noticed by Johannes Schindelin: we forget
to call va_end() for the copy. So instead of just fixing the copy's
initialization, let's do two separate start/end pairs. This is allowed
by the standard, and we don't need to use copy here since we have access
to the original varargs. Matching the pairs with the calls makes it more
obvious that everything is being done correctly.

Note that we do call bug_fl() in the tests, but it didn't trigger this
problem because our format string doesn't have any placeholders. So even
though we were passing a garbage va_list through the stack, nobody ever
needed to look at it. We can easily adjust one of the trace2 tests to
trigger this, both for bug() and for BUG(). The latter isn't broken, but
it's nice to exercise both a bit more. Without the fix in this patch
(but with the test change), the bug() case causes a segfault.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-06-16 13:28:22 -07:00
..
.gitignore
test-advise.c
test-bitmap.c t/helper/test-bitmap.c: add 'dump-hashes' mode 2021-09-14 16:34:17 -07:00
test-bloom.c
test-chmtime.c t/helper/test-chmtime: skip directories on Windows 2022-03-25 16:04:17 -07:00
test-config.c
test-crontab.c
test-csprng.c wrapper: add a helper to generate numbers from a CSPRNG 2022-01-17 14:17:48 -08:00
test-ctype.c
test-date.c date API: add and use a date_mode_release() 2022-02-16 09:40:00 -08:00
test-delta.c
test-dir-iterator.c
test-drop-caches.c lazyload: use correct calling conventions 2022-01-09 10:34:53 -08:00
test-dump-cache-tree.c
test-dump-fsmonitor.c
test-dump-split-index.c
test-dump-untracked-cache.c environment.c: remove test-specific "ignore_untracked..." variable 2021-09-22 13:15:00 -07:00
test-example-decorate.c
test-fake-ssh.c
test-fast-rebase.c
test-fsmonitor-client.c t/helper/fsmonitor-client: create IPC client to talk to FSMonitor Daemon 2022-03-25 16:04:16 -07:00
test-genrandom.c
test-genzeros.c test-tool genzeros: generate large amounts of data more efficiently 2021-11-03 11:22:26 -07:00
test-getcwd.c t0001: fix broken not-quite getcwd(3) test in bed67874e2 2021-07-30 10:18:27 -07:00
test-hash-speed.c
test-hash.c
test-hashmap.c
test-index-version.c
test-json-writer.c
test-lazy-init-name-hash.c
test-match-trees.c
test-mergesort.c test-mergesort: use repeatable random numbers 2021-10-08 10:04:56 -07:00
test-mktemp.c
test-oid-array.c tests: fix test-oid-array leak, test in SANITIZE=leak 2021-10-07 15:40:15 -07:00
test-oidmap.c
test-oidtree.c tests: fix a memory leak in test-oidtree.c 2021-10-07 15:40:15 -07:00
test-online-cpus.c
test-parse-options.c tests: fix a memory leak in test-parse-options.c 2021-10-07 15:40:15 -07:00
test-parse-pathspec-file.c
test-partial-clone.c
test-path-utils.c
test-pcre2-config.c
test-pkt-line.c
test-prio-queue.c tests: fix a memory leak in test-prio-queue.c 2021-10-07 15:40:15 -07:00
test-proc-receive.c
test-progress.c progress.c tests: make start/stop commands on stdin 2022-02-03 15:39:55 -08:00
test-reach.c
test-read-cache.c test-read-cache: remove --table, --expand options 2021-12-22 11:42:40 -08:00
test-read-graph.c test-read-graph: include extra post-parse info 2022-03-01 12:09:55 -08:00
test-read-midx.c t/helper/test-read-midx.c: free MIDX within read_midx_file() 2021-10-27 16:26:37 -07:00
test-ref-store.c refs API: remove "failure_errno" from refs_resolve_ref_unsafe() 2022-01-26 15:58:41 -08:00
test-reftable.c reftable: order unittests by complexity 2022-01-20 11:31:53 -08:00
test-regex.c
test-repository.c
test-revision-walking.c
test-run-command.c Merge branch 'ep/remove-duplicated-includes' 2022-03-23 14:09:30 -07:00
test-scrap-cache-tree.c
test-serve-v2.c serve.[ch]: remove "serve_options", split up --advertise-refs code 2021-08-05 08:59:37 -07:00
test-sha1.c
test-sha1.sh
test-sha256.c
test-sigchain.c
test-simple-ipc.c t/helper/simple-ipc: convert test-simple-ipc to use start_bg_command 2021-09-20 08:57:58 -07:00
test-strcmp-offset.c
test-string-list.c
test-submodule-config.c
test-submodule-nested-repo-config.c repository: support unabsorbed in repo_submodule_init 2021-09-09 14:09:30 -07:00
test-subprocess.c run-command API users: use strvec_pushv(), not argv assignment 2021-11-25 22:15:07 -08:00
test-tool.c t/helper/fsmonitor-client: create IPC client to talk to FSMonitor Daemon 2022-03-25 16:04:16 -07:00
test-tool.h t/helper/fsmonitor-client: create IPC client to talk to FSMonitor Daemon 2022-03-25 16:04:16 -07:00
test-trace2.c bug_fl(): correctly initialize trace2 va_list 2022-06-16 13:28:22 -07:00
test-urlmatch-normalization.c
test-userdiff.c
test-wildmatch.c
test-windows-named-pipe.c
test-write-cache.c
test-xml-encode.c