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:
Justine Tunney 2023-09-01 20:49:13 -07:00
parent e2b3c3618e
commit 0d748ad58e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
571 changed files with 1306 additions and 1888 deletions

View file

@ -94,8 +94,8 @@ static void PrintHeader(uint8_t *p) {
static void Print(void) {
int arsize;
uint8_t *b, *p;
uint64_t offset;
uint8_t *b, *p, *e;
uint32_t i, n, o, table, entries, symbols, symbolslen;
arsize = atoi((char *)(data + 8 + 48));
CHECK_LE(4, arsize);

View file

@ -31,6 +31,8 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -53,8 +55,8 @@ static struct stat st[1];
static Elf64_Ehdr *elf;
static void startfile(void) {
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf", basename(path),
NULL, &kModelineAsm);
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf",
basename(gc(strdup(path))), NULL, &kModelineAsm);
printf("#include \"libc/elf.h\"\n\n", path);
}
@ -224,7 +226,6 @@ static void printelfgroups(void) {
section->sh_name)
: 0);
}
shdr->sh_offset;
}
}
}

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/arraylist2.internal.h"
#include "tool/decode/lib/flagger.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/decode/lib/flagger.h"
/**
* Formats numeric flags integer as symbolic code.
@ -46,7 +46,7 @@ dontdiscard char *RecreateFlags(const struct IdName *names, unsigned long id) {
} else {
first = false;
}
CONCAT(&bufp, &bufi, &bufn, names->name, strlen(names->name));
CONCAT(&bufp, &bufi, &bufn, (char *)names->name, strlen(names->name));
}
}
if (id) {

View file

@ -23,6 +23,8 @@
#include "libc/fmt/libgen.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macho.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -56,7 +58,7 @@ static void showmachoheader(void) {
exit(1);
}
#endif
showtitle(basename(path), "macho", "header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "macho", "header", NULL, NULL);
printf("\n");
showinthex(macho->magic);
show(".long",
@ -171,7 +173,7 @@ static void showmacholoaduuid(struct MachoLoadUuid *lu) {
#define COLS 8
static void showmacholoadgeneric(struct MachoLoadCommand *lc) {
int i, c, col = 0;
int c, col = 0;
int need_newline = 0;
char16_t glyphs[COLS + 1];
const unsigned char *p, *pe;

View file

@ -23,6 +23,8 @@
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/struct/imagedosheader.internal.h"
#include "libc/nt/struct/imagentheaders.internal.h"
#include "libc/nt/struct/imageoptionalheader.internal.h"
@ -99,7 +101,7 @@ static void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize,
}
static void showmzheader(void) {
showtitle(basename(path), "dos", "mz header",
showtitle(basename(gc(strdup(path))), "dos", "mz header",
"\tMZ = Mark 'Zibo' Joseph Zbikowski\n"
"\te_cblp: bytes on last page\n"
"\te_cp: 512-byte pages in file\n"
@ -152,7 +154,8 @@ static void showdosstub(void) {
static void showpeoptionalheader(struct NtImageOptionalHeader *opt) {
int i;
showtitle(basename(path), "windows", "pe \"optional\" header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "windows", "pe \"optional\" header",
NULL, NULL);
printf("\n");
show(".short",
firstnonnull(findnamebyid(kNtPeOptionalHeaderMagicNames, opt->Magic),
@ -248,7 +251,8 @@ static void ShowIlt(uint32_t rva) {
static void ShowIdt(char *idt, size_t size) {
char *p, *e;
printf("\n");
showtitle(basename(path), "windows", "import descriptor table (idt)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import descriptor table (idt)", 0, 0);
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
printf("\n");
show(".long", format(b1, "%#x", READ32LE(p)),
@ -266,14 +270,16 @@ static void ShowIdt(char *idt, size_t size) {
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
if (READ32LE(p)) {
printf("\n");
showtitle(basename(path), "windows", "import lookup table (ilt)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import lookup table (ilt)", 0, 0);
ShowIlt(READ32LE(p));
}
}
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
if (READ32LE(p)) {
printf("\n");
showtitle(basename(path), "windows", "import address table (iat)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import address table (iat)", 0, 0);
ShowIlt(READ32LE(p + 16));
}
}
@ -316,14 +322,14 @@ static void ShowSections(struct NtImageSectionHeader *s, size_t n) {
sections = s;
section_count = n;
printf("\n");
showtitle(basename(path), "windows", "sections", 0, 0);
showtitle(basename(gc(strdup(path))), "windows", "sections", 0, 0);
for (i = 0; i < n; ++i) {
ShowSection(s + i);
}
}
static void showpeheader(struct NtImageNtHeaders *pe) {
showtitle(basename(path), "windows", "pe header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "windows", "pe header", NULL, NULL);
printf("\n");
showorg(mz->e_lfanew);
show(".ascii", format(b1, "%`'.*s", 4, (const char *)&pe->Signature),

View file

@ -419,7 +419,7 @@ uint8_t *GetZipCdir64(const uint8_t *p, size_t n) {
do {
if (READ32LE(p + i) == kZipCdir64LocatorMagic &&
(j = ZIP_LOCATE64_OFFSET(p + i)) + kZipCdir64HdrMinSize <= n) {
return p + j;
return (uint8_t *)p + j;
}
} while (i--);
}
@ -430,7 +430,7 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) {
size_t pos;
uint16_t i;
static int records;
uint8_t *eocd32, *eocd64, *cdir, *cf, *lf, *q;
uint8_t *eocd32, *eocd64, *cdir, *cf, *lf;
eocd32 = GetZipCdir32(p, n);
eocd64 = GetZipCdir64(p, n);
CHECK(eocd32 || eocd64);