sysroot: Fix gcc `-fanalyzer` warning
authorColin Walters <walters@verbum.org>
Fri, 8 Oct 2021 12:59:52 +0000 (08:59 -0400)
committerColin Walters <walters@verbum.org>
Wed, 13 Oct 2021 21:13:14 +0000 (17:13 -0400)
In general, we're probably going to need to change most of our
`g_return_if_fail` to `g_assert`.  The analyzer flags that
the function can return `NULL`, but the caller isn't prepared for
this.

In practice, let's abort.

src/libostree/ostree-sysroot.c

index be5306b7716844ab12086c888b103eed185434be..04432cbcf1cb34cb37965bd8595c89d742182474 100644 (file)
@@ -1235,12 +1235,15 @@ ostree_sysroot_get_subbootversion (OstreeSysroot   *self)
  * ostree_sysroot_get_booted_deployment:
  * @self: Sysroot
  *
+ * This function may only be called if the sysroot is loaded.
+ *
  * Returns: (transfer none) (nullable): The currently booted deployment, or %NULL if none
  */
 OstreeDeployment *
 ostree_sysroot_get_booted_deployment (OstreeSysroot       *self)
 {
-  g_return_val_if_fail (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED, NULL);
+  g_assert (self);
+  g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED);
 
   return self->booted_deployment;
 }
@@ -1390,7 +1393,8 @@ ostree_sysroot_get_repo (OstreeSysroot         *self,
 OstreeRepo *
 ostree_sysroot_repo (OstreeSysroot *self)
 {
-  g_return_val_if_fail (self->loadstate >= OSTREE_SYSROOT_LOAD_STATE_LOADED, NULL);
+  g_assert (self);
+  g_assert (self->loadstate >= OSTREE_SYSROOT_LOAD_STATE_LOADED);
   g_assert (self->repo);
   return self->repo;
 }