[easytag/wip/clang-analyzer: 9/14] Refactor Set_Config() slightly



commit 5e5028234e27ad49cb3ab8b44e8b43ae7ca4f6cb
Author: David King <amigadave amigadave com>
Date:   Mon Aug 12 16:36:53 2013 +0100

    Refactor Set_Config() slightly
    
    Check and report if a configuration key is not found and also if an
    empty value is found.

 src/setting.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/setting.c b/src/setting.c
index d55acfa..1eb6301 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -1009,8 +1009,8 @@ Save_Config_To_File (void)
 static void
 Set_Config (gchar *line)
 {
-    gchar *var_descriptor;
-    gchar *var_value;
+    const gchar *var_descriptor;
+    const gchar *var_value;
     gint ConfigVarListLen;
     gint i;
 
@@ -1019,9 +1019,21 @@ Set_Config (gchar *line)
     if (*line=='\n' || *line=='#') return;
 
     /* Cut string */
-    var_descriptor = strtok(line,"=");
-    var_value      = strtok(NULL,"=");
-    //g_print("\nstr1:'%s',\t str2:'%s'",var_descriptor,var_value);
+    var_descriptor = strtok (line, "=");
+
+    if (!var_descriptor)
+    {
+        g_message ("Invalid configuration file line ā€˜%sā€™", line);
+        return;
+    }
+
+    var_value = strtok (NULL, "=");
+
+    if (!var_value)
+    {
+        g_message ("No value for configuration key ā€˜%sā€™", var_descriptor);
+        return;
+    }
 
     ConfigVarListLen = sizeof(Config_Variables)/sizeof(tConfigVariable);
     for (i=0; i<ConfigVarListLen; i++)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]