diff options
author | Colin Walters <walters@verbum.org> | 2022-11-26 10:19:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-26 10:19:30 -0500 |
commit | 7b4f1b7699eb177e0acd06bcc1dafeb006f84cb2 (patch) | |
tree | 3c1ba4c924354e4a81e4a8f445811bc7261c81b3 | |
parent | aafabc56a211a6d64fd26cf8db079acd75e1b55b (diff) | |
parent | 2034ed04193dd3b595292f9974da82d2ed26b544 (diff) | |
download | ostree-7b4f1b7699eb177e0acd06bcc1dafeb006f84cb2.tar.gz |
Merge pull request #2788 from lucab/ups/lib-assertions
lib: assert more invariants
-rw-r--r-- | src/libostree/ostree-async-progress.c | 10 | ||||
-rw-r--r-- | src/libostree/ostree-checksum-input-stream.c | 15 | ||||
-rw-r--r-- | src/libostree/ostree-date-utils.c | 6 | ||||
-rw-r--r-- | src/libostree/ostree-gpg-verifier.c | 2 | ||||
-rw-r--r-- | src/libostree/ostree-repo-static-delta-compilation.c | 3 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot-cleanup.c | 4 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot-deploy.c | 6 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot-upgrader.c | 4 |
8 files changed, 27 insertions, 23 deletions
diff --git a/src/libostree/ostree-async-progress.c b/src/libostree/ostree-async-progress.c index edbde11c..8a780372 100644 --- a/src/libostree/ostree-async-progress.c +++ b/src/libostree/ostree-async-progress.c @@ -128,10 +128,12 @@ GVariant * ostree_async_progress_get_variant (OstreeAsyncProgress *self, const char *key) { + g_assert (OSTREE_IS_ASYNC_PROGRESS (self)); + GVariant *rval; - g_return_val_if_fail (OSTREE_IS_ASYNC_PROGRESS (self), NULL); - g_return_val_if_fail (key != NULL, NULL); + if (key == NULL) + return NULL; /* Early return */ g_mutex_lock (&self->lock); rval = g_hash_table_lookup (self->values, GUINT_TO_POINTER (g_quark_from_string (key))); @@ -437,8 +439,8 @@ void ostree_async_progress_copy_state (OstreeAsyncProgress *self, OstreeAsyncProgress *dest) { - g_return_if_fail (OSTREE_IS_ASYNC_PROGRESS (self)); - g_return_if_fail (OSTREE_IS_ASYNC_PROGRESS (dest)); + g_assert (OSTREE_IS_ASYNC_PROGRESS (self)); + g_assert (OSTREE_IS_ASYNC_PROGRESS (dest)); g_mutex_lock (&self->lock); diff --git a/src/libostree/ostree-checksum-input-stream.c b/src/libostree/ostree-checksum-input-stream.c index 7cdf2048..9747515e 100644 --- a/src/libostree/ostree-checksum-input-stream.c +++ b/src/libostree/ostree-checksum-input-stream.c @@ -124,16 +124,15 @@ OstreeChecksumInputStream * ostree_checksum_input_stream_new (GInputStream *base, GChecksum *checksum) { - OstreeChecksumInputStream *stream; + g_assert (G_IS_INPUT_STREAM (base)); - g_return_val_if_fail (G_IS_INPUT_STREAM (base), NULL); + OstreeChecksumInputStream *stream = g_object_new ( + OSTREE_TYPE_CHECKSUM_INPUT_STREAM, + "base-stream", base, + "checksum", checksum, + NULL); - stream = g_object_new (OSTREE_TYPE_CHECKSUM_INPUT_STREAM, - "base-stream", base, - "checksum", checksum, - NULL); - - return (OstreeChecksumInputStream*) (stream); + return stream; } static gssize diff --git a/src/libostree/ostree-date-utils.c b/src/libostree/ostree-date-utils.c index a7156911..7c078a96 100644 --- a/src/libostree/ostree-date-utils.c +++ b/src/libostree/ostree-date-utils.c @@ -40,8 +40,10 @@ parse_uint (const char *buf, const char *end_ptr = NULL; gint saved_errno = 0; - g_return_val_if_fail (n_digits == 2 || n_digits == 4, FALSE); - g_return_val_if_fail (out != NULL, FALSE); + g_assert (out != NULL); + + if(!(n_digits == 2 || n_digits == 4)) + return FALSE; errno = 0; number = g_ascii_strtoull (buf, (gchar **)&end_ptr, 10); diff --git a/src/libostree/ostree-gpg-verifier.c b/src/libostree/ostree-gpg-verifier.c index 1c8d9464..8301907c 100644 --- a/src/libostree/ostree-gpg-verifier.c +++ b/src/libostree/ostree-gpg-verifier.c @@ -549,7 +549,7 @@ _ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (OSTREE_IS_GPG_VERIFIER (self), FALSE); + g_assert (OSTREE_IS_GPG_VERIFIER (self)); const char *global_keyring_path = g_getenv ("OSTREE_GPG_HOME"); if (global_keyring_path == NULL) diff --git a/src/libostree/ostree-repo-static-delta-compilation.c b/src/libostree/ostree-repo-static-delta-compilation.c index dece876e..1e3af0d8 100644 --- a/src/libostree/ostree-repo-static-delta-compilation.c +++ b/src/libostree/ostree-repo-static-delta-compilation.c @@ -1384,7 +1384,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, builder.max_chunk_size_bytes = ((guint64)max_chunk_size) * 1000 * 1000; (void) g_variant_lookup (params, "endianness", "u", &endianness); - g_return_val_if_fail (endianness == G_BIG_ENDIAN || endianness == G_LITTLE_ENDIAN, FALSE); + if (!(endianness == G_BIG_ENDIAN || endianness == G_LITTLE_ENDIAN)) + return glnx_throw (error, "Invalid endianness parameter"); builder.swap_endian = endianness != G_BYTE_ORDER; builder.parts = builder_parts; diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c index 3471cac7..51f87b03 100644 --- a/src/libostree/ostree-sysroot-cleanup.c +++ b/src/libostree/ostree-sysroot-cleanup.c @@ -578,8 +578,8 @@ _ostree_sysroot_cleanup_internal (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (OSTREE_IS_SYSROOT (self), FALSE); - g_return_val_if_fail (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED, FALSE); + g_assert (OSTREE_IS_SYSROOT (self)); + g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 26b07080..482124e2 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2755,7 +2755,7 @@ sysroot_initialize_deployment (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (osname != NULL || self->booted_deployment != NULL, FALSE); + g_assert (osname != NULL || self->booted_deployment != NULL); if (osname == NULL) osname = ostree_deployment_get_osname (self->booted_deployment); @@ -3198,8 +3198,8 @@ ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - g_return_val_if_fail (fd != -1, FALSE); - g_return_val_if_fail (out_checksum != NULL, FALSE); + g_assert (fd != -1); + g_assert (out_checksum != NULL); if (!glnx_shutil_mkdir_p_at (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR, 0755, cancellable, error)) diff --git a/src/libostree/ostree-sysroot-upgrader.c b/src/libostree/ostree-sysroot-upgrader.c index 58f8ecd0..b8d2d0c9 100644 --- a/src/libostree/ostree-sysroot-upgrader.c +++ b/src/libostree/ostree-sysroot-upgrader.c @@ -340,9 +340,9 @@ ostree_sysroot_upgrader_get_origin (OstreeSysrootUpgrader *self) GKeyFile * ostree_sysroot_upgrader_dup_origin (OstreeSysrootUpgrader *self) { - GKeyFile *copy = NULL; + g_assert (OSTREE_IS_SYSROOT_UPGRADER (self)); - g_return_val_if_fail (OSTREE_IS_SYSROOT_UPGRADER (self), NULL); + GKeyFile *copy = NULL; if (self->origin != NULL) { |