[Libosinfo] [libosinfo PATCH 2/3] os: Deal with a NULL profile on _find_install_script()
Fabiano Fidêncio
fidencio at redhat.com
Fri Nov 23 12:49:54 UTC 2018
Let's ensure we're not going to crash in case a NULL profile is passed
for osinfo_find_install_script().
Also, document which are the expected values for @profile
---
osinfo/osinfo_os.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 9328820..314b4d8 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -956,17 +956,25 @@ void osinfo_os_add_maximum_resources(OsinfoOs *os,
/**
* osinfo_os_find_install_script:
* @os: an operating system
- * @profile: the install script profile
+ * @profile: the install script profile that must be either
+ * OSINFO_INSTALL_SCRIPT_PROFILE_DESKTOP or OSINFO_INSTALL_SCRIPT_PROFILE_JEOS
*
* Returns: (transfer full): A new #OsinfoInstallScript for the @os @profile
*/
OsinfoInstallScript *osinfo_os_find_install_script(OsinfoOs *os, const gchar *profile)
{
- g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
- GList *scripts = osinfo_list_get_elements(OSINFO_LIST(os->priv->scripts));
- GList *tmp = scripts;
+ GList *scripts;
+ GList *tmp;
OsinfoInstallScript *script = NULL;
+ g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+ scripts = osinfo_list_get_elements(OSINFO_LIST(os->priv->scripts));
+ tmp = scripts;
+
+ if (profile == NULL)
+ return script;
+
while (tmp) {
script = tmp->data;
if (g_str_equal(profile, osinfo_install_script_get_profile(script)))
--
2.19.1
More information about the Libosinfo
mailing list