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.
This commit is contained in:
Evgeny Grin (Karlson2k)
2022-04-19 18:55:27 +03:00
parent 57cc8b7113
commit b6eb14d646
4 changed files with 17 additions and 10 deletions
+6 -6
View File
@@ -534,7 +534,7 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
#endif
return -1;
}
cert.data = (unsigned char *) daemon->https_mem_trust;
cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_trust);
cert.size = (unsigned int) paramlen;
if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred,
&cert,
@@ -571,9 +571,9 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
#endif
return -1;
}
key.data = (unsigned char *) daemon->https_mem_key;
key.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_key);
key.size = (unsigned int) param1len;
cert.data = (unsigned char *) daemon->https_mem_cert;
cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_cert);
cert.size = (unsigned int) param2len;
if (NULL != daemon->https_key_password)
@@ -4948,7 +4948,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
(-1 != daemon->epoll_upgrade_fd) ) )
{
event.events = EPOLLIN | EPOLLOUT;
event.data.ptr = (void *) upgrade_marker;
event.data.ptr = _MHD_DROP_CONST (upgrade_marker);
if (0 != epoll_ctl (daemon->epoll_fd,
EPOLL_CTL_ADD,
daemon->epoll_upgrade_fd,
@@ -5850,7 +5850,7 @@ parse_options_va (struct MHD_Daemon *daemon,
#endif
return MHD_NO;
}
dhpar.data = (unsigned char *) pstr;
dhpar.data = (unsigned char *) _MHD_DROP_CONST (pstr);
pstr_len = strlen (pstr);
if (UINT_MAX < pstr_len)
{
@@ -6340,7 +6340,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
if (MHD_ITC_IS_VALID_ (daemon->itc))
{
event.events = EPOLLIN;
event.data.ptr = (void *) epoll_itc_marker;
event.data.ptr = _MHD_DROP_CONST (epoll_itc_marker);
if (0 != epoll_ctl (daemon->epoll_fd,
EPOLL_CTL_ADD,
MHD_itc_r_fd_ (daemon->itc),
+7
View File
@@ -63,6 +63,13 @@
#include "mhd_sockets.h"
#include "mhd_itc_types.h"
/**
* Macro to drop 'const' qualifier from pointer without compiler warning.
* To be used *only* to deal with broken external APIs, which require non-const
* pointer to unmodifiable data.
* Must not be used to transform pointers for MHD needs.
*/
#define _MHD_DROP_CONST(ptr) ((void *)((uintptr_t)((const void *)(ptr))))
/**
* @def _MHD_MACRO_NO
+2 -2
View File
@@ -1054,9 +1054,9 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
#endif /* ! HAVE_SENDMSG */
push_hdr || push_body);
#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
vector[0].iov_base = (void *) header;
vector[0].iov_base = _MHD_DROP_CONST (header);
vector[0].iov_len = header_size;
vector[1].iov_base = (void *) body;
vector[1].iov_base = _MHD_DROP_CONST (body);
vector[1].iov_len = body_size;
#if defined(HAVE_SENDMSG)
+2 -2
View File
@@ -1623,14 +1623,14 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
#if defined(MHD_WINSOCK_SOCKETS) && defined(_WIN64)
while (MHD_IOV_ELMN_MAX_SIZE < element_size)
{
iov_copy[i_cp].iov_base = (char *) buf;
iov_copy[i_cp].iov_base = (char *) _MHD_DROP_CONST (buf);
iov_copy[i_cp].iov_len = ULONG_MAX;
buf += ULONG_MAX;
element_size -= ULONG_MAX;
i_cp++;
}
#endif /* MHD_WINSOCK_SOCKETS && _WIN64 */
iov_copy[i_cp].iov_base = (void *) buf;
iov_copy[i_cp].iov_base = _MHD_DROP_CONST (buf);
iov_copy[i_cp].iov_len = (MHD_iov_size_) element_size;
i_cp++;
}