Skip to content

Commit

Permalink
Assorted clang warning fixes
Browse files Browse the repository at this point in the history
Fixes a few warnings reported by clang 14.0.7 (Android NDK r25c):

- Remove unnecessary std::move() that prevents copy elision
- BpfProgram class has a non-static member of a reference type, so the move
  assignment operator is implicitly deleted[1]; remove `= default`
- Use reinterpret_cast in elf_parser to silence the warning about increased
  alignment requirement (the pointer is 8-byte aligned anyway)
- Use the correct printf specifier for uint64_t

[1] https://en.cppreference.com/w/cpp/language/move_assignment
  • Loading branch information
tnovak committed Oct 20, 2023
1 parent 713f170 commit 0d4e1d1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ast/elf_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BpfBytecode parseBpfBytecodeFromElfObject(void *const elf)
// were ever to diverge.
assert(sizeof(Elf64_Shdr) == ehdr->e_shentsize);

Elf64_Shdr *shdrs = (Elf64_Shdr *)(fileptr + ehdr->e_shoff);
Elf64_Shdr *shdrs = reinterpret_cast<Elf64_Shdr *>(fileptr + ehdr->e_shoff);
Elf64_Shdr *strtable_shdr = &shdrs[ehdr->e_shstrndx];
assert(strtable_shdr->sh_type == SHT_STRTAB);
char *strtable = fileptr + strtable_shdr->sh_offset;
Expand Down
2 changes: 1 addition & 1 deletion src/bpfprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BpfProgram
BpfProgram(const BpfProgram &) = delete;
BpfProgram &operator=(const BpfProgram &) = delete;
BpfProgram(BpfProgram &&) = default;
BpfProgram &operator=(BpfProgram &&) = default;
BpfProgram &operator=(BpfProgram &&) = delete;

private:
explicit BpfProgram(const BpfBytecode &bytecode,
Expand Down
3 changes: 2 additions & 1 deletion src/bpftrace.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <cassert>
#include <cerrno>
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <ctime>
Expand Down Expand Up @@ -2035,7 +2036,7 @@ std::string BPFtrace::resolve_timestamp(uint32_t mode,
const auto &raw_fmt = resources.strftime_args[strftime_id];
uint64_t us = ((basetime->tv_nsec + nsecs) % 1000000000) / 1000;
char usecs_buf[7];
snprintf(usecs_buf, sizeof(usecs_buf), "%06lu", us);
snprintf(usecs_buf, sizeof(usecs_buf), "%06" PRIu64, us);
auto fmt = std::regex_replace(raw_fmt, usec_regex, usecs_buf);

char timestr[strlen_];
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ int main(int argc, char* argv[])
llvm.emit_elf(args.output_elf);
return 0;
}
bytecode = std::move(llvm.emit());
bytecode = llvm.emit();
}
catch (const std::system_error& ex)
{
Expand Down

0 comments on commit 0d4e1d1

Please sign in to comment.