From 4a38b1115973a8cd00608dc7bc4df96ae93bb79e Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 16 Oct 2019 13:38:29 +0000 Subject: [PATCH 1/3] commit: [scan-build] Remove a dead assignment The `write_commit()` API defaults to current time, and this assignment became dead in: https://github.com/ostreedev/ostree/commit/8ba90a33410c9707a30a77f808a7ec712d465165 --- src/ostree/ot-builtin-commit.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 43eb18b3..0eea09d7 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -772,8 +772,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!skip_commit) { - guint64 timestamp; - if (!opt_no_bindings) { g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); @@ -782,10 +780,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!opt_timestamp) { - GDateTime *now = g_date_time_new_now_utc (); - timestamp = g_date_time_to_unix (now); - g_date_time_unref (now); - if (!ostree_repo_write_commit (repo, parent, opt_subject, commit_body, metadata, OSTREE_REPO_FILE (root), &commit_checksum, cancellable, error)) @@ -800,8 +794,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio "Could not parse '%s'", opt_timestamp); goto out; } - timestamp = ts.tv_sec; + guint64 timestamp = ts.tv_sec; if (!ostree_repo_write_commit_with_time (repo, parent, opt_subject, commit_body, metadata, OSTREE_REPO_FILE (root), timestamp, From a8dc90b02fbbd7b951be59704d4c5969463ab8f2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 16 Oct 2019 13:44:46 +0000 Subject: [PATCH 2/3] tree-wide: [scan-build]: Add some asserts that pointers are non-NULL More "scan-build doesn't understand GError and our out-param conventions" AKA "these errors would be impossible with Rust's sum type Result<> approach". --- src/libostree/ostree-sysroot-cleanup.c | 1 + src/libostree/ostree-sysroot.c | 1 + src/ostree/ot-builtin-fsck.c | 1 + src/ostree/ot-dump.c | 5 ++++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c index 7a352e6b..ef95d13c 100644 --- a/src/libostree/ostree-sysroot-cleanup.c +++ b/src/libostree/ostree-sysroot-cleanup.c @@ -313,6 +313,7 @@ cleanup_old_deployments (OstreeSysroot *self, if (!list_all_deployment_directories (self, &all_deployment_dirs, cancellable, error)) return FALSE; + g_assert (all_deployment_dirs); /* Pacify static analysis */ for (guint i = 0; i < all_deployment_dirs->len; i++) { OstreeDeployment *deployment = all_deployment_dirs->pdata[i]; diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index e17cc233..1c9dbf37 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -945,6 +945,7 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self, g_autoptr(GPtrArray) deployments = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_assert (boot_loader_configs); /* Pacify static analysis */ for (guint i = 0; i < boot_loader_configs->len; i++) { OstreeBootconfigParser *config = boot_loader_configs->pdata[i]; diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index 5ad3bf38..dea03af4 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -434,6 +434,7 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, if (opt_add_tombstones) { guint i; + g_assert (tombstones); /* Pacify static analysis */ if (tombstones->len) { if (!ot_enable_tombstone_commits (repo, error)) diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c index 1ef63740..38f3730b 100644 --- a/src/ostree/ot-dump.c +++ b/src/ostree/ot-dump.c @@ -125,7 +125,10 @@ dump_commit (GVariant *variant, timestamp = GUINT64_FROM_BE (timestamp); str = format_timestamp (timestamp, &local_error); if (!str) - errx (1, "Failed to read commit: %s", local_error->message); + { + g_assert (local_error); /* Pacify static analysis */ + errx (1, "Failed to read commit: %s", local_error->message); + } g_autofree char *contents = ostree_commit_get_content_checksum (variant) ?: ""; g_print ("ContentChecksum: %s\n", contents); g_print ("Date: %s\n", str); From 946659aacf08bc238e3ceda4475a855c165b06c5 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 16 Oct 2019 13:48:20 +0000 Subject: [PATCH 3/3] prune: [scan-build] Initialize a variable Another false positive because we only read this if `opt_keep_younger_than` is `TRUE`, but let's initialize variables on general principle. --- src/ostree/ot-builtin-prune.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index 2f560d14..fd2ab05f 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -205,7 +205,7 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation g_autoptr(GHashTable) all_refs = NULL; g_autoptr(GHashTable) reachable = ostree_repo_traverse_new_reachable (); g_autoptr(GHashTable) retain_branch_depth = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - struct timespec keep_younger_than_ts; + struct timespec keep_younger_than_ts = {0, }; GHashTableIter hash_iter; gpointer key, value;