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;
namespace folly {
namespace detail {
inline void* thunk_return_nullptr() {
return nullptr;
}
} // namespace detail
template <class T, class Allocator>
class fbvector {
//===========================================================================
......@@ -981,26 +987,15 @@ class fbvector {
xallocx(p, newCapacityBytes, 0, 0) == newCapacityBytes) {
impl_.z_ += newCap - oldCap;
} else {
T* newB; // intentionally uninitialized
if (!catch_exception(
[&] {
newB = M_allocate(newCap);
return true;
},
[&] { //
return false;
})) {
T* newB = static_cast<T*>(catch_exception(
[&] { return M_allocate(newCap); }, //
&detail::thunk_return_nullptr));
if (!newB) {
return;
}
if (!catch_exception(
[&] {
M_relocate(newB);
return true;
},
[&] {
M_deallocate(newB, newCap);
return false;
})) {
[&] { return M_relocate(newB), true; },
[&] { return M_deallocate(newB, newCap), false; })) {
return;
}
if (impl_.b_) {
......
......@@ -385,7 +385,10 @@ std::weak_ptr<U> to_weak_ptr_aliasing(const std::shared_ptr<T>& r, U* ptr) {
#if defined(__GLIBCXX__)
std::weak_ptr<void> wv(r);
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);
FOLLY_POP_WARNING
#else
return std::shared_ptr<U>(r, ptr);
#endif
......
......@@ -683,7 +683,10 @@ class EliasFanoReader {
using SizeType = SizeT;
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(Instructions::supported());
}
......
......@@ -91,7 +91,10 @@ class SingleWriterFixedHashMap {
elem_ = std::make_unique<Elem[]>(capacity_);
if (capacity_ == 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_;
setSize(o.size());
return;
......
......@@ -159,16 +159,16 @@ void SimpleAsyncIO::submitOp(
op->setNotificationCallback(
[this, completor{std::move(completor)}, opHolder{std::move(opHolder)}](
AsyncBaseOp* op) mutable {
CHECK(op == opHolder.get());
int rc = op->result();
AsyncBaseOp* op_) mutable {
CHECK(op_ == opHolder.get());
int rc = op_->result();
completionExecutor_->add(
[rc, completor{std::move(completor)}]() mutable { completor(rc); });
// NB: the moment we put the opHolder, the destructor might delete the
// 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));
});
asyncIO_->submit(op);
......
......@@ -27,6 +27,7 @@
#include <folly/Conv.h>
#include <folly/Exception.h>
#include <folly/ScopeGuard.h>
#include <folly/lang/CString.h>
#include <folly/portability/Config.h>
#include <folly/portability/SysMman.h>
......@@ -78,7 +79,7 @@ ElfFile::OpenResult ElfFile::openNoThrow(
// 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
auto guard = makeGuard([&] { reset(); });
strncat(filepath_, name, kFilepathMaxLen - 1);
strlcpy(filepath_, name, kFilepathMaxLen - 1);
fd_ = ::open(name, options.writable() ? O_RDWR : O_RDONLY);
if (fd_ == -1) {
return {kSystemError, "open"};
......@@ -160,7 +161,7 @@ ElfFile::ElfFile(ElfFile&& other) noexcept
length_(other.length_),
baseAddress_(other.baseAddress_) {
// 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.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED);
......@@ -173,7 +174,7 @@ ElfFile& ElfFile::operator=(ElfFile&& other) noexcept {
reset();
// copy other.filepath_, leaving filepath_ zero-terminated, always.
strncat(filepath_, other.filepath_, kFilepathMaxLen - 1);
strlcpy(filepath_, other.filepath_, kFilepathMaxLen - 1);
fd_ = other.fd_;
file_ = other.file_;
length_ = other.length_;
......
......@@ -411,7 +411,7 @@ TEST_F(RequestContextTest, ThreadId) {
EventBase base;
base.runInEventBaseThread([&]() {
RequestContextScopeGuard g;
RequestContextScopeGuard g_;
folly::setThreadName("DummyThread2");
rootids = RequestContext::getRootIdsFromAllThreads();
base.terminateLoopSoon();
......
......@@ -62,7 +62,11 @@
#endif
#if __GNUC__ && __linux__
#if defined(__clang__) || FOLLY_ARM || FOLLY_AARCH64
#define FOLLY_KEEP_DETAIL_ATTR_NAKED [[gnu::naked]]
#else
#define FOLLY_KEEP_DETAIL_ATTR_NAKED
#endif
#define FOLLY_KEEP_DETAIL_ATTR_NOINLINE [[gnu::noinline]]
#else
#define FOLLY_KEEP_DETAIL_ATTR_NAKED
......
......@@ -576,7 +576,9 @@ int fchmod(int fd, mode_t mode) {
reinterpret_cast<int (*)(int, mode_t)>(dlsym(RTLD_NEXT, "fchmod"));
// For sanity, make sure we didn't find ourself,
// 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()) {
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