diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index d057ea34..8c5d9411 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -1588,7 +1588,6 @@ ostree_repo_prepare_transaction (OstreeRepo *self, GCancellable *cancellable, GError **error) { - g_autoptr(_OstreeRepoAutoTransaction) txn = NULL; guint64 reserved_bytes = 0; g_return_val_if_fail (self->in_transaction == FALSE, FALSE); @@ -1596,7 +1595,8 @@ ostree_repo_prepare_transaction (OstreeRepo *self, g_debug ("Preparing transaction in repository %p", self); /* Set up to abort the transaction if we return early from this function. */ - txn = self; + g_autoptr(_OstreeRepoAutoTransaction) txn = self; + (void) txn; /* Add use to silence static analysis */ memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats)); @@ -1652,7 +1652,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self, return FALSE; /* Success: do not abort the transaction when returning. */ - txn = NULL; + txn = NULL; (void) txn; if (out_transaction_resume) *out_transaction_resume = ret_transaction_resume; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index ba6e7289..bcb8b420 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -2181,7 +2181,6 @@ static void start_fetch (OtPullData *pull_data, FetchObjectData *fetch) { - gboolean is_meta; g_autofree char *obj_subpath = NULL; guint64 *expected_max_size_p; guint64 expected_max_size; @@ -2190,13 +2189,12 @@ start_fetch (OtPullData *pull_data, GPtrArray *mirrorlist = NULL; ostree_object_name_deserialize (fetch->object, &expected_checksum, &objtype); - is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype); g_debug ("starting fetch of %s.%s%s", expected_checksum, ostree_object_type_to_string (objtype), fetch->is_detached_meta ? " (detached)" : ""); - is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype); + gboolean is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype); if (is_meta) pull_data->n_outstanding_metadata_fetches++; else diff --git a/src/libotutil/ot-checksum-utils.c b/src/libotutil/ot-checksum-utils.c index 6eb6fdc0..66767368 100644 --- a/src/libotutil/ot-checksum-utils.c +++ b/src/libotutil/ot-checksum-utils.c @@ -250,9 +250,8 @@ ot_gio_splice_get_checksum (GOutputStream *out, guint8 digest[_OSTREE_SHA256_DIGEST_LEN]; ot_checksum_get_digest (&checksum, digest, sizeof (digest)); - g_autofree guchar *ret_csum = g_malloc (sizeof (digest)); - memcpy (ret_csum, digest, sizeof (digest)); - ot_transfer_out_value (out_csum, &ret_csum); + if (out_csum) + *out_csum = g_memdup (digest, sizeof (digest)); return TRUE; } diff --git a/src/libotutil/ot-variant-builder.c b/src/libotutil/ot-variant-builder.c index 5b331e62..6636068e 100644 --- a/src/libotutil/ot-variant-builder.c +++ b/src/libotutil/ot-variant-builder.c @@ -1150,14 +1150,8 @@ ot_variant_builder_end (OtVariantBuilder *builder, GError **error) { OtVariantBuilderInfo *info = builder->head; - gsize total_size; - gsize offset_size; - int i; - g_autofree guchar *offset_table = NULL; - gsize offset_table_size; gboolean add_offset_table = FALSE; gboolean reverse_offset_table = FALSE; - guchar *p; g_return_val_if_fail (info->n_children >= info->min_items, FALSE); @@ -1188,15 +1182,14 @@ ot_variant_builder_end (OtVariantBuilder *builder, if (add_offset_table) { - total_size = gvs_calculate_total_size (info->offset, info->child_ends->len); - offset_size = gvs_get_offset_size (total_size); - - offset_table_size = total_size - info->offset; - offset_table = g_malloc (offset_table_size); - p = offset_table; + const gsize total_size = gvs_calculate_total_size (info->offset, info->child_ends->len); + const gsize offset_size = gvs_get_offset_size (total_size); + const gsize offset_table_size = total_size - info->offset; + g_autofree guchar *offset_table = g_malloc (offset_table_size); + guchar *p = offset_table; if (reverse_offset_table) { - for (i = info->child_ends->len - 1; i >= 0; i--) + for (int i = info->child_ends->len - 1; i >= 0; i--) { gvs_write_unaligned_le (p, g_array_index (info->child_ends, guint64, i), offset_size); p += offset_size; @@ -1204,7 +1197,7 @@ ot_variant_builder_end (OtVariantBuilder *builder, } else { - for (i = 0; i < info->child_ends->len; i++) + for (int i = 0; i < info->child_ends->len; i++) { gvs_write_unaligned_le (p, g_array_index (info->child_ends, guint64, i), offset_size); p += offset_size; diff --git a/tests/libostreetest.c b/tests/libostreetest.c index 9a2fae09..1efee40e 100644 --- a/tests/libostreetest.c +++ b/tests/libostreetest.c @@ -145,7 +145,7 @@ ot_test_setup_sysroot (GCancellable *cancellable, g_autoptr(GString) buf = g_string_new ("mutable-deployments"); - gboolean can_relabel; + gboolean can_relabel = FALSE; if (!ot_check_relabeling (&can_relabel, error)) return FALSE; if (!can_relabel) diff --git a/tests/test-keyfile-utils.c b/tests/test-keyfile-utils.c index 258e7dd8..c580f81c 100644 --- a/tests/test-keyfile-utils.c +++ b/tests/test-keyfile-utils.c @@ -199,16 +199,15 @@ test_get_value_with_default_group_optional (void) static void test_copy_group (void) { - g_auto(GStrv) keys = NULL; - g_auto(GStrv) keys2 = NULL; - gsize length, length2, ii; - GKeyFile *tmp = g_key_file_new (); + gsize length, length2; const char *section = "section"; GLogLevelFlags always_fatal_mask; /* Avoid that g_return_val_if_fail causes the test to fail. */ always_fatal_mask = g_log_set_always_fatal (0); + g_autoptr(GKeyFile) tmp = g_key_file_new (); + g_assert_false (ot_keyfile_copy_group (NULL, tmp, section)); g_assert_false (ot_keyfile_copy_group (g_keyfile, NULL, section)); g_assert_false (ot_keyfile_copy_group (g_keyfile, tmp, NULL)); @@ -218,21 +217,17 @@ test_copy_group (void) g_assert_true (ot_keyfile_copy_group (g_keyfile, tmp, section)); - keys = g_key_file_get_keys (g_keyfile, section, &length, NULL); - keys2 = g_key_file_get_keys (tmp, section, &length2, NULL); + g_auto(GStrv) keys = g_key_file_get_keys (g_keyfile, section, &length, NULL); + g_strfreev (g_key_file_get_keys (tmp, section, &length2, NULL)); g_assert_cmpint(length, ==, length2); - for (ii = 0; ii < length; ii++) + for (gsize ii = 0; ii < length; ii++) { - g_autofree char *value = NULL; - g_autofree char *value2 = NULL; - - value = g_key_file_get_value (g_keyfile, section, keys[ii], NULL); - value2 = g_key_file_get_value (g_keyfile, section, keys[ii], NULL); + g_autofree char *value = g_key_file_get_value (g_keyfile, section, keys[ii], NULL); + g_autofree char *value2 = g_key_file_get_value (g_keyfile, section, keys[ii], NULL); g_assert_cmpstr (value, ==, value2); } - g_key_file_free (tmp); } static void