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

@ -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),