Skip to content

Commit

Permalink
fix UBSAN errors in fault_injection_test
Browse files Browse the repository at this point in the history
Summary:
This fixes shift and signed-integer-overflow UBSAN checks in fault_injection_test by using a larger and unsigned type.
Closes facebook#3498

Reviewed By: siying

Differential Revision: D6981116

Pulled By: igorsugak

fbshipit-source-id: 3688f62cce570534b161e9b5f42109ebc9ae5a2c
  • Loading branch information
Igor Sugak authored and facebook-github-bot committed Feb 13, 2018
1 parent dadf016 commit d08d05c
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions db/fault_injection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,17 @@ class FaultInjectionTest : public testing::Test,
return Status::OK();
}

#ifdef ROCKSDB_UBSAN_RUN
#if defined(__clang__)
__attribute__((__no_sanitize__("shift"), no_sanitize("signed-integer-overflow")))
#elif defined(__GNUC__)
__attribute__((__no_sanitize_undefined__))
#endif
#endif
// Return the ith key
Slice Key(int i, std::string* storage) const {
int num = i;
unsigned long long num = i;
if (!sequential_order_) {
// random transfer
const int m = 0x5bd1e995;
num *= m;
num ^= num << 24;
}
char buf[100];
snprintf(buf, sizeof(buf), "%016d", num);
snprintf(buf, sizeof(buf), "%016d", static_cast<int>(num));
storage->assign(buf, strlen(buf));
return Slice(*storage);
}
Expand Down

0 comments on commit d08d05c

Please sign in to comment.