mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 09:48:29 +00:00
Fix warnings
This change fixes Cosmopolitan so it has fewer opinions about compiler warnings. The whole repository had to be cleaned up to be buildable in -Werror -Wall mode. This lets us benefit from things like strict const checking. Some actual bugs might have been caught too.
This commit is contained in:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_
|
|||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § executable linkable format ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
/* clang-format off */
|
||||
|
||||
bool IsElfSymbolContent(const Elf64_Sym *);
|
||||
bool IsElf64Binary(const Elf64_Ehdr *, size_t);
|
||||
|
@ -18,11 +19,11 @@ Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
|||
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
||||
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *, size_t, char *, const char *);
|
||||
const char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
||||
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
|
||||
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
||||
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
|
||||
const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *);
|
||||
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* @param mapsize is the number of bytes past `elf` we can access
|
||||
* @return pointer to section header within image, or null
|
||||
*/
|
||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *elf, size_t mapsize,
|
||||
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
char *shdrstrtab, const char *name) {
|
||||
long i;
|
||||
Elf64_Shdr *shdr;
|
||||
|
|
|
@ -39,7 +39,7 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
|
|||
const Elf64_Shdr *shdr) { // foreign
|
||||
Elf64_Off last;
|
||||
if (!shdr) return 0;
|
||||
if (!shdr->sh_size) return elf;
|
||||
if (!shdr->sh_size) return (void *)elf;
|
||||
if (shdr->sh_type == SHT_NOBITS) return 0;
|
||||
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
|
||||
if (last > mapsize) return 0;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/elf/elf.h"
|
||||
|
||||
const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
Elf64_Shdr *shdr) {
|
||||
char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||
const Elf64_Shdr *shdr) {
|
||||
if (!shdr) return 0;
|
||||
return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize),
|
||||
shdr->sh_name);
|
||||
|
|
|
@ -39,10 +39,10 @@
|
|||
* 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or
|
||||
* 4. an arithmetic overflow occurred
|
||||
*/
|
||||
const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||
size_t mapsize, // validated
|
||||
const char *strtab, // validated
|
||||
Elf64_Word i) { // foreign
|
||||
char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||
size_t mapsize, // validated
|
||||
const char *strtab, // validated
|
||||
Elf64_Word i) { // foreign
|
||||
const char *e;
|
||||
if (!i) return "";
|
||||
e = (const char *)elf;
|
||||
|
@ -50,5 +50,5 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
|||
if (i >= mapsize) return 0;
|
||||
if (strtab + i >= e + mapsize) return 0;
|
||||
if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0;
|
||||
return (const char *)strtab + i;
|
||||
return (char *)strtab + i;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, //
|
|||
const char *section_name) {
|
||||
int i;
|
||||
char *name;
|
||||
Elf64_Shdr *shdr;
|
||||
const Elf64_Shdr *shdr;
|
||||
for (i = 0; i < elf->e_shnum; ++i) {
|
||||
if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) &&
|
||||
shdr->sh_type == SHT_STRTAB &&
|
||||
|
|
|
@ -22,7 +22,7 @@ COSMOPOLITAN_C_START_
|
|||
((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \
|
||||
(unsigned)(e)->e_shentsize * (i)))
|
||||
|
||||
static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
||||
static inline char *GetStrtab(const Elf64_Ehdr *e, size_t *n) {
|
||||
int i;
|
||||
char *name;
|
||||
Elf64_Shdr *shdr;
|
||||
|
@ -39,7 +39,7 @@ static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||
static inline Elf64_Sym *GetSymtab(const Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||
int i;
|
||||
Elf64_Shdr *shdr;
|
||||
for (i = e->e_shnum; i-- > 0;) {
|
||||
|
@ -52,9 +52,10 @@ static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void GetImageRange(Elf64_Ehdr *elf, intptr_t *x, intptr_t *y) {
|
||||
static inline void GetImageRange(const Elf64_Ehdr *elf, intptr_t *x,
|
||||
intptr_t *y) {
|
||||
unsigned i;
|
||||
Elf64_Phdr *phdr;
|
||||
const Elf64_Phdr *phdr;
|
||||
intptr_t start, end, pstart, pend;
|
||||
start = INTPTR_MAX;
|
||||
end = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue