From 53a691039c1f350229e555070be751d2e4540beb Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Tue, 21 Nov 2023 11:08:02 +0300 Subject: [PATCH] Moved user options counter to shorter its lifetime --- src/microhttpd/daemon.c | 15 ++++++++++++--- src/microhttpd/internal.h | 9 --------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 78153056..44be347a 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -6200,6 +6200,14 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon) */ struct MHD_InterimParams_ { + /** + * The total number of all user options used. + * + * Contains number only of meaningful options, i.e. #MHD_OPTION_END and + * #MHD_OPTION_ARRAY themselves are not counted, while options inside + * #MHD_OPTION_ARRAY are counted. + */ + size_t num_opts; /** * Set to 'true' if @a fdset_size is set by application. */ @@ -6582,7 +6590,7 @@ parse_options_va (struct MHD_Daemon *daemon, { /* Increase counter at start, so resulting value is number of * processed options, including any failed ones. */ - daemon->num_opts++; + params->num_opts++; switch (opt) { case MHD_OPTION_CONNECTION_MEMORY_LIMIT: @@ -6978,7 +6986,7 @@ parse_options_va (struct MHD_Daemon *daemon, VfprintfFunctionPointerType); daemon->custom_error_log_cls = va_arg (ap, void *); - if (1 != daemon->num_opts) + if (1 != params->num_opts) MHD_DLOG (daemon, _ ("MHD_OPTION_EXTERNAL_LOGGER is not the first option " "specified for the daemon. Some messages may be " @@ -7049,7 +7057,7 @@ parse_options_va (struct MHD_Daemon *daemon, #endif /* HAVE_MESSAGES */ break; case MHD_OPTION_ARRAY: - daemon->num_opts--; /* Do not count MHD_OPTION_ARRAY */ + params->num_opts--; /* Do not count MHD_OPTION_ARRAY */ oa = va_arg (ap, struct MHD_OptionItem *); i = 0; while (MHD_OPTION_END != (opt = oa[i].option)) @@ -7754,6 +7762,7 @@ MHD_start_daemon_va (unsigned int flags, } #endif /* HTTPS_SUPPORT */ + interim_params->num_opts = 0; interim_params->fdset_size_set = false; interim_params->fdset_size = 0; interim_params->listen_fd_set = false; diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 3d7d774a..4113e66d 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h @@ -2443,15 +2443,6 @@ struct MHD_Daemon */ unsigned int listen_backlog_size; - /** - * The number of user options used. - * - * Contains number of only meaningful options, i.e. #MHD_OPTION_END - * and #MHD_OPTION_ARRAY are not counted, while options inside - * #MHD_OPTION_ARRAY are counted. - */ - size_t num_opts; - /* TODO: replace with a single member */ /** * The value to be returned by #MHD_get_daemon_info()