gitypelib: Fix iterating through typelib prefixes

The iteration code used `g_string_overwrite_len()` to try and simplify
buffer allocation and growth, but seemingly forgot to handle the fact
that it doesn’t nul-terminate what it overwrites: the method is intended
to be used to splice bits into longer strings, not to overwrite an
entire nul-terminated string.

This meant that when iterating over a comma-separated `c_prefix` like
`GUnix,G`, on the second iteration `g_string_overwrite_len()` would be
used to write `G` into index 0 of the already-set `GUnix` string in the
buffer, leading to the first iteration happening all over again and the
`G` prefix being ignored.

This led to symbols failing to be matched to the `GioUnix` typelib, even
though they should have been.

This will be checked by a test in the following commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3303
This commit is contained in:
Philip Withnall 2024-05-02 15:59:46 +01:00
parent 04bdf50c68
commit 25b7ecf895
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -316,7 +316,8 @@ strsplit_iter_next (StrSplitIter *iter,
}
else
{
g_string_overwrite_len (&iter->buf, 0, s, (gssize)len);
g_string_overwrite_len (&iter->buf, 0, s, (gssize)len + 1);
iter->buf.str[len] = '\0';
*out_val = iter->buf.str;
}
return TRUE;