diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-18 13:11:26 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-19 18:55:27 +0300 |
commit | b6eb14d6469a5d48df977cfcd3b38f2d19e5951f (patch) | |
tree | 414cfbf69a66c926bdc640ded6988924697f4644 /src | |
parent | 57cc8b71135a2d79240bf7edc678697a7192d208 (diff) | |
download | libmicrohttpd-b6eb14d6469a5d48df977cfcd3b38f2d19e5951f.tar.gz libmicrohttpd-b6eb14d6469a5d48df977cfcd3b38f2d19e5951f.zip |
Added workaround for external APIs
Some APIs require non-const pointer even when data is supposed to be
unmodifiable. Added workaround to deal with such APIs without compiler
warnings.
Diffstat (limited to 'src')
-rw-r--r-- | src/microhttpd/daemon.c | 12 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 7 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.c | 4 | ||||
-rw-r--r-- | src/microhttpd/response.c | 4 |
4 files changed, 17 insertions, 10 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index c2f4b2c7..81b3afa9 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -534,7 +534,7 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon) | |||
534 | #endif | 534 | #endif |
535 | return -1; | 535 | return -1; |
536 | } | 536 | } |
537 | cert.data = (unsigned char *) daemon->https_mem_trust; | 537 | cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_trust); |
538 | cert.size = (unsigned int) paramlen; | 538 | cert.size = (unsigned int) paramlen; |
539 | if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, | 539 | if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred, |
540 | &cert, | 540 | &cert, |
@@ -571,9 +571,9 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon) | |||
571 | #endif | 571 | #endif |
572 | return -1; | 572 | return -1; |
573 | } | 573 | } |
574 | key.data = (unsigned char *) daemon->https_mem_key; | 574 | key.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_key); |
575 | key.size = (unsigned int) param1len; | 575 | key.size = (unsigned int) param1len; |
576 | cert.data = (unsigned char *) daemon->https_mem_cert; | 576 | cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_cert); |
577 | cert.size = (unsigned int) param2len; | 577 | cert.size = (unsigned int) param2len; |
578 | 578 | ||
579 | if (NULL != daemon->https_key_password) | 579 | if (NULL != daemon->https_key_password) |
@@ -4948,7 +4948,7 @@ MHD_epoll (struct MHD_Daemon *daemon, | |||
4948 | (-1 != daemon->epoll_upgrade_fd) ) ) | 4948 | (-1 != daemon->epoll_upgrade_fd) ) ) |
4949 | { | 4949 | { |
4950 | event.events = EPOLLIN | EPOLLOUT; | 4950 | event.events = EPOLLIN | EPOLLOUT; |
4951 | event.data.ptr = (void *) upgrade_marker; | 4951 | event.data.ptr = _MHD_DROP_CONST (upgrade_marker); |
4952 | if (0 != epoll_ctl (daemon->epoll_fd, | 4952 | if (0 != epoll_ctl (daemon->epoll_fd, |
4953 | EPOLL_CTL_ADD, | 4953 | EPOLL_CTL_ADD, |
4954 | daemon->epoll_upgrade_fd, | 4954 | daemon->epoll_upgrade_fd, |
@@ -5850,7 +5850,7 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
5850 | #endif | 5850 | #endif |
5851 | return MHD_NO; | 5851 | return MHD_NO; |
5852 | } | 5852 | } |
5853 | dhpar.data = (unsigned char *) pstr; | 5853 | dhpar.data = (unsigned char *) _MHD_DROP_CONST (pstr); |
5854 | pstr_len = strlen (pstr); | 5854 | pstr_len = strlen (pstr); |
5855 | if (UINT_MAX < pstr_len) | 5855 | if (UINT_MAX < pstr_len) |
5856 | { | 5856 | { |
@@ -6340,7 +6340,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon) | |||
6340 | if (MHD_ITC_IS_VALID_ (daemon->itc)) | 6340 | if (MHD_ITC_IS_VALID_ (daemon->itc)) |
6341 | { | 6341 | { |
6342 | event.events = EPOLLIN; | 6342 | event.events = EPOLLIN; |
6343 | event.data.ptr = (void *) epoll_itc_marker; | 6343 | event.data.ptr = _MHD_DROP_CONST (epoll_itc_marker); |
6344 | if (0 != epoll_ctl (daemon->epoll_fd, | 6344 | if (0 != epoll_ctl (daemon->epoll_fd, |
6345 | EPOLL_CTL_ADD, | 6345 | EPOLL_CTL_ADD, |
6346 | MHD_itc_r_fd_ (daemon->itc), | 6346 | MHD_itc_r_fd_ (daemon->itc), |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 95d301f9..3bedf8ed 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -63,6 +63,13 @@ | |||
63 | #include "mhd_sockets.h" | 63 | #include "mhd_sockets.h" |
64 | #include "mhd_itc_types.h" | 64 | #include "mhd_itc_types.h" |
65 | 65 | ||
66 | /** | ||
67 | * Macro to drop 'const' qualifier from pointer without compiler warning. | ||
68 | * To be used *only* to deal with broken external APIs, which require non-const | ||
69 | * pointer to unmodifiable data. | ||
70 | * Must not be used to transform pointers for MHD needs. | ||
71 | */ | ||
72 | #define _MHD_DROP_CONST(ptr) ((void *)((uintptr_t)((const void *)(ptr)))) | ||
66 | 73 | ||
67 | /** | 74 | /** |
68 | * @def _MHD_MACRO_NO | 75 | * @def _MHD_MACRO_NO |
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index f0ebd38d..009283d6 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -1054,9 +1054,9 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection, | |||
1054 | #endif /* ! HAVE_SENDMSG */ | 1054 | #endif /* ! HAVE_SENDMSG */ |
1055 | push_hdr || push_body); | 1055 | push_hdr || push_body); |
1056 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) | 1056 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) |
1057 | vector[0].iov_base = (void *) header; | 1057 | vector[0].iov_base = _MHD_DROP_CONST (header); |
1058 | vector[0].iov_len = header_size; | 1058 | vector[0].iov_len = header_size; |
1059 | vector[1].iov_base = (void *) body; | 1059 | vector[1].iov_base = _MHD_DROP_CONST (body); |
1060 | vector[1].iov_len = body_size; | 1060 | vector[1].iov_len = body_size; |
1061 | 1061 | ||
1062 | #if defined(HAVE_SENDMSG) | 1062 | #if defined(HAVE_SENDMSG) |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index bf1d9c31..8ddde763 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -1623,14 +1623,14 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov, | |||
1623 | #if defined(MHD_WINSOCK_SOCKETS) && defined(_WIN64) | 1623 | #if defined(MHD_WINSOCK_SOCKETS) && defined(_WIN64) |
1624 | while (MHD_IOV_ELMN_MAX_SIZE < element_size) | 1624 | while (MHD_IOV_ELMN_MAX_SIZE < element_size) |
1625 | { | 1625 | { |
1626 | iov_copy[i_cp].iov_base = (char *) buf; | 1626 | iov_copy[i_cp].iov_base = (char *) _MHD_DROP_CONST (buf); |
1627 | iov_copy[i_cp].iov_len = ULONG_MAX; | 1627 | iov_copy[i_cp].iov_len = ULONG_MAX; |
1628 | buf += ULONG_MAX; | 1628 | buf += ULONG_MAX; |
1629 | element_size -= ULONG_MAX; | 1629 | element_size -= ULONG_MAX; |
1630 | i_cp++; | 1630 | i_cp++; |
1631 | } | 1631 | } |
1632 | #endif /* MHD_WINSOCK_SOCKETS && _WIN64 */ | 1632 | #endif /* MHD_WINSOCK_SOCKETS && _WIN64 */ |
1633 | iov_copy[i_cp].iov_base = (void *) buf; | 1633 | iov_copy[i_cp].iov_base = _MHD_DROP_CONST (buf); |
1634 | iov_copy[i_cp].iov_len = (MHD_iov_size_) element_size; | 1634 | iov_copy[i_cp].iov_len = (MHD_iov_size_) element_size; |
1635 | i_cp++; | 1635 | i_cp++; |
1636 | } | 1636 | } |