mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
gvariant: Rework array iteration in g_variant_format_string_scan_type()
This introduces no functional changes. Switch from incrementing a pointer to incrementing a counter and using array indexing. This squashes a scan-build false positive, where it can’t choose which of `dest` and `new` ‘own’ the newly allocated memory, so it kind of assumes both do, and then warns there’s a potential leak of `dest` when the function returns. In actual fact, ownership of the memory is returned via `new`. Partly this might be masked through use of the `G_VARIANT_TYPE` macro, which the following commit will address. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #1767
This commit is contained in:
parent
79be995c0c
commit
156c1496ba
@ -4620,7 +4620,7 @@ g_variant_format_string_scan_type (const gchar *string,
|
|||||||
const gchar **endptr)
|
const gchar **endptr)
|
||||||
{
|
{
|
||||||
const gchar *my_end;
|
const gchar *my_end;
|
||||||
gchar *dest;
|
gsize i;
|
||||||
gchar *new;
|
gchar *new;
|
||||||
|
|
||||||
if (endptr == NULL)
|
if (endptr == NULL)
|
||||||
@ -4629,14 +4629,15 @@ g_variant_format_string_scan_type (const gchar *string,
|
|||||||
if (!g_variant_format_string_scan (string, limit, endptr))
|
if (!g_variant_format_string_scan (string, limit, endptr))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dest = new = g_malloc (*endptr - string + 1);
|
new = g_malloc (*endptr - string + 1);
|
||||||
|
i = 0;
|
||||||
while (string != *endptr)
|
while (string != *endptr)
|
||||||
{
|
{
|
||||||
if (*string != '@' && *string != '&' && *string != '^')
|
if (*string != '@' && *string != '&' && *string != '^')
|
||||||
*dest++ = *string;
|
new[i++] = *string;
|
||||||
string++;
|
string++;
|
||||||
}
|
}
|
||||||
*dest = '\0';
|
new[i++] = '\0';
|
||||||
|
|
||||||
return (GVariantType *) G_VARIANT_TYPE (new);
|
return (GVariantType *) G_VARIANT_TYPE (new);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user