From ea04d6b878ec4da073db925a594a0c2989e39791 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 7 Sep 2021 16:44:14 +0100 Subject: [PATCH] ocaml/guestfs-c.c: Avoid bogus -fanalyzer warning This warning is bogus, caused by the analyzer cannot track that len == 0 if roots == NULL. I just changed the code to make it easier to analyze, this doesn't fix any real bug. guestfs-c.c: In function 'guestfs_finalize': guestfs-c.c:85:9: error: dereference of NULL '0B' [CWE-476] [-Werror=analyzer-null-dereference] 85 | caml_remove_generational_global_root (roots[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- ocaml/guestfs-c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c index 339327ba8..ad62fbec0 100644 --- a/ocaml/guestfs-c.c +++ b/ocaml/guestfs-c.c @@ -79,7 +79,7 @@ guestfs_finalize (value gv) guestfs_close (g); /* Now unregister the global roots. */ - if (len > 0) { + if (roots && len > 0) { size_t i; for (i = 0; i < len; ++i) { caml_remove_generational_global_root (roots[i]);