mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
gkeyfile: Rework preconditions to avoid unreachable branches
It’s a programmer error for `NULL` to reach `is_group_name()` or `is_key_name()`, so rework the preconditions so that all programmer error checks are wrapped in a `g_return_if_fail()`. The coverage scanning is set up to ignore anything inside that. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
e8a6d0b54e
commit
513f48bab7
@ -1888,8 +1888,8 @@ g_key_file_set_value (GKeyFile *key_file,
|
|||||||
GKeyFileKeyValuePair *pair;
|
GKeyFileKeyValuePair *pair;
|
||||||
|
|
||||||
g_return_if_fail (key_file != NULL);
|
g_return_if_fail (key_file != NULL);
|
||||||
g_return_if_fail (g_key_file_is_group_name (group_name));
|
g_return_if_fail (group_name != NULL && g_key_file_is_group_name (group_name));
|
||||||
g_return_if_fail (g_key_file_is_key_name (key, strlen (key)));
|
g_return_if_fail (key != NULL && g_key_file_is_key_name (key, strlen (key)));
|
||||||
g_return_if_fail (value != NULL);
|
g_return_if_fail (value != NULL);
|
||||||
|
|
||||||
group = g_key_file_lookup_group (key_file, group_name);
|
group = g_key_file_lookup_group (key_file, group_name);
|
||||||
@ -3351,7 +3351,7 @@ g_key_file_set_group_comment (GKeyFile *key_file,
|
|||||||
{
|
{
|
||||||
GKeyFileGroup *group;
|
GKeyFileGroup *group;
|
||||||
|
|
||||||
g_return_val_if_fail (g_key_file_is_group_name (group_name), FALSE);
|
g_return_val_if_fail (group_name != NULL && g_key_file_is_group_name (group_name), FALSE);
|
||||||
|
|
||||||
group = g_key_file_lookup_group (key_file, group_name);
|
group = g_key_file_lookup_group (key_file, group_name);
|
||||||
if (!group)
|
if (!group)
|
||||||
@ -3481,7 +3481,7 @@ g_key_file_get_key_comment (GKeyFile *key_file,
|
|||||||
GString *string;
|
GString *string;
|
||||||
gchar *comment;
|
gchar *comment;
|
||||||
|
|
||||||
g_return_val_if_fail (g_key_file_is_group_name (group_name), NULL);
|
g_return_val_if_fail (group_name != NULL && g_key_file_is_group_name (group_name), NULL);
|
||||||
|
|
||||||
group = g_key_file_lookup_group (key_file, group_name);
|
group = g_key_file_lookup_group (key_file, group_name);
|
||||||
if (!group)
|
if (!group)
|
||||||
@ -3828,7 +3828,7 @@ g_key_file_add_group (GKeyFile *key_file,
|
|||||||
GKeyFileGroup *group;
|
GKeyFileGroup *group;
|
||||||
|
|
||||||
g_return_if_fail (key_file != NULL);
|
g_return_if_fail (key_file != NULL);
|
||||||
g_return_if_fail (g_key_file_is_group_name (group_name));
|
g_return_if_fail (group_name != NULL && g_key_file_is_group_name (group_name));
|
||||||
|
|
||||||
group = g_key_file_lookup_group (key_file, group_name);
|
group = g_key_file_lookup_group (key_file, group_name);
|
||||||
if (group != NULL)
|
if (group != NULL)
|
||||||
@ -4156,8 +4156,7 @@ g_key_file_is_group_name (const gchar *name)
|
|||||||
{
|
{
|
||||||
const gchar *p, *q;
|
const gchar *p, *q;
|
||||||
|
|
||||||
if (name == NULL)
|
g_assert (name != NULL);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
p = q = name;
|
p = q = name;
|
||||||
while (*q && *q != ']' && *q != '[' && !g_ascii_iscntrl (*q))
|
while (*q && *q != ']' && *q != '[' && !g_ascii_iscntrl (*q))
|
||||||
@ -4175,8 +4174,7 @@ g_key_file_is_key_name (const gchar *name,
|
|||||||
{
|
{
|
||||||
const gchar *p, *q, *end;
|
const gchar *p, *q, *end;
|
||||||
|
|
||||||
if (name == NULL)
|
g_assert (name != NULL);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
p = q = name;
|
p = q = name;
|
||||||
end = name + len;
|
end = name + len;
|
||||||
|
Loading…
Reference in New Issue
Block a user