From: Timo Sirainen Date: Fri, 12 Mar 2021 00:58:37 +0000 (+0200) Subject: global: Avoid casting away const X-Git-Tag: 2.3.15~177 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b2948c33c6dda0ce7cedc261e35ef7f37e522885;p=thirdparty%2Fdovecot%2Fcore.git global: Avoid casting away const --- diff --git a/src/auth/test-mech.c b/src/auth/test-mech.c index 7362d5b384..8a2c7b357b 100644 --- a/src/auth/test-mech.c +++ b/src/auth/test-mech.c @@ -92,7 +92,7 @@ static void test_mechs_init(void) process_start_time = time(NULL); /* Copy default settings */ - set = *(struct auth_settings *) auth_setting_parser_info.defaults; + set = *(const struct auth_settings *)auth_setting_parser_info.defaults; global_auth_settings = &set; global_auth_settings->base_dir = "."; memset((&set)->username_chars_map, 1, sizeof((&set)->username_chars_map)); diff --git a/src/doveadm/doveadm-dump-log.c b/src/doveadm/doveadm-dump-log.c index fcfbfd8f80..4c1f6eef3b 100644 --- a/src/doveadm/doveadm-dump-log.c +++ b/src/doveadm/doveadm-dump-log.c @@ -354,7 +354,8 @@ static void log_record_print(const struct mail_transaction_header *hdr, record_size = (sizeof(*rec) + prev_intro.record_size + 3) & ~3U; while (rec < end) { printf(" - uid=%u: ", rec->uid); - if (prev_intro.record_size <= (char*)end - (char *)(rec+1)) + size_t bytes_left = (const char *)end - (const char *)(rec + 1); + if (prev_intro.record_size <= bytes_left) print_data(rec + 1, prev_intro.record_size); else printf("(record_size too large)"); diff --git a/src/doveadm/dsync/dsync-ibc-pipe.c b/src/doveadm/dsync/dsync-ibc-pipe.c index bb552dfa8b..14b31ade07 100644 --- a/src/doveadm/dsync/dsync-ibc-pipe.c +++ b/src/doveadm/dsync/dsync-ibc-pipe.c @@ -279,7 +279,7 @@ dsync_ibc_pipe_recv_mailbox_tree_node(struct dsync_ibc *ibc, if (item == NULL) return DSYNC_IBC_RECV_RET_TRYAGAIN; - *name_r = (void *)item->u.node.name; + *name_r = (const void *)item->u.node.name; item->u.node.name = NULL; *node_r = &item->u.node; diff --git a/src/imap-hibernate/imap-hibernate-client.c b/src/imap-hibernate/imap-hibernate-client.c index 29992b0ca0..4065adc592 100644 --- a/src/imap-hibernate/imap-hibernate-client.c +++ b/src/imap-hibernate/imap-hibernate-client.c @@ -224,7 +224,8 @@ imap_hibernate_client_input_line(struct connection *conn, const char *line) pool = pool_alloconly_create("client cmd", 1024); args = p_strsplit_tabescaped(pool, line); - ret = imap_hibernate_client_input_args(conn, (void *)args, fd, pool); + ret = imap_hibernate_client_input_args(conn, (const void *)args, + fd, pool); if (ret >= 0 && client->debug) e_debug(conn->event, "Create client with input: %s", line); pool_unref(&pool); diff --git a/src/imap/imap-master-client.c b/src/imap/imap-master-client.c index 0257fb2de8..f3556de581 100644 --- a/src/imap/imap-master-client.c +++ b/src/imap/imap-master-client.c @@ -371,7 +371,8 @@ imap_master_client_input_line(struct connection *conn, const char *line) pool = pool_alloconly_create("imap master client cmd", 1024); args = p_strsplit_tabescaped(pool, line); - ret = imap_master_client_input_args(conn, (void *)args, fd_client, pool); + ret = imap_master_client_input_args(conn, (const void *)args, + fd_client, pool); pool_unref(&pool); return ret; } diff --git a/src/lib-http/http-response-parser.c b/src/lib-http/http-response-parser.c index e7162ee45e..e381403337 100644 --- a/src/lib-http/http-response-parser.c +++ b/src/lib-http/http-response-parser.c @@ -303,7 +303,7 @@ http_response_parse_retry_after(const char *hdrval, time_t resp_time, } return (http_date_parse - ((unsigned char *)hdrval, strlen(hdrval), retry_after_r) ? 0 : -1); + ((const unsigned char *)hdrval, strlen(hdrval), retry_after_r) ? 0 : -1); } uoff_t http_response_parser_get_last_offset(struct http_response_parser *parser) diff --git a/src/lib-http/test-http-client.c b/src/lib-http/test-http-client.c index ecde11ef74..fc24bfa50d 100644 --- a/src/lib-http/test-http-client.c +++ b/src/lib-http/test-http-client.c @@ -141,7 +141,7 @@ static void run_tests(struct http_client *http_client) "POST", "test.dovecot.org", "/http/post/index.php", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query1, strlen(test_query1)); + ((const unsigned char *)test_query1, strlen(test_query1)); http_client_request_set_payload(http_req, post_payload, FALSE); i_stream_unref(&post_payload); http_client_request_add_header(http_req, @@ -153,7 +153,7 @@ static void run_tests(struct http_client *http_client) "POST", "test.dovecot.org", "/http/post/index.php", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query2, strlen(test_query2)); + ((const unsigned char *)test_query2, strlen(test_query2)); http_client_request_set_payload(http_req, post_payload, TRUE); i_stream_unref(&post_payload); http_client_request_add_header(http_req, @@ -201,7 +201,7 @@ static void run_tests(struct http_client *http_client) "POST", "posttestserver.com", "/post.php", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query1, strlen(test_query1)); + ((const unsigned char *)test_query1, strlen(test_query1)); http_client_request_set_payload(http_req, post_payload, TRUE); i_stream_unref(&post_payload); http_client_request_set_ssl(http_req, TRUE); @@ -212,7 +212,7 @@ static void run_tests(struct http_client *http_client) "POST", "posttestserver.com", "/post.php", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query1, strlen(test_query1)); + ((const unsigned char *)test_query1, strlen(test_query1)); http_client_request_set_payload(http_req, post_payload, TRUE); i_stream_unref(&post_payload); http_client_request_set_ssl(http_req, TRUE); @@ -223,7 +223,7 @@ static void run_tests(struct http_client *http_client) "POST", "posttestserver.com", "/post.php", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query1, strlen(test_query1)); + ((const unsigned char *)test_query1, strlen(test_query1)); http_client_request_set_payload(http_req, post_payload, TRUE); i_stream_unref(&post_payload); http_client_request_set_ssl(http_req, TRUE); @@ -246,7 +246,7 @@ static void run_tests(struct http_client *http_client) "POST", "jigsaw.w3.org", "/HTTP/300/Go_307", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query3, strlen(test_query3)); + ((const unsigned char *)test_query3, strlen(test_query3)); http_client_request_set_payload(http_req, post_payload, FALSE); i_stream_unref(&post_payload); http_client_request_submit(http_req); @@ -256,7 +256,7 @@ static void run_tests(struct http_client *http_client) "POST", "jigsaw.w3.org", "/HTTP/300/Go_307", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query3, strlen(test_query3)); + ((const unsigned char *)test_query3, strlen(test_query3)); http_client_request_set_payload(http_req, post_payload, FALSE); i_stream_unref(&post_payload); http_client_request_submit(http_req); @@ -266,7 +266,7 @@ static void run_tests(struct http_client *http_client) "POST", "jigsaw.w3.org", "/HTTP/300/Go_307", got_request_response, test_req); post_payload = i_stream_create_from_data - ((unsigned char *)test_query3, strlen(test_query3)); + ((const unsigned char *)test_query3, strlen(test_query3)); http_client_request_set_payload(http_req, post_payload, FALSE); i_stream_unref(&post_payload); http_client_request_submit(http_req); diff --git a/src/lib-ldap/ldap-search.c b/src/lib-ldap/ldap-search.c index 962fd08bca..694fd6dfaf 100644 --- a/src/lib-ldap/ldap-search.c +++ b/src/lib-ldap/ldap-search.c @@ -152,7 +152,7 @@ void ldap_connection_search_start(struct ldap_connection *conn, if (input->attributes != NULL) { ARRAY_TYPE(const_string) arr; p_array_init(&arr, req->pool, 8); - for(const char **ptr = (const char**)input->attributes; *ptr != NULL; ptr++) { + for (const char *const *ptr = input->attributes; *ptr != NULL; ptr++) { const char *tmp = p_strdup(req->pool, *ptr); array_push_back(&arr, &tmp); } diff --git a/src/lib-mail/test-message-address.c b/src/lib-mail/test-message-address.c index 2488114cc7..e6204bb058 100644 --- a/src/lib-mail/test-message-address.c +++ b/src/lib-mail/test-message-address.c @@ -405,7 +405,7 @@ test_parse_path(const char *input, const struct message_address **addr_r) if (input_len > 0) input = input_dup = i_memdup(input, input_len); ret = message_address_parse_path(pool_datastack_create(), - (unsigned char *)input, input_len, + (const unsigned char *)input, input_len, &addr); if (input_len > 0) i_free(input_dup); diff --git a/src/lib-smtp/smtp-parser.c b/src/lib-smtp/smtp-parser.c index a704698b11..5672ff0c48 100644 --- a/src/lib-smtp/smtp-parser.c +++ b/src/lib-smtp/smtp-parser.c @@ -121,8 +121,8 @@ void smtp_parser_init(struct smtp_parser *parser, pool_t pool, const char *data) { parser->pool = pool; - parser->begin = parser->cur = (unsigned char *)data; - parser->end = (unsigned char *)data + strlen(data); + parser->begin = parser->cur = (const unsigned char *)data; + parser->end = parser->begin + strlen(data); parser->error = NULL; } diff --git a/src/lib-test/test-ostream.c b/src/lib-test/test-ostream.c index ea42e7a7fb..4ca3a4a008 100644 --- a/src/lib-test/test-ostream.c +++ b/src/lib-test/test-ostream.c @@ -133,7 +133,8 @@ o_stream_test_flush_pending(struct ostream_private *stream, bool set) static size_t o_stream_test_get_buffer_used_size(const struct ostream_private *stream) { - struct test_ostream *tstream = (struct test_ostream *)stream; + const struct test_ostream *tstream = + (const struct test_ostream *)stream; return tstream->internal_buf == NULL ? 0 : tstream->internal_buf->used; diff --git a/src/lib/test-array.c b/src/lib/test-array.c index eddf52406b..73f6ae55bb 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -84,7 +84,7 @@ static void test_array_foreach_elem_string(void) t_array_init(&cblurbs, 32); for (i = 0; i < 10; i++) { cstring = t_strdup_printf("x%iy", i); - string = (char *)cstring; + string = t_strdup_noconst(cstring); array_push_back(&blurbs, &string); array_push_back(&cblurbs, &cstring); } diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index 02a8d622c6..498bc88e48 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -1177,7 +1177,7 @@ int uri_check(const char *uri, enum uri_parse_flags flags, const char **error_r) { return uri_check_data - ((unsigned char *)uri, strlen(uri), flags, error_r); + ((const unsigned char *)uri, strlen(uri), flags, error_r); } /*