1From b0a64db90a24469e36978c748417ebe456b34d59 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 22 Apr 2017 11:54:57 -0700
4Subject: [PATCH] configure: Check for -Wno-error=format-truncation compiler
5 option
6
7If this option is supported by compiler then disable it ( gcc7+)
8Use -Werror to elevate the warning to an error in case compiler like clang
9which warn about unknown options but not error out unless asked for
10
11Fixes
12client.c:834:23: error: '%s' directive output may be truncated writing up to 1023 bytes into a region of size 1010 [-Werror=format-truncation=]
13
14Signed-off-by: Khem Raj <raj.khem@gmail.com>
15
16---
17 configure.ac                |  1 +
18 m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++
19 2 files changed, 75 insertions(+)
20 create mode 100644 m4/ax_check_compile_flag.m4
21
22diff --git a/configure.ac b/configure.ac
23index a7eca97d..560eb988 100644
24--- a/configure.ac
25+++ b/configure.ac
26@@ -6794,6 +6794,7 @@ if test "x$enable_werror" != "xno"; then
27   AM_CFLAGS="$AM_CFLAGS -Werror"
28   AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
29 fi
30+AX_CHECK_COMPILE_FLAG([-Werror -Werror=format-truncation],[AM_CFLAGS="$AM_CFLAGS -Wno-error=format-truncation" AM_CXXFLAGS="$AM_CXXFLAGS -Wno-error=format-truncation"])
31
32 AC_SUBST([AM_CFLAGS])
33 AC_SUBST([AM_CXXFLAGS])
34diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
35new file mode 100644
36index 00000000..dcabb92a
37--- /dev/null
38+++ b/m4/ax_check_compile_flag.m4
39@@ -0,0 +1,74 @@
40+# ===========================================================================
41+#  https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
42+# ===========================================================================
43+#
44+# SYNOPSIS
45+#
46+#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
47+#
48+# DESCRIPTION
49+#
50+#   Check whether the given FLAG works with the current language's compiler
51+#   or gives an error.  (Warnings, however, are ignored)
52+#
53+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
54+#   success/failure.
55+#
56+#   If EXTRA-FLAGS is defined, it is added to the current language's default
57+#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with
58+#   the flags: "CFLAGS EXTRA-FLAGS FLAG".  This can for example be used to
59+#   force the compiler to issue an error when a bad flag is given.
60+#
61+#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.
62+#
63+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
64+#   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
65+#
66+# LICENSE
67+#
68+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
69+#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
70+#
71+#   This program is free software: you can redistribute it and/or modify it
72+#   under the terms of the GNU General Public License as published by the
73+#   Free Software Foundation, either version 3 of the License, or (at your
74+#   option) any later version.
75+#
76+#   This program is distributed in the hope that it will be useful, but
77+#   WITHOUT ANY WARRANTY; without even the implied warranty of
78+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
79+#   Public License for more details.
80+#
81+#   You should have received a copy of the GNU General Public License along
82+#   with this program. If not, see <https://www.gnu.org/licenses/>.
83+#
84+#   As a special exception, the respective Autoconf Macro's copyright owner
85+#   gives unlimited permission to copy, distribute and modify the configure
86+#   scripts that are the output of Autoconf when processing the Macro. You
87+#   need not follow the terms of the GNU General Public License when using
88+#   or distributing such scripts, even though portions of the text of the
89+#   Macro appear in them. The GNU General Public License (GPL) does govern
90+#   all other use of the material that constitutes the Autoconf Macro.
91+#
92+#   This special exception to the GPL applies to versions of the Autoconf
93+#   Macro released by the Autoconf Archive. When you make and distribute a
94+#   modified version of the Autoconf Macro, you may extend this special
95+#   exception to the GPL to apply to your modified version as well.
96+
97+#serial 5
98+
99+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
100+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
101+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
102+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
103+  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
104+  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
105+  AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
106+    [AS_VAR_SET(CACHEVAR,[yes])],
107+    [AS_VAR_SET(CACHEVAR,[no])])
108+  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
109+AS_VAR_IF(CACHEVAR,yes,
110+  [m4_default([$2], :)],
111+  [m4_default([$3], :)])
112+AS_VAR_POPDEF([CACHEVAR])dnl
113+])dnl AX_CHECK_COMPILE_FLAGS
114