libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit aa3146708088f2763474c08067084b6910039959
parent 6c8ff9a082e87c9cf440d581daee2962ef06a7b1
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Fri, 30 Oct 2026 17:42:48 +0100

upgrade_prep.c: minor code adjustment

Diffstat:
Msrc/mhd2/upgrade_prep.c | 27+++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/mhd2/upgrade_prep.c b/src/mhd2/upgrade_prep.c @@ -74,24 +74,26 @@ * Check whether the provided data fits the buffer and append provided data * to the buffer * @param buf_size the size of the @a buf buffer - * @param buf the buffer to use + * @param buf the buffer to use, must not be NULL * @param[in,out] pbuf_used the pointer to the variable with current offset in * the @a buf buffer, updated if @a copy_data is added - * @param copy_size the size of the @a copy_data - * @param copy_data the data to append to the buffer + * @param copy_size the size of the @a copy_data, must be non-zero + * @param copy_data the data to append to the buffer, must not be NULL * @return 'true' if @a copy_data has been appended to the @a buf buffer, * 'false' if @a buf buffer has not enough space */ -mhd_static_inline +mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2, 1) -MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_INOUT_ (3) +MHD_FN_PAR_INOUT_ (3) MHD_FN_PAR_IN_SIZE_ (5, 4) bool buf_append (size_t buf_size, - char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], + char *buf, size_t *restrict pbuf_used, size_t copy_size, const char copy_data[MHD_FN_PAR_DYN_ARR_SIZE_ (copy_size)]) { + mhd_assert (0 != copy_size); + if ((*pbuf_used + copy_size > buf_size) || (((size_t)(*pbuf_used + copy_size)) < copy_size)) return false; @@ -130,7 +132,8 @@ enum mhd_UpgradeHeaderBuildRes * switched to the "upgraded" mode. * @param c the connection to use * @param buf_size the size of the @a buf buffer - * @param[out] buf the buffer to build the reply + * @param[out] buf the buffer to build the reply, + * can be NULL if @a buf_size is zero * @param[out] pbuf_used the pointer to the variable receiving the size of * the reply header in the @a buf buffer * @param upgrade_hdr_value the value of the "Upgrade:" reply header @@ -142,16 +145,17 @@ enum mhd_UpgradeHeaderBuildRes * @a pbuf_used has been updated, * #MHD_UPGRADE_HDR_BUILD_NO_MEM if @a buf has not enough space to build * the reply header (the error is not yet logged), - * #MHD_UPGRADE_HDR_BUILD_NO_MEM if any other error occurs (the error + * #MHD_UPGRADE_HDR_BUILD_OTHER_ERR if any other error occurs (the error * has been logged) */ -static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) +static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_IF_NONZERO_ (3, 2) +MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_NONNULL_ (5) MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_CSTR_ (5) MHD_FN_PAR_NONNULL_IF_NONZERO_ (7, 6) MHD_FN_PAR_IN_SIZE_ (7, 6) enum mhd_UpgradeHeaderBuildRes build_reply_header (struct MHD_Connection *restrict c, const size_t buf_size, - char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], + char *buf, size_t *pbuf_used, const char *restrict upgrade_hdr_value, size_t num_headers, @@ -173,6 +177,9 @@ build_reply_header (struct MHD_Connection *restrict c, mhd_assert ((0 == c->rq.cntn.cntn_size) \ || (mhd_HTTP_STAGE_FULL_REQ_RECEIVED == c->stage)); + if (0 == buf_size) + return MHD_UPGRADE_HDR_BUILD_NO_MEM; + buf_used = 0; if (c->rq.have_expect_100 && !c->rp.sent_100_cntn)