]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change strdup to c99 copy
authorBastian Dehn <hhaalo@arcor.de>
Sat, 8 Feb 2025 15:51:04 +0000 (16:51 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 8 Feb 2025 15:51:27 +0000 (16:51 +0100)
src/kds_s2000w_config.c
tests/kds_s2000w_client_mock.c
tests/kds_s2000w_net_get_opt_tests_run.c
tests/kds_s2000w_net_tests.c
tests/kds_s2000w_net_tests_run.c

index e6ddcb9b3530e7e0dbc0ccfcc1d1bb86715b06f7..cce2127b58b2e3e850bac8f4dcfd9a674e04eabd 100644 (file)
@@ -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)
index f19e335c084c0d325d61b5be685bc8aee8701373..2d77285e304e033bf3c330dfe1b52a69325c6d71 100644 (file)
@@ -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
index 2bd71ee4af250e28ad410e61d3e5fd13bfc07ac5..00f39bb79fcb62459d6d952add3c53ab2bb843d3 100644 (file)
@@ -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;
 }
index 4fb1c8805583c08ca7f9ade2ca7972250cb2eeda..0dd8636aff46b791226f2ce6d04f08c26e7ce1a8 100644 (file)
@@ -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();
index e8386959e4e5d7535e80209b3241efd487a03ea1..e47e4196a9e20e4b6551c22f0beedeffb1a4c0a0 100644 (file)
@@ -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;