Skip to content

Commit 24e6dd7

Browse files
committed
clang-tidy: use C++ casts
Found with google-readability-casting Signed-off-by: Rosen Penev <[email protected]>
1 parent 85393d3 commit 24e6dd7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/patchelf.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ static FileContents readFile(const std::string & fileName,
315315
if (stat(fileName.c_str(), &st) != 0)
316316
throw SysError(fmt("getting info about '", fileName, "'"));
317317

318-
if ((uint64_t) st.st_size > (uint64_t) std::numeric_limits<size_t>::max())
318+
if (static_cast<uint64_t>(st.st_size) > static_cast<uint64_t>(std::numeric_limits<size_t>::max()))
319319
throw SysError(fmt("cannot read file of size ", st.st_size, " into memory"));
320320

321-
size_t size = std::min(cutOff, (size_t) st.st_size);
321+
size_t size = std::min(cutOff, static_cast<size_t>(st.st_size));
322322

323323
FileContents contents = std::make_shared<std::vector<unsigned char>>();
324324
contents->reserve(size + 32 * 1024 * 1024);
@@ -351,7 +351,8 @@ struct ElfType
351351
ElfType getElfType(const FileContents & fileContents)
352352
{
353353
/* Check the ELF header for basic validity. */
354-
if (fileContents->size() < (off_t) sizeof(Elf32_Ehdr)) error("missing ELF header");
354+
if (fileContents->size() < static_cast<off_t>(sizeof(Elf32_Ehdr)))
355+
error("missing ELF header");
355356

356357
auto contents = fileContents->data();
357358

@@ -367,13 +368,13 @@ ElfType getElfType(const FileContents & fileContents)
367368
bool is32Bit = contents[EI_CLASS] == ELFCLASS32;
368369

369370
// FIXME: endianness
370-
return ElfType{is32Bit, is32Bit ? ((Elf32_Ehdr *) contents)->e_machine : ((Elf64_Ehdr *) contents)->e_machine};
371+
return ElfType { is32Bit, is32Bit ? (reinterpret_cast<Elf32_Ehdr *>(contents))->e_machine : (reinterpret_cast<Elf64_Ehdr *>(contents))->e_machine };
371372
}
372373

373374

374375
static void checkPointer(const FileContents & contents, void * p, unsigned int size)
375376
{
376-
unsigned char * q = (unsigned char *) p;
377+
unsigned char * q = static_cast<unsigned char *>(p);
377378
if (!(q >= contents->data() && q + size <= contents->data() + contents->size()))
378379
error("data region extends past file end");
379380
}

0 commit comments

Comments
 (0)