mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
Merge branch 'static-analysis' into 'main'
fix issues found by svace static code analyzer See merge request GNOME/glib!2285
This commit is contained in:
commit
2423419a29
@ -997,6 +997,8 @@ parse_header (gchar *line)
|
||||
|
||||
line[len - 1] = 0;
|
||||
s = strchr (line, ':');
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
match = g_slice_new0 (TreeMatch);
|
||||
match->priority = atoi (line + 1);
|
||||
@ -1025,9 +1027,13 @@ parse_match_line (gchar *line,
|
||||
{
|
||||
*depth = atoi (line);
|
||||
s = strchr (line, '>');
|
||||
if (s == NULL)
|
||||
goto handle_error;
|
||||
}
|
||||
s += 2;
|
||||
p = strchr (s, '"');
|
||||
if (p == NULL)
|
||||
goto handle_error;
|
||||
*p = 0;
|
||||
|
||||
matchlet->path = g_strdup (s);
|
||||
@ -1058,6 +1064,10 @@ parse_match_line (gchar *line,
|
||||
g_strfreev (parts);
|
||||
|
||||
return matchlet;
|
||||
|
||||
handle_error:
|
||||
g_slice_free (TreeMatchlet, matchlet);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
@ -1119,7 +1129,7 @@ read_tree_magic_from_directory (const gchar *prefix)
|
||||
gchar *text;
|
||||
gsize len;
|
||||
gchar **lines;
|
||||
gint i;
|
||||
gsize i;
|
||||
TreeMatch *match;
|
||||
TreeMatchlet *matchlet;
|
||||
gint depth;
|
||||
@ -1134,14 +1144,18 @@ read_tree_magic_from_directory (const gchar *prefix)
|
||||
match = NULL;
|
||||
for (i = 0; lines[i] && lines[i][0]; i++)
|
||||
{
|
||||
if (lines[i][0] == '[')
|
||||
if (lines[i][0] == '[' && (match = parse_header (lines[i])) != NULL)
|
||||
{
|
||||
match = parse_header (lines[i]);
|
||||
insert_match (match);
|
||||
}
|
||||
else if (match != NULL)
|
||||
{
|
||||
matchlet = parse_match_line (lines[i], &depth);
|
||||
if (matchlet == NULL)
|
||||
{
|
||||
g_warning ("%s: body corrupt; skipping", filename);
|
||||
break;
|
||||
}
|
||||
insert_matchlet (match, matchlet, depth);
|
||||
}
|
||||
else
|
||||
|
@ -881,8 +881,8 @@ keyring_generate_entry (const gchar *cookie_context,
|
||||
error))
|
||||
{
|
||||
*out_id = 0;
|
||||
*out_cookie = 0;
|
||||
g_free (*out_cookie);
|
||||
*out_cookie = 0;
|
||||
ret = FALSE;
|
||||
goto out;
|
||||
}
|
||||
|
@ -2011,7 +2011,16 @@ g_local_file_trash (GFile *file,
|
||||
* trying to rename across a filesystem boundary, which doesn't work. So
|
||||
* we use g_stat here instead of g_lstat, to know where the symlink
|
||||
* points to. */
|
||||
g_stat (path, &file_stat);
|
||||
if (g_stat (path, &file_stat))
|
||||
{
|
||||
errsv = errno;
|
||||
g_free (path);
|
||||
|
||||
g_set_io_error (error,
|
||||
_("Error trashing file %s: %s"),
|
||||
file, errsv);
|
||||
return FALSE;
|
||||
}
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
|
@ -2650,7 +2650,7 @@ set_mtime_atime (char *filename,
|
||||
{
|
||||
if (lazy_stat (filename, &statbuf, &got_stat) == 0)
|
||||
{
|
||||
times[0].tv_sec = statbuf.st_mtime;
|
||||
times[0].tv_sec = statbuf.st_atime;
|
||||
#if defined (HAVE_STRUCT_STAT_ST_ATIMENSEC)
|
||||
times[0].tv_usec = statbuf.st_atimensec / 1000;
|
||||
#elif defined (HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
|
||||
|
@ -490,14 +490,14 @@ _g_cclosure_marshal_BOOLEAN__STRINGv (GClosure *closure,
|
||||
gpointer arg0;
|
||||
va_list args_copy;
|
||||
|
||||
g_return_if_fail (return_value != NULL);
|
||||
|
||||
G_VA_COPY (args_copy, args);
|
||||
arg0 = (gpointer) va_arg (args_copy, gpointer);
|
||||
if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
|
||||
arg0 = g_strdup (arg0);
|
||||
va_end (args_copy);
|
||||
|
||||
g_return_if_fail (return_value != NULL);
|
||||
|
||||
if (G_CCLOSURE_SWAP_DATA (closure))
|
||||
{
|
||||
data1 = closure->data;
|
||||
|
@ -108,6 +108,8 @@ g_openuri_portal_open_uri (const char *uri,
|
||||
errsv = errno;
|
||||
if (fd == -1)
|
||||
{
|
||||
g_free (path);
|
||||
g_variant_builder_clear (&opt_builder);
|
||||
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
|
||||
"Failed to open '%s'", path);
|
||||
return FALSE;
|
||||
|
@ -262,8 +262,12 @@ g_proxy_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
||||
}
|
||||
dest_protocol = g_uri_parse_scheme (priv->dest_uri);
|
||||
|
||||
g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (priv->proxy_address),
|
||||
NULL);
|
||||
if (!G_IS_INET_SOCKET_ADDRESS (priv->proxy_address))
|
||||
{
|
||||
g_free (dest_hostname);
|
||||
g_free (dest_protocol);
|
||||
}
|
||||
g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (priv->proxy_address), NULL);
|
||||
|
||||
inetsaddr = G_INET_SOCKET_ADDRESS (priv->proxy_address);
|
||||
inetaddr = g_inet_socket_address_get_address (inetsaddr);
|
||||
@ -352,6 +356,11 @@ return_result (GTask *task)
|
||||
}
|
||||
dest_protocol = g_uri_parse_scheme (priv->dest_uri);
|
||||
|
||||
if (!G_IS_INET_SOCKET_ADDRESS (priv->proxy_address))
|
||||
{
|
||||
g_free (dest_hostname);
|
||||
g_free (dest_protocol);
|
||||
}
|
||||
g_return_if_fail (G_IS_INET_SOCKET_ADDRESS (priv->proxy_address));
|
||||
|
||||
inetsaddr = G_INET_SOCKET_ADDRESS (priv->proxy_address);
|
||||
|
@ -200,6 +200,8 @@ g_settings_get_mapping_int (GValue *value,
|
||||
l = g_variant_get_int32 (variant);
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT64))
|
||||
l = g_variant_get_int64 (variant);
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
|
||||
l = g_variant_get_handle (variant);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
@ -291,8 +293,6 @@ g_settings_get_mapping_unsigned_int (GValue *value,
|
||||
u = g_variant_get_uint32 (variant);
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT64))
|
||||
u = g_variant_get_uint64 (variant);
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
|
||||
u = g_variant_get_handle (variant);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
@ -459,7 +459,8 @@ g_settings_get_mapping (GValue *value,
|
||||
|
||||
else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_INT16) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_INT32) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_INT64))
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_INT64) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_HANDLE))
|
||||
return g_settings_get_mapping_int (value, variant);
|
||||
|
||||
else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_DOUBLE))
|
||||
@ -467,8 +468,7 @@ g_settings_get_mapping (GValue *value,
|
||||
|
||||
else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT16) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT64) ||
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_HANDLE))
|
||||
g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT64))
|
||||
return g_settings_get_mapping_unsigned_int (value, variant);
|
||||
|
||||
else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING) ||
|
||||
|
@ -621,7 +621,7 @@ g_socket (gint domain,
|
||||
(flags & FD_CLOEXEC) == 0)
|
||||
{
|
||||
flags |= FD_CLOEXEC;
|
||||
fcntl (fd, F_SETFD, flags);
|
||||
(void) fcntl (fd, F_SETFD, flags);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
@ -328,7 +328,7 @@ set_connect_msg (guint8 *msg,
|
||||
*
|
||||
* The parser only requires 4 bytes.
|
||||
*/
|
||||
#define SOCKS5_CONN_REP_LEN 255
|
||||
#define SOCKS5_CONN_REP_LEN 257
|
||||
static gboolean
|
||||
parse_connect_reply (const guint8 *data, gint *atype, GError **error)
|
||||
{
|
||||
@ -509,7 +509,7 @@ g_socks5_proxy_connect (GProxy *proxy,
|
||||
guint8 data[SOCKS5_CONN_REP_LEN];
|
||||
gint atype;
|
||||
|
||||
if (!g_input_stream_read_all (in, data, 4, NULL,
|
||||
if (!g_input_stream_read_all (in, data, 4 /* VER, REP, RSV, ATYP */, NULL,
|
||||
cancellable, error))
|
||||
goto error;
|
||||
|
||||
@ -519,23 +519,26 @@ g_socks5_proxy_connect (GProxy *proxy,
|
||||
switch (atype)
|
||||
{
|
||||
case SOCKS5_ATYP_IPV4:
|
||||
if (!g_input_stream_read_all (in, data, 6, NULL,
|
||||
cancellable, error))
|
||||
if (!g_input_stream_read_all (in, data,
|
||||
4 /* IPv4 length */ + 2 /* port */,
|
||||
NULL, cancellable, error))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case SOCKS5_ATYP_IPV6:
|
||||
if (!g_input_stream_read_all (in, data, 18, NULL,
|
||||
cancellable, error))
|
||||
if (!g_input_stream_read_all (in, data,
|
||||
16 /* IPv6 length */ + 2 /* port */,
|
||||
NULL, cancellable, error))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case SOCKS5_ATYP_DOMAINNAME:
|
||||
if (!g_input_stream_read_all (in, data, 1, NULL,
|
||||
cancellable, error))
|
||||
if (!g_input_stream_read_all (in, data, 1 /* domain name length */,
|
||||
NULL, cancellable, error))
|
||||
goto error;
|
||||
if (!g_input_stream_read_all (in, data, data[0] + 2, NULL,
|
||||
cancellable, error))
|
||||
if (!g_input_stream_read_all (in, data,
|
||||
data[0] /* domain name length */ + 2 /* port */,
|
||||
NULL, cancellable, error))
|
||||
goto error;
|
||||
break;
|
||||
}
|
||||
|
@ -103,6 +103,8 @@ _xdg_mime_magic_matchlet_new (void)
|
||||
XdgMimeMagicMatchlet *matchlet;
|
||||
|
||||
matchlet = malloc (sizeof (XdgMimeMagicMatchlet));
|
||||
if (matchlet == NULL)
|
||||
return NULL;
|
||||
|
||||
matchlet->indent = 0;
|
||||
matchlet->offset = 0;
|
||||
@ -355,6 +357,11 @@ _xdg_mime_magic_parse_magic_line (FILE *magic_file,
|
||||
return XDG_MIME_MAGIC_ERROR;
|
||||
|
||||
matchlet = _xdg_mime_magic_matchlet_new ();
|
||||
|
||||
/* OOM */
|
||||
if (matchlet == NULL)
|
||||
return XDG_MIME_MAGIC_ERROR;
|
||||
|
||||
matchlet->indent = indent;
|
||||
matchlet->offset = _xdg_mime_magic_read_a_number (magic_file, &end_of_file);
|
||||
if (end_of_file)
|
||||
@ -767,6 +774,11 @@ _xdg_mime_magic_read_magic_file (XdgMimeMagic *mime_magic,
|
||||
{
|
||||
case XDG_MIME_MAGIC_SECTION:
|
||||
match = _xdg_mime_magic_match_new ();
|
||||
|
||||
/* OOM */
|
||||
if (match == NULL)
|
||||
return;
|
||||
|
||||
state = _xdg_mime_magic_parse_header (magic_file, match);
|
||||
if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
|
||||
_xdg_mime_magic_match_free (match);
|
||||
|
@ -340,7 +340,11 @@ stack_trace (const char * const *args)
|
||||
/* Save stderr for printing failure below */
|
||||
int old_err = dup (2);
|
||||
if (old_err != -1)
|
||||
fcntl (old_err, F_SETFD, fcntl (old_err, F_GETFD) | FD_CLOEXEC);
|
||||
{
|
||||
int getfd = fcntl (old_err, F_GETFD);
|
||||
if (getfd != -1)
|
||||
(void) fcntl (old_err, F_SETFD, getfd | FD_CLOEXEC);
|
||||
}
|
||||
|
||||
close (0); dup (in_fd[0]); /* set the stdin to the in pipe */
|
||||
close (1); dup (out_fd[1]); /* set the stdout to the out pipe */
|
||||
|
@ -2259,9 +2259,6 @@ g_key_file_get_locale_string (GKeyFile *key_file,
|
||||
|
||||
if (translated_value)
|
||||
break;
|
||||
|
||||
g_free (translated_value);
|
||||
translated_value = NULL;
|
||||
}
|
||||
|
||||
/* Fallback to untranslated key
|
||||
|
@ -2321,7 +2321,10 @@ g_log_writer_format_fields (GLogLevelFlags log_level,
|
||||
now = g_get_real_time ();
|
||||
now_secs = (time_t) (now / 1000000);
|
||||
now_tm = localtime (&now_secs);
|
||||
strftime (time_buf, sizeof (time_buf), "%H:%M:%S", now_tm);
|
||||
if (G_LIKELY (now_tm != NULL))
|
||||
strftime (time_buf, sizeof (time_buf), "%H:%M:%S", now_tm);
|
||||
else
|
||||
strcpy (time_buf, "(error)");
|
||||
|
||||
g_string_append_printf (gstring, "%s%s.%03d%s: ",
|
||||
use_color ? "\033[34m" : "",
|
||||
|
@ -1307,7 +1307,7 @@ static gsize
|
||||
allocator_aligned_page_size (Allocator *allocator,
|
||||
gsize n_bytes)
|
||||
{
|
||||
gsize val = 1 << g_bit_storage (n_bytes - 1);
|
||||
gsize val = (gsize) 1 << g_bit_storage (n_bytes - 1);
|
||||
val = MAX (val, allocator->min_page_size);
|
||||
return val;
|
||||
}
|
||||
|
@ -800,7 +800,13 @@ g_variant_new_array (const GVariantType *child_type,
|
||||
|
||||
for (i = 0; i < n_children; i++)
|
||||
{
|
||||
TYPE_CHECK (children[i], child_type, NULL);
|
||||
if G_UNLIKELY (!g_variant_is_of_type (children[i], child_type))
|
||||
{
|
||||
while (i != 0)
|
||||
g_variant_unref (my_children[--i]);
|
||||
g_free (my_children);
|
||||
g_return_val_if_fail (g_variant_is_of_type (children[i], child_type), NULL);
|
||||
}
|
||||
my_children[i] = g_variant_ref_sink (children[i]);
|
||||
trusted &= g_variant_is_trusted (children[i]);
|
||||
}
|
||||
@ -3190,8 +3196,7 @@ struct heap_builder
|
||||
#define GVSB_MAGIC ((gsize) 1033660112u)
|
||||
#define GVSB_MAGIC_PARTIAL ((gsize) 2942751021u)
|
||||
#define GVHB_MAGIC ((gsize) 3087242682u)
|
||||
#define is_valid_builder(b) (b != NULL && \
|
||||
GVSB(b)->magic == GVSB_MAGIC)
|
||||
#define is_valid_builder(b) (GVSB(b)->magic == GVSB_MAGIC)
|
||||
#define is_valid_heap_builder(b) (GVHB(b)->magic == GVHB_MAGIC)
|
||||
|
||||
/* Just to make sure that by adding a union to GVariantBuilder, we
|
||||
@ -3201,7 +3206,9 @@ G_STATIC_ASSERT (sizeof (GVariantBuilder) == sizeof (gsize[16]));
|
||||
static gboolean
|
||||
ensure_valid_builder (GVariantBuilder *builder)
|
||||
{
|
||||
if (is_valid_builder (builder))
|
||||
if (builder == NULL)
|
||||
return FALSE;
|
||||
else if (is_valid_builder (builder))
|
||||
return TRUE;
|
||||
if (builder->u.s.partial_magic == GVSB_MAGIC_PARTIAL)
|
||||
{
|
||||
@ -3847,8 +3854,7 @@ struct heap_dict
|
||||
#define GVSD_MAGIC ((gsize) 2579507750u)
|
||||
#define GVSD_MAGIC_PARTIAL ((gsize) 3488698669u)
|
||||
#define GVHD_MAGIC ((gsize) 2450270775u)
|
||||
#define is_valid_dict(d) (d != NULL && \
|
||||
GVSD(d)->magic == GVSD_MAGIC)
|
||||
#define is_valid_dict(d) (GVSD(d)->magic == GVSD_MAGIC)
|
||||
#define is_valid_heap_dict(d) (GVHD(d)->magic == GVHD_MAGIC)
|
||||
|
||||
/* Just to make sure that by adding a union to GVariantDict, we didn't
|
||||
@ -3858,7 +3864,9 @@ G_STATIC_ASSERT (sizeof (GVariantDict) == sizeof (gsize[16]));
|
||||
static gboolean
|
||||
ensure_valid_dict (GVariantDict *dict)
|
||||
{
|
||||
if (is_valid_dict (dict))
|
||||
if (dict == NULL)
|
||||
return FALSE;
|
||||
else if (is_valid_dict (dict))
|
||||
return TRUE;
|
||||
if (dict->u.s.partial_magic == GVSD_MAGIC_PARTIAL)
|
||||
{
|
||||
|
@ -3159,11 +3159,14 @@ g_type_class_peek_parent (gpointer g_class)
|
||||
g_return_val_if_fail (g_class != NULL, NULL);
|
||||
|
||||
node = lookup_type_node_I (G_TYPE_FROM_CLASS (g_class));
|
||||
|
||||
g_return_val_if_fail (node != NULL, NULL);
|
||||
|
||||
/* We used to acquire a read lock here. That is not necessary, since
|
||||
* parent->data->class.class is constant as long as the derived class
|
||||
* exists.
|
||||
*/
|
||||
if (node && node->is_classed && node->data && NODE_PARENT_TYPE (node))
|
||||
if (node->is_classed && node->data && NODE_PARENT_TYPE (node))
|
||||
{
|
||||
node = lookup_type_node_I (NODE_PARENT_TYPE (node));
|
||||
class = node->data->class.class;
|
||||
|
Loading…
Reference in New Issue
Block a user