From: Bastian Dehn Date: Sat, 8 Feb 2025 15:51:04 +0000 (+0100) Subject: change strdup to c99 copy X-Git-Tag: v1.0.33^2~2 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=dd66353b7122e32de0066dbcc521ba02e99447e8;p=sane-kds-s2000w-net.git change strdup to c99 copy --- diff --git a/src/kds_s2000w_config.c b/src/kds_s2000w_config.c index e6ddcb9..cce2127 100644 --- a/src/kds_s2000w_config.c +++ b/src/kds_s2000w_config.c @@ -9,7 +9,10 @@ void _kds_s2000w_config_copy_string_to_config_value(cfg_t* cfg, const char* key, *config_value = NULL; char* value_str = cfg_getstr(cfg, key); - *config_value = strdup(value_str); + + size_t size_str = strlen(value_str) + 1; + *config_value = malloc(size_str); + memcpy(*config_value, value_str, size_str); } void _kds_s2000w_config_set_log_level(int log_level) diff --git a/tests/kds_s2000w_client_mock.c b/tests/kds_s2000w_client_mock.c index f19e335..2d77285 100644 --- a/tests/kds_s2000w_client_mock.c +++ b/tests/kds_s2000w_client_mock.c @@ -105,5 +105,10 @@ void __wrap_kds_s2000w_image_converter_to_pnm(blobdata* in, blobdata* out) char* __wrap_sanei_config_get_paths(void) { char* str = "config_dir_list"; - return strdup(str); + + size_t size = strlen(str) + 1; + char* cpystr = malloc(size); + memcpy(cpystr, str, size); + + return cpystr; } \ No newline at end of file diff --git a/tests/kds_s2000w_net_get_opt_tests_run.c b/tests/kds_s2000w_net_get_opt_tests_run.c index 2bd71ee..00f39bb 100644 --- a/tests/kds_s2000w_net_get_opt_tests_run.c +++ b/tests/kds_s2000w_net_get_opt_tests_run.c @@ -41,9 +41,10 @@ int setup_default_get_option(void** state) \"ScanSource\": \"DocumentFeeder\" \ } \ }"; - resp->data = strdup(responsedata); - resp->code = 200; resp->size = 918; + resp->data = malloc(resp->size); + memcpy(resp->data, responsedata, resp->size); + resp->code = 200; *state = resp; return 0; } diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index 4fb1c88..0dd8636 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -220,9 +220,10 @@ void sane_kds_s2000w_net_start_test(void** state) \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 204; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); will_return(mock_response, response_list[2]); @@ -266,9 +267,10 @@ void sane_kds_s2000w_net_start_one_page_per_flatscan_test(void** state) \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 204; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); will_return(mock_response, response_list[2]); @@ -313,9 +315,10 @@ void sane_kds_s2000w_net_start_one_page_per_feeder_test(void** state) \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 209; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); will_return(mock_response, response_list[2]); @@ -362,9 +365,10 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** state) \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 209; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); will_return(mock_response, response_list[2]); @@ -397,9 +401,10 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** state) }}\0"; free(resp_status->data); resp_status->data = NULL; - resp_status->data = strdup(status2); - resp_status->code = 200; resp_status->size = 209; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status2, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); will_return(mock_response, response_list[2]); @@ -438,9 +443,10 @@ void sane_kds_s2000w_net_cancel_test() \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 204; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); response* resp = kds_s2000w_client_response_init(); @@ -482,9 +488,10 @@ void sane_kds_s2000w_net_cancel_canceled_test() { response* resp_status = kds_s2000w_client_response_init(); const char* status = "{\"SessionId\":\"1251877821\"}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 27; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_open_session, 0); response* set_option = kds_s2000w_client_response_init(); @@ -523,9 +530,10 @@ void sane_kds_s2000w_net_cancel_completed_scan_feeder_test() \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 209; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); expect_function_call(__wrap_kds_s2000w_client_status_session); @@ -556,16 +564,18 @@ void sane_kds_s2000w_net_cancel_completed_scan_flatbed_test() \"PaperDetected\": \"0\", \ \"PercentAvailable\": 99 \ }}"; - resp_status->data = strdup(status); - resp_status->code = 200; resp_status->size = 204; + resp_status->data = malloc(resp_status->size); + memcpy(resp_status->data, status, resp_status->size); + resp_status->code = 200; will_return(mock_response, resp_status); will_return(__wrap_kds_s2000w_client_status_session, 0); response* resp_session = kds_s2000w_client_response_init(); const char* responsedata = "{\"SessionId\":\"1251877821\"}"; - resp_session->data = strdup(responsedata); - resp_session->code = 200; resp_session->size = 27; + resp_session->data = malloc(resp_session->size); + memcpy(resp_session->data, responsedata, resp_session->size); + resp_session->code = 200; will_return(mock_response, resp_session); will_return(__wrap_kds_s2000w_client_open_session, 0); response* resp_options = kds_s2000w_client_response_init(); diff --git a/tests/kds_s2000w_net_tests_run.c b/tests/kds_s2000w_net_tests_run.c index e838695..e47e419 100644 --- a/tests/kds_s2000w_net_tests_run.c +++ b/tests/kds_s2000w_net_tests_run.c @@ -17,9 +17,10 @@ int setup(void** state) \"ImageHeight\": 1080, \ }\ }"; - response_list[1]->data = strdup(metadata); - response_list[1]->code = 200; response_list[1]->size = 106; + response_list[1]->data = malloc(response_list[1]->size); + memcpy(response_list[1]->data, metadata, response_list[1]->size); + response_list[1]->code = 200; response_list[2] = kds_s2000w_client_response_init(); response_list[2]->code = 200; response_list[2]->size = 17;