Commit 61a1244e authored by Mike Kaplinskiy's avatar Mike Kaplinskiy Committed by Sara Golemon

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
parent 33f2a1c9
......@@ -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 <stdio.h>
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],
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment