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