소스 검색

Added support for "noreturn" function declaration.

It should help static analyzer to properly detect code paths.
Evgeny Grin (Karlson2k) 4 년 전
부모
커밋
85db559ed6
3개의 변경된 파일46개의 추가작업 그리고 4개의 파일을 삭제
  1. 42 0
      configure.ac
  2. 1 1
      src/microhttpd/daemon.c
  3. 3 3
      src/testcurl/test_toolarge.c

+ 42 - 0
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

+ 1 - 1
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,

+ 3 - 3
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]))