Просмотр исходного кода

Merge branch 'maint'

* maint:
  Latest automake
  Don't enable SEGV/BUS handlers when address sanitizer is active
  vprintf functions can use printf format attribute too
  sdprintf: Avoid processing if not needed
Bryan Drewery 7 лет назад
Родитель
Сommit
1838de306f
5 измененных файлов с 43 добавлено и 31 удалено
  1. 1 0
      build/autotools/configure.ac
  2. 28 27
      configure
  3. 2 2
      src/config.h.in
  4. 10 0
      src/debug.cc
  5. 2 2
      src/sprintf.h

+ 1 - 0
build/autotools/configure.ac

@@ -50,6 +50,7 @@ fi
 CXX_FLAG_CHECK_LINK([DEBCXXFLAGS], [-fsanitize=address], [fsanitize_address])
 if [[ "${ax_cv_prog_cc_fsanitize_address}" = "yes" ]]; then
   DEBLDFLAGS="${DEBLDFLAGS} -fsanitize=address"
+  DEBCXXFLAGS="${DEBCXXFLAGS} -D__SANITIZE_ADDRESS__"
 fi
 CXX_FLAG_CHECK([DEBCXXFLAGS], [-fstack-protector-all], [stackprotectorall])
 CXX_FLAG_CHECK([DEBCXXFLAGS], [-Wconditional-uninitialized], [w_conditional_uninitialized])

+ 28 - 27
configure

@@ -4043,6 +4043,7 @@ EOF
 
 if [ "${ax_cv_prog_cc_fsanitize_address}" = "yes" ]; then
   DEBLDFLAGS="${DEBLDFLAGS} -fsanitize=address"
+  DEBCXXFLAGS="${DEBCXXFLAGS} -D__SANITIZE_ADDRESS__"
 fi
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler understands -fstack-protector-all" >&5
@@ -7575,18 +7576,18 @@ else
 /* end build/confdefs.h.  */
 
   /* For now, do not test the preprocessor; as of 2007 there are too many
-         implementations with broken preprocessors.  Perhaps this can
-         be revisited in 2012.  In the meantime, code should not expect
-         #if to work with literals wider than 32 bits.  */
+	 implementations with broken preprocessors.  Perhaps this can
+	 be revisited in 2012.  In the meantime, code should not expect
+	 #if to work with literals wider than 32 bits.  */
       /* Test literals.  */
       long long int ll = 9223372036854775807ll;
       long long int nll = -9223372036854775807LL;
       unsigned long long int ull = 18446744073709551615ULL;
       /* Test constant expressions.   */
       typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
-                     ? 1 : -1)];
+		     ? 1 : -1)];
       typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
-                     ? 1 : -1)];
+		     ? 1 : -1)];
       int i = 63;
 int
 main ()
@@ -7595,9 +7596,9 @@ main ()
       long long int llmax = 9223372036854775807ll;
       unsigned long long int ullmax = 18446744073709551615ull;
       return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
-              | (llmax / ll) | (llmax % ll)
-              | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
-              | (ullmax / ull) | (ullmax % ull));
+	      | (llmax / ll) | (llmax % ll)
+	      | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
+	      | (ullmax / ull) | (ullmax % ull));
   ;
   return 0;
 }
@@ -7629,33 +7630,33 @@ if ${ac_cv_type_long_long_int+:} false; then :
 else
   ac_cv_type_long_long_int=yes
       if test "x${ac_cv_prog_cc_c99-no}" = xno; then
-        ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
-        if test $ac_cv_type_long_long_int = yes; then
-                                        if test "$cross_compiling" = yes; then :
+	ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
+	if test $ac_cv_type_long_long_int = yes; then
+	  	  	  	  if test "$cross_compiling" = yes; then :
   :
 else
   cat build/confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end build/confdefs.h.  */
 #include <limits.h>
-                 #ifndef LLONG_MAX
-                 # define HALF \
-                          (1LL << (sizeof (long long int) * CHAR_BIT - 2))
-                 # define LLONG_MAX (HALF - 1 + HALF)
-                 #endif
+		 #ifndef LLONG_MAX
+		 # define HALF \
+			  (1LL << (sizeof (long long int) * CHAR_BIT - 2))
+		 # define LLONG_MAX (HALF - 1 + HALF)
+		 #endif
 int
 main ()
 {
 long long int n = 1;
-                 int i;
-                 for (i = 0; ; i++)
-                   {
-                     long long int m = n << i;
-                     if (m >> i != n)
-                       return 1;
-                     if (LLONG_MAX / 2 < m)
-                       break;
-                   }
-                 return 0;
+		 int i;
+		 for (i = 0; ; i++)
+		   {
+		     long long int m = n << i;
+		     if (m >> i != n)
+		       return 1;
+		     if (LLONG_MAX / 2 < m)
+		       break;
+		   }
+		 return 0;
   ;
   return 0;
 }
@@ -7669,7 +7670,7 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
   conftest.$ac_objext conftest.beam conftest.$ac_ext
 fi
 
-        fi
+	fi
       fi
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_long_int" >&5

+ 2 - 2
src/config.h.in

@@ -84,7 +84,7 @@
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 
-/* Define to 1 if the system has the type 'long long int'. */
+/* Define to 1 if the system has the type `long long int'. */
 #undef HAVE_LONG_LONG_INT
 
 /* Define to 1 if you have the `madvise' function. */
@@ -221,7 +221,7 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
-/* Define to 1 if the system has the type 'unsigned long long int'. */
+/* Define to 1 if the system has the type `unsigned long long int'. */
 #undef HAVE_UNSIGNED_LONG_LONG_INT
 
 /* Define to 1 if you have the `vsnprintf' function. */

+ 10 - 0
src/debug.cc

@@ -89,6 +89,10 @@ void sdprintf (const char *format, ...)
   char s[2001] = "";
   va_list va;
 
+#ifndef DEBUG
+  if (!sdebug)
+    return;
+#endif
   va_start(va, format);
   egg_vsnprintf(s, sizeof(s), format, va);
   va_end(va);
@@ -180,6 +184,7 @@ static void write_debug(bool fatal = 1)
 static void got_bus(int) __attribute__ ((noreturn));
 #endif /* DEBUG */
 
+#ifndef __SANITIZE_ADDRESS__
 static void got_bus(int z)
 {
   signal(SIGBUS, SIG_DFL);
@@ -191,11 +196,13 @@ static void got_bus(int z)
   exit(1);
 #endif /* DEBUG */
 }
+#endif /* !__SANITIZE_ADDRESS__ */
 
 #ifndef DEBUG
 static void got_segv(int) __attribute__ ((noreturn));
 #endif /* DEBUG */
 
+#ifndef __SANITIZE_ADDRESS__
 static void got_segv(int z)
 {
   signal(SIGSEGV, SIG_DFL);
@@ -207,6 +214,7 @@ static void got_segv(int z)
   exit(1);
 #endif /* DEBUG */
 }
+#endif /* !__SANITIZE_ADDRESS__ */
 
 #ifndef DEBUG
 static void got_fpe(int) __attribute__ ((noreturn));
@@ -291,8 +299,10 @@ got_usr1(int z)
 
 void init_signals() 
 {
+#ifndef __SANITIZE_ADDRESS__
   signal(SIGBUS, got_bus);
   signal(SIGSEGV, got_segv);
+#endif
   signal(SIGFPE, got_fpe);
   signal(SIGTERM, got_term);
   signal(SIGCONT, got_cont);

+ 2 - 2
src/sprintf.h

@@ -7,8 +7,8 @@
 
 #define VSPRINTF_MAXSIZE		4096
 
-size_t simple_vsnprintf(char *, size_t, const char *, va_list);
-size_t simple_vsprintf(char *, const char *, va_list);
+size_t simple_vsnprintf(char *, size_t, const char *, va_list) __attribute__((format(printf, 3, 0)));
+size_t simple_vsprintf(char *, const char *, va_list) __attribute__((format(printf, 2, 0)));
 size_t simple_sprintf (char *, const char *, ...) __attribute__((format(printf, 2, 3)));
 size_t simple_snprintf2 (char *, size_t, const char *, ...);
 size_t simple_snprintf (char *, size_t, const char *, ...) __attribute__((format(printf, 3, 4)));