[gnome-software/wip/mcrha/static-analyzers-fixes: 7/7] Misc: Fix various warnings reported by static analyzers
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/mcrha/static-analyzers-fixes: 7/7] Misc: Fix various warnings reported by static analyzers
- Date: Wed, 20 Oct 2021 10:34:01 +0000 (UTC)
commit 843c9a3ef274f738ca54bf5a8e19dd6ae757214c
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 | 2 ++
lib/gs-utils.c | 6 +++---
lib/tools/profile-key-colors.c | 3 +++
plugins/core/gs-plugin-appstream.c | 4 ++--
plugins/flatpak/gs-flatpak.c | 4 ++--
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 3 +--
7 files changed, 15 insertions(+), 10 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..ef2d6d01c 100644
--- a/lib/gs-key-colors.c
+++ b/lib/gs-key-colors.c
@@ -180,6 +180,8 @@ k_means (GArray *colors,
pixels = (ClusterPixel8 *) raw_pixels;
pixels_end = &pixels[height * width];
+ memset (cluster_centres, 0, sizeof (cluster_centres));
+
/* 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 d61998a09..cafe1f549 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
@@ -1223,10 +1223,10 @@ gs_flatpak_refresh_appstream (GsFlatpak *self, guint cache_age,
if (flatpak_remote_get_disabled (xremote))
continue;
+ remote_name = flatpak_remote_get_name (xremote);
locker = g_mutex_locker_new (&self->broken_remotes_mutex);
/* skip known-broken repos */
- remote_name = 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;
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 273ccb181..d9bf29d0d 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]