Commit 1f2e92bf authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

fix some warning violations

Reviewed By: Orvid

Differential Revision: D34031459

fbshipit-source-id: 13e11ff462c5a975851970043d7e673d2905e237
parent c3d483b7
...@@ -74,6 +74,12 @@ class fbvector; ...@@ -74,6 +74,12 @@ class fbvector;
namespace folly { namespace folly {
namespace detail {
inline void* thunk_return_nullptr() {
return nullptr;
}
} // namespace detail
template <class T, class Allocator> template <class T, class Allocator>
class fbvector { class fbvector {
//=========================================================================== //===========================================================================
...@@ -981,26 +987,15 @@ class fbvector { ...@@ -981,26 +987,15 @@ class fbvector {
xallocx(p, newCapacityBytes, 0, 0) == newCapacityBytes) { xallocx(p, newCapacityBytes, 0, 0) == newCapacityBytes) {
impl_.z_ += newCap - oldCap; impl_.z_ += newCap - oldCap;
} else { } else {
T* newB; // intentionally uninitialized T* newB = static_cast<T*>(catch_exception(
if (!catch_exception( [&] { return M_allocate(newCap); }, //
[&] { &detail::thunk_return_nullptr));
newB = M_allocate(newCap); if (!newB) {
return true;
},
[&] { //
return false;
})) {
return; return;
} }
if (!catch_exception( if (!catch_exception(
[&] { [&] { return M_relocate(newB), true; },
M_relocate(newB); [&] { return M_deallocate(newB, newCap), false; })) {
return true;
},
[&] {
M_deallocate(newB, newCap);
return false;
})) {
return; return;
} }
if (impl_.b_) { if (impl_.b_) {
......
...@@ -385,7 +385,10 @@ std::weak_ptr<U> to_weak_ptr_aliasing(const std::shared_ptr<T>& r, U* ptr) { ...@@ -385,7 +385,10 @@ std::weak_ptr<U> to_weak_ptr_aliasing(const std::shared_ptr<T>& r, U* ptr) {
#if defined(__GLIBCXX__) #if defined(__GLIBCXX__)
std::weak_ptr<void> wv(r); std::weak_ptr<void> wv(r);
detail::weak_ptr_set_stored_ptr(wv, ptr); detail::weak_ptr_set_stored_ptr(wv, ptr);
FOLLY_PUSH_WARNING
FOLLY_GCC_DISABLE_WARNING("-Wstrict-aliasing")
return reinterpret_cast<std::weak_ptr<U>&&>(wv); return reinterpret_cast<std::weak_ptr<U>&&>(wv);
FOLLY_POP_WARNING
#else #else
return std::shared_ptr<U>(r, ptr); return std::shared_ptr<U>(r, ptr);
#endif #endif
......
...@@ -683,7 +683,10 @@ class EliasFanoReader { ...@@ -683,7 +683,10 @@ class EliasFanoReader {
using SizeType = SizeT; using SizeType = SizeT;
explicit EliasFanoReader(const typename Encoder::CompressedList& list) explicit EliasFanoReader(const typename Encoder::CompressedList& list)
: upper_(list), lower_(list.lower), numLowerBits_(list.numLowerBits) { : upper_(list),
lower_(list.lower),
value_(),
numLowerBits_(list.numLowerBits) {
DCHECK_LE(list.size, std::numeric_limits<SizeType>::max()); DCHECK_LE(list.size, std::numeric_limits<SizeType>::max());
DCHECK(Instructions::supported()); DCHECK(Instructions::supported());
} }
......
...@@ -91,7 +91,10 @@ class SingleWriterFixedHashMap { ...@@ -91,7 +91,10 @@ class SingleWriterFixedHashMap {
elem_ = std::make_unique<Elem[]>(capacity_); elem_ = std::make_unique<Elem[]>(capacity_);
if (capacity_ == o.capacity_ && if (capacity_ == o.capacity_ &&
(o.used_ < o.capacity_ || o.size() == o.capacity_)) { (o.used_ < o.capacity_ || o.size() == o.capacity_)) {
memcpy(elem_.get(), o.elem_.get(), capacity_ * sizeof(Elem)); std::memcpy(
static_cast<void*>(elem_.get()),
static_cast<const void*>(o.elem_.get()),
capacity_ * sizeof(Elem));
used_ = o.used_; used_ = o.used_;
setSize(o.size()); setSize(o.size());
return; return;
......
...@@ -159,16 +159,16 @@ void SimpleAsyncIO::submitOp( ...@@ -159,16 +159,16 @@ void SimpleAsyncIO::submitOp(
op->setNotificationCallback( op->setNotificationCallback(
[this, completor{std::move(completor)}, opHolder{std::move(opHolder)}]( [this, completor{std::move(completor)}, opHolder{std::move(opHolder)}](
AsyncBaseOp* op) mutable { AsyncBaseOp* op_) mutable {
CHECK(op == opHolder.get()); CHECK(op_ == opHolder.get());
int rc = op->result(); int rc = op_->result();
completionExecutor_->add( completionExecutor_->add(
[rc, completor{std::move(completor)}]() mutable { completor(rc); }); [rc, completor{std::move(completor)}]() mutable { completor(rc); });
// NB: the moment we put the opHolder, the destructor might delete the // NB: the moment we put the opHolder, the destructor might delete the
// current instance. So do not access any member variables after this // current instance. So do not access any member variables after this
// point! Also, obviously, do not access op. // point! Also, obviously, do not access op_.
putOp(std::move(opHolder)); putOp(std::move(opHolder));
}); });
asyncIO_->submit(op); asyncIO_->submit(op);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/Exception.h> #include <folly/Exception.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/lang/CString.h>
#include <folly/portability/Config.h> #include <folly/portability/Config.h>
#include <folly/portability/SysMman.h> #include <folly/portability/SysMman.h>
...@@ -78,7 +79,7 @@ ElfFile::OpenResult ElfFile::openNoThrow( ...@@ -78,7 +79,7 @@ ElfFile::OpenResult ElfFile::openNoThrow(
// Always close fd and unmap in case of failure along the way to avoid // Always close fd and unmap in case of failure along the way to avoid
// check failure above if we leave fd != -1 and the object is recycled // check failure above if we leave fd != -1 and the object is recycled
auto guard = makeGuard([&] { reset(); }); auto guard = makeGuard([&] { reset(); });
strncat(filepath_, name, kFilepathMaxLen - 1); strlcpy(filepath_, name, kFilepathMaxLen - 1);
fd_ = ::open(name, options.writable() ? O_RDWR : O_RDONLY); fd_ = ::open(name, options.writable() ? O_RDWR : O_RDONLY);
if (fd_ == -1) { if (fd_ == -1) {
return {kSystemError, "open"}; return {kSystemError, "open"};
...@@ -160,7 +161,7 @@ ElfFile::ElfFile(ElfFile&& other) noexcept ...@@ -160,7 +161,7 @@ ElfFile::ElfFile(ElfFile&& other) noexcept
length_(other.length_), length_(other.length_),
baseAddress_(other.baseAddress_) { baseAddress_(other.baseAddress_) {
// copy other.filepath_, leaving filepath_ zero-terminated, always. // copy other.filepath_, leaving filepath_ zero-terminated, always.
strncat(filepath_, other.filepath_, kFilepathMaxLen - 1); strlcpy(filepath_, other.filepath_, kFilepathMaxLen - 1);
other.filepath_[0] = 0; other.filepath_[0] = 0;
other.fd_ = -1; other.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED); other.file_ = static_cast<char*>(MAP_FAILED);
...@@ -173,7 +174,7 @@ ElfFile& ElfFile::operator=(ElfFile&& other) noexcept { ...@@ -173,7 +174,7 @@ ElfFile& ElfFile::operator=(ElfFile&& other) noexcept {
reset(); reset();
// copy other.filepath_, leaving filepath_ zero-terminated, always. // copy other.filepath_, leaving filepath_ zero-terminated, always.
strncat(filepath_, other.filepath_, kFilepathMaxLen - 1); strlcpy(filepath_, other.filepath_, kFilepathMaxLen - 1);
fd_ = other.fd_; fd_ = other.fd_;
file_ = other.file_; file_ = other.file_;
length_ = other.length_; length_ = other.length_;
......
...@@ -411,7 +411,7 @@ TEST_F(RequestContextTest, ThreadId) { ...@@ -411,7 +411,7 @@ TEST_F(RequestContextTest, ThreadId) {
EventBase base; EventBase base;
base.runInEventBaseThread([&]() { base.runInEventBaseThread([&]() {
RequestContextScopeGuard g; RequestContextScopeGuard g_;
folly::setThreadName("DummyThread2"); folly::setThreadName("DummyThread2");
rootids = RequestContext::getRootIdsFromAllThreads(); rootids = RequestContext::getRootIdsFromAllThreads();
base.terminateLoopSoon(); base.terminateLoopSoon();
......
...@@ -62,7 +62,11 @@ ...@@ -62,7 +62,11 @@
#endif #endif
#if __GNUC__ && __linux__ #if __GNUC__ && __linux__
#if defined(__clang__) || FOLLY_ARM || FOLLY_AARCH64
#define FOLLY_KEEP_DETAIL_ATTR_NAKED [[gnu::naked]] #define FOLLY_KEEP_DETAIL_ATTR_NAKED [[gnu::naked]]
#else
#define FOLLY_KEEP_DETAIL_ATTR_NAKED
#endif
#define FOLLY_KEEP_DETAIL_ATTR_NOINLINE [[gnu::noinline]] #define FOLLY_KEEP_DETAIL_ATTR_NOINLINE [[gnu::noinline]]
#else #else
#define FOLLY_KEEP_DETAIL_ATTR_NAKED #define FOLLY_KEEP_DETAIL_ATTR_NAKED
......
...@@ -576,7 +576,9 @@ int fchmod(int fd, mode_t mode) { ...@@ -576,7 +576,9 @@ int fchmod(int fd, mode_t mode) {
reinterpret_cast<int (*)(int, mode_t)>(dlsym(RTLD_NEXT, "fchmod")); reinterpret_cast<int (*)(int, mode_t)>(dlsym(RTLD_NEXT, "fchmod"));
// For sanity, make sure we didn't find ourself, // For sanity, make sure we didn't find ourself,
// since that would cause infinite recursion. // since that would cause infinite recursion.
CHECK_NE(realFunction, fchmod); CHECK_NE(
reinterpret_cast<uintptr_t>(realFunction),
reinterpret_cast<uintptr_t>(&fchmod));
if (FChmodFailure::shouldFail()) { if (FChmodFailure::shouldFail()) {
errno = EINVAL; errno = EINVAL;
......
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