Commit 344088dc authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Allow building with -Wshift-sign-overflow

Summary: Prior to C++14 these shifts are undefined behavior, but the unsigned version is not, so do the shifts on unsigned values before converting to the final type.

Reviewed By: yfeldblum

Differential Revision: D4309311

fbshipit-source-id: 914b207bac2f77a96c07a8a5df81980c672aa677
parent 0d6a706b
...@@ -154,14 +154,14 @@ TEST(Json, BoolConversion) { ...@@ -154,14 +154,14 @@ TEST(Json, BoolConversion) {
} }
TEST(Json, JavascriptSafe) { TEST(Json, JavascriptSafe) {
auto badDouble = (1ll << 63ll) + 1; auto badDouble = int64_t((1ULL << 63ULL) + 1);
dynamic badDyn = badDouble; dynamic badDyn = badDouble;
EXPECT_EQ(folly::toJson(badDouble), folly::to<std::string>(badDouble)); EXPECT_EQ(folly::toJson(badDouble), folly::to<std::string>(badDouble));
folly::json::serialization_opts opts; folly::json::serialization_opts opts;
opts.javascript_safe = true; opts.javascript_safe = true;
EXPECT_ANY_THROW(folly::json::serialize(badDouble, opts)); EXPECT_ANY_THROW(folly::json::serialize(badDouble, opts));
auto okDouble = 1ll << 63ll; auto okDouble = int64_t(1ULL << 63ULL);
dynamic okDyn = okDouble; dynamic okDyn = okDouble;
EXPECT_EQ(folly::toJson(okDouble), folly::to<std::string>(okDouble)); EXPECT_EQ(folly::toJson(okDouble), folly::to<std::string>(okDouble));
} }
......
...@@ -91,7 +91,8 @@ template<class T> struct PslTest { ...@@ -91,7 +91,8 @@ template<class T> struct PslTest {
PslTest() { lock.init(); } PslTest() { lock.init(); }
void doTest() { void doTest() {
T ourVal = rand() % (T(1) << (sizeof(T) * 8 - 1)); using UT = typename std::make_unsigned<T>::type;
T ourVal = rand() % T(UT(1) << (sizeof(UT) * 8 - 1));
for (int i = 0; i < 10000; ++i) { for (int i = 0; i < 10000; ++i) {
std::lock_guard<PicoSpinLock<T>> guard(lock); std::lock_guard<PicoSpinLock<T>> guard(lock);
lock.setData(ourVal); lock.setData(ourVal);
......
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