Commit 82ba5835 authored by Anton Likhtarov's avatar Anton Likhtarov Committed by facebook-github-bot-1

Disallow nullptr literal in StringPiece constructor

Summary: This disallows implicitly constructing a StringPiece from a literal nullptr at compile time
(without this change, nullptr would cause a segfault in strlen()).

Reviewed By: meyering, andriigrynenko

Differential Revision: D2603597

fb-gh-sync-id: cafbc45945bacc72a7c89310b99aa62d19a3ff9f
parent 89e6ee60
......@@ -388,6 +388,11 @@ estimateSpaceNeeded(Src value) {
return folly::StringPiece(value).size();
}
template<>
inline size_t estimateSpaceNeeded(std::nullptr_t value) {
return 0;
}
template<class Src>
typename std::enable_if<
std::is_pointer<Src>::value &&
......
......@@ -27,6 +27,7 @@
#include <algorithm>
#include <boost/operators.hpp>
#include <climits>
#include <cstddef>
#include <cstring>
#include <glog/logging.h>
#include <iosfwd>
......@@ -200,6 +201,12 @@ public:
constexpr Range(Iter start, size_t size)
: b_(start), e_(start + size) { }
# if !defined(__clang__) || __clang_major__ > 3 || \
(__clang_major__ == 3 && __clang_minor__ > 6)
// Clang 3.6 crashes on this line
/* implicit */ Range(std::nullptr_t) = delete;
# endif
template <class T = Iter, typename detail::IsCharPointer<T>::type = 0>
constexpr /* implicit */ Range(Iter str)
: b_(str), e_(str + constexpr_strlen(str)) {}
......
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