Merge branch 'static-analysis-fixes' into 'main'

tests: Various static analysis fixes

See merge request GNOME/glib!2731
This commit is contained in:
Sebastian Dröge 2022-06-07 10:50:18 +00:00
commit 5de59d34e1
5 changed files with 27 additions and 11 deletions

View File

@ -249,14 +249,14 @@ int
main (int argc,
char *argv[])
{
GSocket *socket;
GSocketAddress *address;
GSocket *socket = NULL;
GSocketAddress *address = NULL;
GError *error = NULL;
GOptionContext *context;
GCancellable *cancellable;
GIOStream *connection;
GInputStream *istream;
GOutputStream *ostream;
GIOStream *connection = NULL;
GInputStream *istream = NULL;
GOutputStream *ostream = NULL;
GSocketAddress *src_address = NULL;
GTlsCertificate *certificate = NULL;
gint i;

View File

@ -1555,9 +1555,14 @@ g_ptr_array_free (GPtrArray *array,
/* if others are holding a reference, preserve the wrapper but
* do free/return the data
*
* Coverity doesnt understand this and assumes its a leak, so comment this
* out.
*/
#ifndef __COVERITY__
if (!g_atomic_ref_count_dec (&rarray->ref_count))
flags |= PRESERVE_WRAPPER;
#endif
return ptr_array_free (array, flags);
}

View File

@ -3484,8 +3484,19 @@ g_variant_builder_init (GVariantBuilder *builder,
g_assert_not_reached ();
}
#ifdef G_ANALYZER_ANALYZING
/* Static analysers cant couple the code in g_variant_builder_init() to the
* code in g_variant_builder_end() by GVariantType, so end up assuming that
* @offset and @children mismatch and that uninitialised memory is accessed
* from @children. At runtime, this is caught by the preconditions at the top
* of g_variant_builder_end(). Help the analyser by zero-initialising the
* memory to avoid a false positive. */
GVSB(builder)->children = g_new0 (GVariant *,
GVSB(builder)->allocated_children);
#else
GVSB(builder)->children = g_new (GVariant *,
GVSB(builder)->allocated_children);
#endif
}
static void

View File

@ -186,7 +186,7 @@ addition_thread (gpointer value)
static void
test_mutex_perf (gconstpointer data)
{
guint n_threads = GPOINTER_TO_UINT (data);
const guint n_threads = GPOINTER_TO_UINT (data);
GThread *threads[THREADS];
gint64 start_time;
gdouble rate;

View File

@ -25,11 +25,11 @@
#define quick_rand32() \
(rand_accu = 1664525 * rand_accu + 1013904223, rand_accu)
static guint prime_size = 1021; /* 769; 509 */
static gboolean clean_memchunks = FALSE;
static guint number_of_blocks = 10000; /* total number of blocks allocated */
static guint number_of_repetitions = 10000; /* number of alloc+free repetitions */
static gboolean want_corruption = FALSE;
static const guint prime_size = 1021; /* 769; 509 */
static const gboolean clean_memchunks = FALSE;
static const guint number_of_blocks = 10000; /* total number of blocks allocated */
static const guint number_of_repetitions = 10000; /* number of alloc+free repetitions */
static const gboolean want_corruption = FALSE;
/* --- old memchunk prototypes (memchunks.c) --- */
GMemChunk* old_mem_chunk_new (const gchar *name,