From: Mike Kaplinskiy Date: Mon, 22 Jun 2015 23:15:24 +0000 (-0700) Subject: Add ./configure check for vsnprintf returning negative on error X-Git-Tag: v0.48.0~28 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=61a1244ec0d11e8a612c4e2614c8cea32f4d87d4;hp=33f2a1c9f813a5a54aa2aedd333ee5208e724f8b Add ./configure check for vsnprintf returning negative on error Summary: This is slightly more correct than assuming that __APPLE__ is the only place this assumption breaks. Pulled from relevant section of folly-PR#95, other sections are either already applied by other fixes, or have been code-moved. Closes #95 Reviewed By: @jwatzman Differential Revision: D2178439 --- diff --git a/folly/configure.ac b/folly/configure.ac index 8b975066..3a4311a3 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -253,6 +253,25 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then [Define to 1 if the linker supports weak symbols.]) fi +AC_CACHE_CHECK( + [for vsnprintf reporting bad format strings], + [folly_cv_prog_vsnprintf_bad_format], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE[ + #include + + int main(int argc, char** argv) { + char buf[256]; + return vsnprintf(buf, sizeof(buf), "%", 1) < 0 ? 0 : 1; + }]], + [folly_cv_prog_vsnprintf_bad_format="yes"], + [folly_cv_prog_vsnprintf_bad_format="no"])]) + +if test "$folly_cv_prog_vsnprintf_bad_format" = yes; then + AC_DEFINE([HAVE_VSNPRINTF_ERRORS], [1], + [Define to 1 if the vsnprintf supports returning errors on bad format strings.]) +fi + AC_SEARCH_LIBS([cplus_demangle_v3_callback], [iberty_pic iberty]) if test "$ac_cv_search_cplus_demangle_v3_callback" != "no" ; then AC_DEFINE([HAVE_CPLUS_DEMANGLE_V3_CALLBACK], [1], diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index bda025b7..3c5ecf31 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -102,7 +102,7 @@ void vprintfError(const char* fmt, ...) { // OSX's sprintf family does not return a negative number on a bad format // string, but Linux does. It's unclear to me which behavior is more // correct. -#if !__APPLE__ +#ifdef HAVE_VSNPRINTF_ERRORS EXPECT_THROW({stringVPrintf(fmt, ap);}, std::runtime_error); #endif