Allocate stacks with guard pages by default
[folly.git] / folly / Format.cpp
index 64e2cae56273771f47e1423fa1e6d81d6e70ee3a..0d1d61b126d19e7ad99be135922aef04575a4f68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
 
 #include <folly/Format.h>
 
+#include <folly/portability/Constexpr.h>
+
 #include <double-conversion/double-conversion.h>
 
 namespace folly {
@@ -48,11 +50,13 @@ void FormatValue<double>::formatHelper(
   }
 
   // 2+: for null terminator and optional sign shenanigans.
-  char buf[2 + std::max(
-      2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint +
-       DoubleToStringConverter::kMaxFixedDigitsAfterPoint,
-      std::max(8 + DoubleToStringConverter::kMaxExponentialDigits,
-      7 + DoubleToStringConverter::kMaxPrecisionDigits))];
+  constexpr size_t bufLen =
+      2 + constexpr_max(
+              2 + DoubleToStringConverter::kMaxFixedDigitsBeforePoint +
+                  DoubleToStringConverter::kMaxFixedDigitsAfterPoint,
+              constexpr_max(8 + DoubleToStringConverter::kMaxExponentialDigits,
+                            7 + DoubleToStringConverter::kMaxPrecisionDigits));
+  char buf[bufLen];
   StringBuilder builder(buf + 1, static_cast<int> (sizeof(buf) - 1));
 
   char plusSign;