[gnome-software/wip/mcrha/static-analyzers-fixes] Misc: Fix various warnings reported by static analyzers



commit 8edb3853fc6e5a9bf6eebca438cbad5a97fb6207
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 18 17:21:25 2021 +0200

    Misc: Fix various warnings reported by static analyzers
    
    These had been reported by Coverity Scan, Clang and gcc static
    analyzers.

 lib/gs-app.c                              | 3 ++-
 lib/gs-key-colors.c                       | 3 +++
 lib/gs-utils.c                            | 6 +++---
 lib/tools/profile-key-colors.c            | 3 +++
 plugins/core/gs-plugin-appstream.c        | 4 ++--
 plugins/flatpak/gs-flatpak.c              | 8 ++++----
 plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 3 +--
 7 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 06fffb684..169af6145 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -489,10 +489,11 @@ gs_app_kudos_to_string (guint64 kudos)
 gchar *
 gs_app_to_string (GsApp *app)
 {
-       GString *str = g_string_new ("GsApp:");
+       GString *str;
 
        g_return_val_if_fail (GS_IS_APP (app), NULL);
 
+       str = g_string_new ("GsApp:");
        gs_app_to_string_append (app, str);
        if (str->len > 0)
                g_string_truncate (str, str->len - 1);
diff --git a/lib/gs-key-colors.c b/lib/gs-key-colors.c
index 95cf53b15..34b1f8767 100644
--- a/lib/gs-key-colors.c
+++ b/lib/gs-key-colors.c
@@ -180,6 +180,9 @@ k_means (GArray    *colors,
        pixels = (ClusterPixel8 *) raw_pixels;
        pixels_end = &pixels[height * width];
 
+       memset (cluster_centres, 0, sizeof (cluster_centres));
+       memset (cluster_accumulators, 0, sizeof (cluster_accumulators));
+
        /* Initialise the clusters using the Random Partition method: randomly
         * assign a starting cluster to each pixel.
         *
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 86377e295..537a20f9f 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1301,7 +1301,7 @@ gs_pixbuf_blur_private (GdkPixbuf *src, GdkPixbuf *dest, guint radius, guint8 *d
        gint width, height, src_rowstride, dest_rowstride, n_channels;
        guchar *p_src, *p_dest, *c1, *c2;
        gint x, y, i, i1, i2, width_minus_1, height_minus_1, radius_plus_1;
-       gint r, g, b, a;
+       gint r, g, b;
        guchar *p_dest_row, *p_dest_col;
 
        width = gdk_pixbuf_get_width (src);
@@ -1318,7 +1318,7 @@ gs_pixbuf_blur_private (GdkPixbuf *src, GdkPixbuf *dest, guint radius, guint8 *d
        for (y = 0; y < height; y++) {
 
                /* calc the initial sums of the kernel */
-               r = g = b = a = 0;
+               r = g = b = 0;
                for (i = -radius; i <= (gint) radius; i++) {
                        c1 = p_src + (CLAMP (i, 0, width_minus_1) * n_channels);
                        r += c1[0];
@@ -1365,7 +1365,7 @@ gs_pixbuf_blur_private (GdkPixbuf *src, GdkPixbuf *dest, guint radius, guint8 *d
        for (x = 0; x < width; x++) {
 
                /* calc the initial sums of the kernel */
-               r = g = b = a = 0;
+               r = g = b = 0;
                for (i = -radius; i <= (gint) radius; i++) {
                        c1 = p_src + (CLAMP (i, 0, height_minus_1) * src_rowstride);
                        r += c1[0];
diff --git a/lib/tools/profile-key-colors.c b/lib/tools/profile-key-colors.c
index f8bab229a..44df6a42a 100644
--- a/lib/tools/profile-key-colors.c
+++ b/lib/tools/profile-key-colors.c
@@ -104,6 +104,9 @@ main (void)
                g_ptr_array_add (pixbufs, g_steal_pointer (&pixbuf));
        }
 
+       if (!pixbufs->len)
+               return 2;
+
        /* Set up an output page */
        g_string_append (html_output,
                         "<!DOCTYPE html>\n"
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 5b49b5ce0..042ebbb92 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -247,7 +247,7 @@ gs_plugin_appstream_load_desktop_cb (XbBuilderSource *self,
        xml = as_component_to_xml_data (cpt, actx, error);
        if (xml == NULL)
                return NULL;
-       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), -1, g_free);
+       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), (gssize) -1, g_free);
 }
 
 static gboolean
@@ -365,7 +365,7 @@ gs_plugin_appstream_load_dep11_cb (XbBuilderSource *self,
                xml = g_strdup("");
        }
 
-       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), -1, g_free);
+       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), (gssize) -1, g_free);
 }
 
 #if LIBXMLB_CHECK_VERSION(0,3,1)
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 88bb69a72..997cfbf3d 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -864,7 +864,7 @@ gs_plugin_appstream_load_desktop_cb (XbBuilderSource *self,
        if (xml == NULL)
                return NULL;
 
-       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), -1, g_free);
+       return g_memory_input_stream_new_from_data (g_steal_pointer (&xml), (gssize) -1, g_free);
 }
 
 static gboolean
@@ -1210,12 +1210,12 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
                return FALSE;
        }
        for (guint i = 0; i < xremotes->len; i++) {
-               const gchar *remote_name;
                guint tmp;
                g_autoptr(GError) error_local = NULL;
                g_autoptr(GFile) file = NULL;
                g_autoptr(GFile) file_timestamp = NULL;
                g_autofree gchar *appstream_fn = NULL;
+               g_autofree gchar *remote_name = NULL;
                FlatpakRemote *xremote = g_ptr_array_index (xremotes, i);
                g_autoptr(GMutexLocker) locker = NULL;
 
@@ -1226,7 +1226,7 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
                locker = g_mutex_locker_new (&self->broken_remotes_mutex);
 
                /* skip known-broken repos */
-               remote_name = flatpak_remote_get_name (xremote);
+               remote_name = g_strdup (flatpak_remote_get_name (xremote));
                if (g_hash_table_lookup (self->broken_remotes, remote_name) != NULL) {
                        g_debug ("skipping known broken remote: %s", remote_name);
                        continue;
@@ -1263,7 +1263,7 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
 
                                /* don't try to fetch this again until refresh() */
                                g_hash_table_insert (self->broken_remotes,
-                                                    g_strdup (remote_name),
+                                                    g_steal_pointer (&remote_name),
                                                     GUINT_TO_POINTER (1));
                                continue;
                        }
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 2175f06f9..53085245f 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -2003,7 +2003,6 @@ gs_plugin_file_to_app (GsPlugin *plugin,
 {
        gboolean ret = FALSE;
        FD_t rpmfd = NULL;
-       int r;
        guint64 epoch;
        guint64 size;
        const gchar *name;
@@ -2043,7 +2042,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
                goto out;
        }
 
-       if ((r = rpmReadPackageFile (ts, rpmfd, filename, &h)) != RPMRC_OK) {
+       if (rpmReadPackageFile (ts, rpmfd, filename, &h) != RPMRC_OK) {
                g_set_error (error,
                             GS_PLUGIN_ERROR,
                             GS_PLUGIN_ERROR_FAILED,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]