gproxyresolver: add asserts to ensure error is set

This will catch buggy implementations of GProxyResolver before they are
able to return bogus results to higher level code. In particular, if
g_proxy_resolver_lookup() returns NULL, it'd better set an error to
explain why.
This commit is contained in:
Michael Catanzaro 2022-06-27 15:10:25 -05:00
parent 1738fad172
commit 8e29865112

View File

@ -158,6 +158,7 @@ g_proxy_resolver_lookup (GProxyResolver *resolver,
GError **error)
{
GProxyResolverInterface *iface;
gchar **proxy_uris;
g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
g_return_val_if_fail (uri != NULL, NULL);
@ -171,7 +172,10 @@ g_proxy_resolver_lookup (GProxyResolver *resolver,
iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
return (* iface->lookup) (resolver, uri, cancellable, error);
proxy_uris = (* iface->lookup) (resolver, uri, cancellable, error);
if (proxy_uris == NULL && error != NULL)
g_assert (*error != NULL);
return proxy_uris;
}
/**
@ -237,10 +241,14 @@ g_proxy_resolver_lookup_finish (GProxyResolver *resolver,
GError **error)
{
GProxyResolverInterface *iface;
gchar **proxy_uris;
g_return_val_if_fail (G_IS_PROXY_RESOLVER (resolver), NULL);
iface = G_PROXY_RESOLVER_GET_IFACE (resolver);
return (* iface->lookup_finish) (resolver, result, error);
proxy_uris = (* iface->lookup_finish) (resolver, result, error);
if (proxy_uris == NULL && error != NULL)
g_assert (*error != NULL);
return proxy_uris;
}