libmicrohttpd2

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

commit 461aa80895bed80853d7a520386dbb8eed71cf1d
parent d83aea3a698a261c05c122882e84a96a01e75ce3
Author: Evgeny Grin <k2k@drgrin.dev>
Date:   Sun,  4 May 2025 11:27:44 +0300

lib_get_info: fixed for systems without defined VERSION macro

Diffstat:
Msrc/mhd2/lib_get_info.c | 56+++++++++++++++++++++++++++++++++++---------------------
1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/mhd2/lib_get_info.c b/src/mhd2/lib_get_info.c @@ -111,30 +111,44 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, return MHD_SC_OK; #else /* ! VERSION */ static char str_buf[10] = /* Larger than needed */ - {0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; - if (0 != str_buf[8]) + {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + static size_t str_len = 0; + if ((0 == str_len) || + (0 != str_buf[str_len])) { - uint_fast32_t ver_num = MHD_VERSION; - uint8_t digit; - - digit = (uint8_t) (ver_num >> 24); - (void) mhd_bin_to_hex (&digit, - 1, - str_buf); - str_buf[2] = '.'; - digit = (uint8_t) (ver_num >> 16); - (void) mhd_bin_to_hex (&digit, - 1, - str_buf + 3); - str_buf[5] = '.'; - digit = (uint8_t) (ver_num >> 8); - (void) mhd_bin_to_hex (&digit, - 1, - str_buf + 6); - str_buf[8] = 0; + const uint_fast32_t ver_num = MHD_VERSION; + size_t pos = 0; + + mhd_assert (0 == str_buf[0]); + + pos += mhd_uint32_to_strx ((ver_num >> 24) & 0xFFu, + str_buf + pos, + sizeof(str_buf) - 1 - pos); + mhd_assert (1 <= pos); + mhd_assert (2 >= pos); + + str_buf[pos++] = '.'; + + pos += mhd_uint32_to_strx ((ver_num >> 16) & 0xFFu, + str_buf + pos, + sizeof(str_buf) - 1 - pos); + mhd_assert (3 <= pos); + mhd_assert (5 >= pos); + + str_buf[pos++] = '.'; + + pos += mhd_uint32_to_strx ((ver_num >> 8) & 0xFFu, + str_buf + pos, + sizeof(str_buf) - 1 - pos); + mhd_assert (5 <= pos); + mhd_assert (8 >= pos); + mhd_assert (sizeof(str_buf) > pos); + + str_buf[pos] = 0; + str_len = pos; } output_buf->v_version_string.cstr = str_buf; - output_buf->v_version_string.len = 8; + output_buf->v_version_string.len = str_len; return MHD_SC_OK; #endif /* ! VERSION */ }