]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
declare null pointer opt first in method
authorBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 19:54:05 +0000 (20:54 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 6 Mar 2024 19:54:05 +0000 (20:54 +0100)
src/kds_s2000w_handler_opts.c

index 42707fd8ed803d8aa5aea2af0cee58ee9ec009fa..0466f74d0b965d6fc24c1a3f89ce690353578768 100644 (file)
@@ -41,8 +41,9 @@ void _load_options(handler* h)
 {
        json_object_put(resp_config);
        resp_config = NULL;
+       response* resp = NULL;
 
-       response* resp = kds_s2000w_client_response_init();
+       resp = kds_s2000w_client_response_init();
        int result = kds_s2000w_client_get_option(h->sessionid, resp);
        resp_config = json_tokener_parse(resp->data);
        config = json_object_object_get(resp_config, "Configuration");
@@ -161,8 +162,14 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf
        if (h->read_info->scan_started)
                return;
 
-       config = json_object_object_get(resp_config, "Configuration");
+       response* resp = NULL;
        json_object* value_object = NULL;
+       json_object* capabilities = NULL;
+       json_object* default_values = NULL;
+       json_object* autostart = NULL;
+       json_object* default_config = NULL;
+
+       config = json_object_object_get(resp_config, "Configuration");
 
        int autostart_value = AUTOSTART_ALWAYS_ON;
        value_object = json_object_object_get(config, "AutoStart");
@@ -269,13 +276,13 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf
                        _write_int_value_to_json(value_object, value);
                        break;
                case 23:
-                       response* resp = kds_s2000w_client_response_init();
+                       resp = kds_s2000w_client_response_init();
                        kds_s2000w_client_get_capabilities(resp);
-                       json_object* capabilities = json_tokener_parse(resp->data);
-                       json_object* default_values = json_object_object_get(capabilities, "Defaults");
-                       json_object* autostart = json_object_object_get(default_values, "AutoStart");
+                       capabilities = json_tokener_parse(resp->data);
+                       default_values = json_object_object_get(capabilities, "Defaults");
+                       autostart = json_object_object_get(default_values, "AutoStart");
                        json_object_set_int(autostart, AUTOSTART_ALWAYS_ON);
-                       json_object* default_config = json_object_new_object();
+                       default_config = json_object_new_object();
                        json_object_object_add(default_config, "Configuration", default_values);
 
                        const char* json_string = json_object_to_json_string_ext(default_config, JSON_C_TO_STRING_PLAIN);
@@ -309,7 +316,7 @@ void kds_s2000w_handler_set_option(handler* h, int option, void* value, int* inf
        }
 
        const char* json_string = json_object_to_json_string_ext(resp_config, JSON_C_TO_STRING_PLAIN);
-       response* resp = kds_s2000w_client_response_init();
+       resp = kds_s2000w_client_response_init();
        resp->size = sizeof(char) * strlen(json_string);
        resp->code = 0;
        resp->data = realloc(resp->data, resp->size);