mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Fix "unsafe narrowing" warnings in absl, 7/n.
Addresses failures with the following, in some files: -Wshorten-64-to-32 -Wimplicit-int-conversion -Wsign-compare -Wsign-conversion -Wtautological-unsigned-zero-compare (This specific CL focuses on .cc files in debugging/internal/.) Bug: chromium:1292951 PiperOrigin-RevId: 470812243 Change-Id: I5578030bb42ba73cb83d4df84f89e431ceac8992
This commit is contained in:
committed by
Copybara-Service
parent
75691f1c32
commit
d9382f7290
@@ -52,7 +52,7 @@ namespace debugging_internal {
|
||||
bool AddressIsReadable(const void *addr) {
|
||||
// Align address on 8-byte boundary. On aarch64, checking last
|
||||
// byte before inaccessible page returned unexpected EFAULT.
|
||||
const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~7;
|
||||
const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~uintptr_t{7};
|
||||
addr = reinterpret_cast<const void *>(u_addr);
|
||||
|
||||
// rt_sigprocmask below will succeed for this input.
|
||||
|
||||
@@ -253,11 +253,13 @@ static bool StrPrefix(const char *str, const char *prefix) {
|
||||
return prefix[i] == '\0'; // Consumed everything in "prefix".
|
||||
}
|
||||
|
||||
static void InitState(State *state, const char *mangled, char *out,
|
||||
int out_size) {
|
||||
static void InitState(State* state,
|
||||
const char* mangled,
|
||||
char* out,
|
||||
size_t out_size) {
|
||||
state->mangled_begin = mangled;
|
||||
state->out = out;
|
||||
state->out_end_idx = out_size;
|
||||
state->out_end_idx = static_cast<int>(out_size);
|
||||
state->recursion_depth = 0;
|
||||
state->steps = 0;
|
||||
|
||||
@@ -451,7 +453,7 @@ static bool MaybeAppendDecimal(State *state, int val) {
|
||||
// one-past-the-end and manipulate one character before the pointer.
|
||||
char *p = &buf[kMaxLength];
|
||||
do { // val=0 is the only input that should write a leading zero digit.
|
||||
*--p = (val % 10) + '0';
|
||||
*--p = static_cast<char>((val % 10) + '0');
|
||||
val /= 10;
|
||||
} while (p > buf && val != 0);
|
||||
|
||||
@@ -1974,7 +1976,7 @@ static bool Overflowed(const State *state) {
|
||||
}
|
||||
|
||||
// The demangler entry point.
|
||||
bool Demangle(const char *mangled, char *out, int out_size) {
|
||||
bool Demangle(const char* mangled, char* out, size_t out_size) {
|
||||
State state;
|
||||
InitState(&state, mangled, out, out_size);
|
||||
return ParseTopLevelMangledName(&state) && !Overflowed(&state) &&
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace debugging_internal {
|
||||
// Demangle `mangled`. On success, return true and write the
|
||||
// demangled symbol name to `out`. Otherwise, return false.
|
||||
// `out` is modified even if demangling is unsuccessful.
|
||||
bool Demangle(const char *mangled, char *out, int out_size);
|
||||
bool Demangle(const char* mangled, char* out, size_t out_size);
|
||||
|
||||
} // namespace debugging_internal
|
||||
ABSL_NAMESPACE_END
|
||||
|
||||
@@ -91,7 +91,7 @@ int ElfMemImage::GetNumSymbols() const {
|
||||
return 0;
|
||||
}
|
||||
// See http://www.caldera.com/developers/gabi/latest/ch5.dynamic.html#hash
|
||||
return hash_[1];
|
||||
return static_cast<int>(hash_[1]);
|
||||
}
|
||||
|
||||
const ElfW(Sym) *ElfMemImage::GetDynsym(int index) const {
|
||||
@@ -105,11 +105,9 @@ const ElfW(Versym) *ElfMemImage::GetVersym(int index) const {
|
||||
}
|
||||
|
||||
const ElfW(Phdr) *ElfMemImage::GetPhdr(int index) const {
|
||||
ABSL_RAW_CHECK(index < ehdr_->e_phnum, "index out of range");
|
||||
return GetTableElement<ElfW(Phdr)>(ehdr_,
|
||||
ehdr_->e_phoff,
|
||||
ehdr_->e_phentsize,
|
||||
index);
|
||||
ABSL_RAW_CHECK(index >= 0 && index < ehdr_->e_phnum, "index out of range");
|
||||
return GetTableElement<ElfW(Phdr)>(ehdr_, ehdr_->e_phoff, ehdr_->e_phentsize,
|
||||
static_cast<size_t>(index));
|
||||
}
|
||||
|
||||
const char *ElfMemImage::GetDynstr(ElfW(Word) offset) const {
|
||||
@@ -159,7 +157,8 @@ void ElfMemImage::Init(const void *base) {
|
||||
hash_ = nullptr;
|
||||
strsize_ = 0;
|
||||
verdefnum_ = 0;
|
||||
link_base_ = ~0L; // Sentinel: PT_LOAD .p_vaddr can't possibly be this.
|
||||
// Sentinel: PT_LOAD .p_vaddr can't possibly be this.
|
||||
link_base_ = ~ElfW(Addr){0}; // NOLINT(readability/braces)
|
||||
if (!base) {
|
||||
return;
|
||||
}
|
||||
@@ -218,11 +217,11 @@ void ElfMemImage::Init(const void *base) {
|
||||
}
|
||||
ptrdiff_t relocation =
|
||||
base_as_char - reinterpret_cast<const char *>(link_base_);
|
||||
ElfW(Dyn) *dynamic_entry =
|
||||
reinterpret_cast<ElfW(Dyn) *>(dynamic_program_header->p_vaddr +
|
||||
relocation);
|
||||
ElfW(Dyn)* dynamic_entry = reinterpret_cast<ElfW(Dyn)*>(
|
||||
static_cast<intptr_t>(dynamic_program_header->p_vaddr) + relocation);
|
||||
for (; dynamic_entry->d_tag != DT_NULL; ++dynamic_entry) {
|
||||
const auto value = dynamic_entry->d_un.d_val + relocation;
|
||||
const auto value =
|
||||
static_cast<intptr_t>(dynamic_entry->d_un.d_val) + relocation;
|
||||
switch (dynamic_entry->d_tag) {
|
||||
case DT_HASH:
|
||||
hash_ = reinterpret_cast<ElfW(Word) *>(value);
|
||||
@@ -240,10 +239,10 @@ void ElfMemImage::Init(const void *base) {
|
||||
verdef_ = reinterpret_cast<ElfW(Verdef) *>(value);
|
||||
break;
|
||||
case DT_VERDEFNUM:
|
||||
verdefnum_ = dynamic_entry->d_un.d_val;
|
||||
verdefnum_ = static_cast<size_t>(dynamic_entry->d_un.d_val);
|
||||
break;
|
||||
case DT_STRSZ:
|
||||
strsize_ = dynamic_entry->d_un.d_val;
|
||||
strsize_ = static_cast<size_t>(dynamic_entry->d_un.d_val);
|
||||
break;
|
||||
default:
|
||||
// Unrecognized entries explicitly ignored.
|
||||
|
||||
@@ -80,7 +80,7 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,
|
||||
|
||||
if (IS_STACK_FRAMES) {
|
||||
// No implementation for finding out the stack frame sizes yet.
|
||||
memset(sizes, 0, sizeof(*sizes) * result_count);
|
||||
memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
|
||||
}
|
||||
if (min_dropped_frames != nullptr) {
|
||||
if (size - skip_count - max_depth > 0) {
|
||||
|
||||
@@ -140,13 +140,14 @@ static uintptr_t GetFP(const void *vuc) {
|
||||
// TODO(bcmills): -momit-leaf-frame-pointer is currently the default
|
||||
// behavior when building with clang. Talk to the C++ toolchain team about
|
||||
// fixing that.
|
||||
if (bp >= sp && bp - sp <= kMaxFrameBytes) return bp;
|
||||
if (bp >= sp && bp - sp <= kMaxFrameBytes)
|
||||
return static_cast<uintptr_t>(bp);
|
||||
|
||||
// If bp isn't a plausible frame pointer, return the stack pointer instead.
|
||||
// If we're lucky, it points to the start of a stack frame; otherwise, we'll
|
||||
// get one frame of garbage in the stack trace and fail the sanity check on
|
||||
// the next iteration.
|
||||
return sp;
|
||||
return static_cast<uintptr_t>(sp);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
@@ -310,7 +311,8 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count,
|
||||
int n = 0;
|
||||
void **fp = reinterpret_cast<void **>(__builtin_frame_address(0));
|
||||
|
||||
size_t stack_low = getpagesize(); // Assume that the first page is not stack.
|
||||
// Assume that the first page is not stack.
|
||||
size_t stack_low = static_cast<size_t>(getpagesize());
|
||||
size_t stack_high = std::numeric_limits<size_t>::max() - sizeof(void *);
|
||||
|
||||
while (fp && n < max_depth) {
|
||||
@@ -327,7 +329,9 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count,
|
||||
result[n] = *(fp + 1);
|
||||
if (IS_STACK_FRAMES) {
|
||||
if (next_fp > fp) {
|
||||
sizes[n] = (uintptr_t)next_fp - (uintptr_t)fp;
|
||||
sizes[n] = static_cast<int>(
|
||||
reinterpret_cast<uintptr_t>(next_fp) -
|
||||
reinterpret_cast<uintptr_t>(fp));
|
||||
} else {
|
||||
// A frame-size of 0 is used to indicate unknown frame size.
|
||||
sizes[n] = 0;
|
||||
|
||||
@@ -193,8 +193,9 @@ long VDSOSupport::InitAndGetCPU(unsigned *cpu, // NOLINT(runtime/int)
|
||||
ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY
|
||||
int GetCPU() {
|
||||
unsigned cpu;
|
||||
int ret_code = (*VDSOSupport::getcpu_fn_)(&cpu, nullptr, nullptr);
|
||||
return ret_code == 0 ? cpu : ret_code;
|
||||
long ret_code = // NOLINT(runtime/int)
|
||||
(*VDSOSupport::getcpu_fn_)(&cpu, nullptr, nullptr);
|
||||
return ret_code == 0 ? static_cast<int>(cpu) : static_cast<int>(ret_code);
|
||||
}
|
||||
|
||||
} // namespace debugging_internal
|
||||
|
||||
Reference in New Issue
Block a user