libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b6f083d884729d095b6e9a8c11e5cee93267746b
parent 99f31f0547557d7bf119d7e93b877082b8ff34cd
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed,  1 Sep 2021 19:16:21 +0300

Fixed preprocessor error, fixed timeout calculation
with 64 bit time_t introduced by e42ec8f54d28c982307367c483cee34ade5c54f8

Diffstat:
Mconfigure.ac | 31+++++++++++++++++++++++++++++++
Msrc/microhttpd/daemon.c | 16+++++++++++++---
2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -1072,6 +1072,37 @@ AC_CHECK_HEADER([[search.h]], AM_CONDITIONAL([MHD_HAVE_TSEARCH], [[test "x$ac_cv_header_search_h" = xyes && test "x$HAVE_TSEARCH" = "x1" && test "x$REPLACE_TSEARCH" != "x1"]]) +# Check for types sizes +AC_CACHE_CHECK([size of tv_sec member of struct timeval], [mhd_cv_size_timeval_tv_sec], + [ + AC_COMPUTE_INT([mhd_cv_size_timeval_tv_sec], [((long int)sizeof(test_var.tv_sec))], + [[ +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif /* HAVE_SYS_TIME_H */ +#ifdef HAVE_TIME_H +#include <time.h> +#endif /* HAVE_TIME_H */ +#if HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif /* HAVE_SYS_TYPES_H */ +static struct timeval test_var; + ]], + [ + # The size is used only to exclude additional checks/comparision in code + # to avoid compiler warnings. With larger size MHD code will use + # additional checks which ensure that value will fit but it may produce + # a harmless compiler warning. + AC_MSG_WARN([The size cannot be determined, assuming 8.]) + mhd_cv_size_timeval_tv_sec=8 + ] + ) + ] +) +AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec], + [The size of `tv_sec' member of `struct timeval', as computed by sizeof]) +AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]]) + AC_CHECK_HEADERS([dlfcn.h],[have_tlsplugin=yes],[have_tlsplugin=no], [AC_INCLUDES_DEFAULT]) AM_CONDITIONAL([MHD_HAVE_TLS_PLUGIN], [[test "x$have_tlsplugin" = xyes]]) diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2008,12 +2008,13 @@ thread_main_handle_connection (void *data) else { const uint64_t mseconds_left = timeout - since_actv; -#if UINT64_MAX != TIMEVAL_TV_SEC_MAX +#if (SIZEOF_UINT64_T - 1) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC if (mseconds_left / 1000 > TIMEVAL_TV_SEC_MAX) tv.tv_sec = TIMEVAL_TV_SEC_MAX; else - tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) mseconds_left / 1000; -#endif /* UINT64_MAX != TIMEVAL_TV_SEC_MAX */ +#endif /* (SIZEOF_UINT64_T - 1) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC */ + tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) mseconds_left / 1000; + tv.tv_usec = (mseconds_left % 1000) * 1000; } tvp = &tv; @@ -8143,6 +8144,15 @@ MHD_init (void) MHD_monotonic_sec_counter_init (); MHD_send_init_static_vars_ (); MHD_init_mem_pools_ (); + /* Check whether sizes were correctly detected by configure */ +#ifdef _DEBUG + if (1) + { + struct timeval tv; + mhd_assert (sizeof(tv.tv_sec) == SIZEOF_STRUCT_TIMEVAL_TV_SEC); + } +#endif /* _DEBUG */ + mhd_assert (sizeof(uint64_t) == SIZEOF_UINT64_T); }