aboutsummaryrefslogtreecommitdiff
path: root/libctf/testsuite/libctf-writable/ctf-compressed.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2025-05-12 12:31:00 +0100
committerNick Alcock <nick.alcock@oracle.com>2025-05-23 12:34:35 +0100
commit14303d6295e1bfd8a4e1b447057b78ce583be75d (patch)
treee6e0ee1b921a2c59e0465fbfe91b9927faeeda58 /libctf/testsuite/libctf-writable/ctf-compressed.c
parenta3d6596ecf1cac1f81f121cb23a815895ae70645 (diff)
downloadbinutils-14303d6295e1bfd8a4e1b447057b78ce583be75d.zip
binutils-14303d6295e1bfd8a4e1b447057b78ce583be75d.tar.gz
binutils-14303d6295e1bfd8a4e1b447057b78ce583be75d.tar.bz2
libctf: archive, open: when opening, always set errp to something
ctf_arc_import_parent, called by the cached-opening machinery used by ctf_archive_next and archive-wide lookup functions like ctf_arc_lookup_symbol, has an err-pointer parameter like all other opening functions. Unfortunately it unconditionally initializes it whenever provided, even if there was no error, which can lead to its being initialized to an uninitialized value. This is not technically an API-contract violation, since we don't define what happens to the error value except when an error happens, but it is still unpleasant. Initialize it only when there is an actual error, so we never initialize it to an uninitialized value. While we're at it, improve all the opening pathways: on success, set errp to 0, rather than leaving it what it was, reducing the likelihood of uninitialized error param returns in callers too. (This is inconsistent with the treatment of ctf_errno(), but the err value being a parameter passed in from outside makes the divergence acceptable: in open functions, you're never going to be overwriting some old error value someone might want to keep around across multiple calls, some of which are successful and some of which are not.) Soup up existing tests to verify all this. Thanks to Bruce McCulloch for the original patch, and Stephen Brennan for the report. libctf/ PR libctf/32903 * ctf-archive.c (ctf_arc_open_internal): Zero errp on success. (ctf_dict_open_sections): Zero errp at the start. (ctf_arc_import_parent): Intialize err. * ctf-open.c (ctf_bufopen): Zero errp at the start. * testsuite/libctf-lookup/add-to-opened.c: Make sure one-element archive opens update errp. * testsuite/libctf-writable/ctf-compressed.c: Make sure real archive opens update errp.
Diffstat (limited to 'libctf/testsuite/libctf-writable/ctf-compressed.c')
-rw-r--r--libctf/testsuite/libctf-writable/ctf-compressed.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/libctf/testsuite/libctf-writable/ctf-compressed.c b/libctf/testsuite/libctf-writable/ctf-compressed.c
index 4769cdb..646b603 100644
--- a/libctf/testsuite/libctf-writable/ctf-compressed.c
+++ b/libctf/testsuite/libctf-writable/ctf-compressed.c
@@ -119,10 +119,14 @@ main (int argc, char *argv[])
/* Dump the header of each archive member, and search for CTF_F_COMPRESS in
the resulting dump. */
+ err = 666;
while ((dump_fp = ctf_archive_next (final_arc, &i, NULL, 0, &err)) != NULL)
{
char *dumpstr;
+ if (err != 0)
+ fprintf (stderr, "err not set to success on success\n");
+
while ((dumpstr = ctf_dump (dump_fp, &dump_state, CTF_SECT_HEADER,
NULL, NULL)) != NULL)
{