libmicrohttpd

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

commit 85db559ed6a0df39587cad4d055020a84d18e04b
parent 22aff9e263b1e753715c8417cd3ee61b61768104
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon,  4 Oct 2021 10:32:11 +0300

Added support for "noreturn" function declaration.

It should help static analyzer to properly detect code paths.

Diffstat:
Mconfigure.ac | 42++++++++++++++++++++++++++++++++++++++++++
Msrc/microhttpd/daemon.c | 2+-
Msrc/testcurl/test_toolarge.c | 6+++---
3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -1,5 +1,6 @@ # This file is part of libmicrohttpd. # (C) 2006-2021 Christian Grothoff (and other contributing authors) +# (C) 2014-2021 Evgeny Grin (Karlson2k) # # libmicrohttpd is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published @@ -1107,6 +1108,47 @@ 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"]]) +AC_CACHE_CHECK([for suported 'noreturn' keyword], [mhd_cv_decl_noreturn], + [ + mhd_cv_decl_noreturn="none" + save_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${errattr_CFLAGS}" + for decl_noret in '_Noreturn' '__attribute__((__noreturn__))' '__declspec(noreturn)'; do + AC_LINK_IFELSE([AC_LANG_SOURCE( + [[ +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +${decl_noret} void myexitfunc(int code) +{ +#ifdef HAVE_STDLIB_H + exit (code); +#else + (void)code; +#endif +} + +int main (int argc, char *const *argv) +{ + (void) argv; + if (argc > 2) + myexitfunc (2); + return 0; +} + ]] + )], [mhd_cv_decl_noreturn="${decl_noret}"] + ) + AS_IF([test "x${mhd_cv_decl_noreturn}" != "xnone"], [break]) + done + CFLAGS="${save_CFLAGS}" + ] +) +AS_VAR_IF([mhd_cv_decl_noreturn], ["none"], + [AC_DEFINE([_MHD_NORETURN], [], [Define to supported 'noreturn' function declaration])], + [AC_DEFINE_UNQUOTED([_MHD_NORETURN], [${mhd_cv_decl_noreturn}], [Define to supported 'noreturn' function declaration])] +) + # Check for types sizes # Types sizes are used as an indirect indication of maximum allowed values for types # which is used to exclude by preprocessor some compiler checks for values clips diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -125,7 +125,7 @@ MHD_epoll (struct MHD_Daemon *daemon, * @param line line number with the problem * @param reason error message with details */ -static void +_MHD_NORETURN static void mhd_panic_std (void *cls, const char *file, unsigned int line, diff --git a/src/testcurl/test_toolarge.c b/src/testcurl/test_toolarge.c @@ -113,7 +113,7 @@ #endif -static void +_MHD_NORETURN static void _externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum) { if ((NULL != errDesc) && (0 != errDesc[0])) @@ -137,7 +137,7 @@ _externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum) static char libcurl_errbuf[CURL_ERROR_SIZE] = ""; -static void +_MHD_NORETURN static void _libcurlErrorExit_func (const char *errDesc, const char *funcName, int lineNum) { if ((NULL != errDesc) && (0 != errDesc[0])) @@ -159,7 +159,7 @@ _libcurlErrorExit_func (const char *errDesc, const char *funcName, int lineNum) } -static void +_MHD_NORETURN static void _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum) { if ((NULL != errDesc) && (0 != errDesc[0]))