From: Bastian Dehn Date: Wed, 6 Mar 2024 19:54:05 +0000 (+0100) Subject: declare null pointer opt first in method X-Git-Tag: v1.0.0^2~136 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=bf348c27e46ab7e075881f2ce420baf46f3d6846;p=sane-kds-s2000w-net.git declare null pointer opt first in method --- diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 42707fd..0466f74 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -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);