]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Check for empty body in source code
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 9 Feb 2011 15:23:29 +0000 (15:23 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 9 Feb 2011 15:23:29 +0000 (15:23 +0000)
Enable a warning in gcc to stop the compilation if an empty body is found after
some control structures. It should detect stray semi-colons at the end of the
control structures such as if, for, while,...

CMakeLists.txt
configure.in

index 133cf0be43a61b4c13a4bcde2ca2db25b7836565..8b2cc7c5b07191ecb7624c4680fd64b1a742a2e1 100755 (executable)
@@ -329,11 +329,18 @@ OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF)
 IF(ENABLE_EXTRA_PROTECT)
    GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
    SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
+
    CHECK_C_COMPILER_FLAG("-Wformat -Werror=format-security" HAVE_WERROR_FORMAT_SECURITY)
    IF(HAVE_WERROR_FORMAT_SECURITY)
       GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
       SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Wformat -Werror=format-security")
    ENDIF(HAVE_WERROR_FORMAT_SECURITY)
+
+   CHECK_C_COMPILER_FLAG("-Wempty-body" HAVE_EMPTY_BODY)
+   IF(HAVE_EMPTY_BODY)
+      GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
+      SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Wempty-body")
+   ENDIF(HAVE_EMPTY_BODY)
 ENDIF(ENABLE_EXTRA_PROTECT)
 
 # Compile sarg for debugging
index e15aba9dac36d9c4f8fa5e5c5959bfe9f68bdee8..48b32a0c5021c0795a89fcf9a3c07db7daca92fb 100644 (file)
@@ -215,6 +215,15 @@ AC_ARG_ENABLE(extraprotection,
        if test "$have_format_security" == "no" ; then
           CFLAGS="${saved_CFLAGS}"
        fi
+
+       AC_MSG_CHECKING([for empty body flag in $CC])
+       saved_CFLAGS="${CFLAGS}"
+       CFLAGS="${CFLAGS} -Wempty-body"
+       AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],[have_empty_body="yes"],[have_empty_body="no"])
+       AC_MSG_RESULT($have_empty_body)
+       if test "$have_empty_body" == "no" ; then
+          CFLAGS="${saved_CFLAGS}"
+       fi
     fi
 ])