mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-02 19:59:21 +02:00
girepository: Fix -Wsign-conversion warnings with string arithmetic
There are a few `g_strndup()` calls which use a length calculated from the return value of `strchr()` minus the original string. That’s fine, as long as `strchr()` doesn’t return `NULL`. Add some asserts to ensure that. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3405
This commit is contained in:
@@ -607,7 +607,8 @@ load_dependencies_recurse (GIRepository *repository,
|
|||||||
const char *dependency_version;
|
const char *dependency_version;
|
||||||
|
|
||||||
last_dash = strrchr (dependency, '-');
|
last_dash = strrchr (dependency, '-');
|
||||||
dependency_namespace = g_strndup (dependency, last_dash - dependency);
|
g_assert (last_dash != NULL); /* get_typelib_dependencies() guarantees this */
|
||||||
|
dependency_namespace = g_strndup (dependency, (size_t) (last_dash - dependency));
|
||||||
dependency_version = last_dash+1;
|
dependency_version = last_dash+1;
|
||||||
|
|
||||||
if (!gi_repository_require (repository, dependency_namespace, dependency_version,
|
if (!gi_repository_require (repository, dependency_namespace, dependency_version,
|
||||||
@@ -785,7 +786,8 @@ get_typelib_dependencies_transitive (GIRepository *repository,
|
|||||||
|
|
||||||
/* Recurse for this namespace. */
|
/* Recurse for this namespace. */
|
||||||
last_dash = strrchr (dependency, '-');
|
last_dash = strrchr (dependency, '-');
|
||||||
dependency_namespace = g_strndup (dependency, last_dash - dependency);
|
g_assert (last_dash != NULL); /* get_typelib_dependencies() guarantees this */
|
||||||
|
dependency_namespace = g_strndup (dependency, (size_t) (last_dash - dependency));
|
||||||
|
|
||||||
typelib = get_registered (repository, dependency_namespace, NULL);
|
typelib = get_registered (repository, dependency_namespace, NULL);
|
||||||
g_return_if_fail (typelib != NULL);
|
g_return_if_fail (typelib != NULL);
|
||||||
@@ -1742,7 +1744,12 @@ enumerate_namespace_versions (const char *namespace,
|
|||||||
|
|
||||||
name_end = strrchr (entry, '.');
|
name_end = strrchr (entry, '.');
|
||||||
last_dash = strrchr (entry, '-');
|
last_dash = strrchr (entry, '-');
|
||||||
version = g_strndup (last_dash+1, name_end-(last_dash+1));
|
|
||||||
|
/* These are guaranteed by the suffix and prefix checks above: */
|
||||||
|
g_assert (name_end != NULL);
|
||||||
|
g_assert (last_dash != NULL);
|
||||||
|
|
||||||
|
version = g_strndup (last_dash + 1, (size_t) (name_end - (last_dash + 1u)));
|
||||||
if (!parse_version (version, &major, &minor))
|
if (!parse_version (version, &major, &minor))
|
||||||
{
|
{
|
||||||
g_free (version);
|
g_free (version);
|
||||||
|
@@ -707,7 +707,7 @@ parse_type_internal (GIIrModule *module,
|
|||||||
*str == ':')
|
*str == ':')
|
||||||
(str)++;
|
(str)++;
|
||||||
|
|
||||||
type->giinterface = g_strndup (start, str - start);
|
type->giinterface = g_strndup (start, (size_t) (str - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next)
|
if (next)
|
||||||
|
Reference in New Issue
Block a user