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

@ -22,7 +22,7 @@
#include "libc/str/str.h"
static const char *TryMonoRepoPath(const char *var, const char *path) {
const char buf[PATH_MAX];
char buf[PATH_MAX];
if (getenv(var)) return 0;
if (!isexecutable(path)) return 0;
if (*path != '/') {

View file

@ -94,18 +94,18 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) {
sys_dup2(ttyfd, 1, 0);
__sys_execve(gdb,
(char *const[]){
"gdb", "--tui",
"-p", pidstr,
se, elf,
"-ex", "set osabi GNU/Linux",
"-ex", "set complaints 0",
"-ex", "set confirm off",
"-ex", layout,
"-ex", "layout reg",
"-ex", "set var g_gdbsync = 1",
"-q", rewind,
breakcmd, "-ex",
"c", NULL,
"gdb", "--tui",
"-p", pidstr,
(char *)se, (char *)elf,
"-ex", "set osabi GNU/Linux",
"-ex", "set complaints 0",
"-ex", "set confirm off",
"-ex", (char *)layout,
"-ex", "layout reg",
"-ex", "set var g_gdbsync = 1",
"-q", (char *)rewind,
breakcmd, "-ex",
"c", NULL,
},
environ);
abort();

View file

@ -49,12 +49,15 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
ssize_t got;
intptr_t addr;
size_t i, j, gi;
char *p1, *p2, *p3;
int ws, pid, pipefds[2];
struct Garbages *garbage;
const struct StackFrame *frame;
char *debugbin, *p1, *p2, *p3, *addr2line;
const char *debugbin, *addr2line;
char buf[kBacktraceBufSize], *argv[kBacktraceMaxFrames];
(void)gi;
// DWARF is a weak standard. Platforms that use LLVM or old GNU
// usually can't be counted upon to print backtraces correctly.
if (!IsLinux() && !IsWindows()) {
@ -95,7 +98,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
argv[i++] = "addr2line";
argv[i++] = "-a"; /* filter out w/ shell script wrapper for old versions */
argv[i++] = "-pCife";
argv[i++] = debugbin;
argv[i++] = (char *)debugbin;
garbage = __tls_enabled ? __get_tls()->tib_garbages : 0;
gi = garbage ? garbage->i : 0;
for (frame = bp; frame && i < kBacktraceMaxFrames - 1; frame = frame->next) {

View file

@ -47,12 +47,12 @@
*/
dontinstrument dontasan int PrintBacktraceUsingSymbols(
int fd, const struct StackFrame *bp, struct SymbolTable *st) {
bool ok;
size_t gi;
intptr_t addr;
int i, symbol, addend;
struct Garbages *garbage;
const struct StackFrame *frame;
(void)gi;
if (!bp) bp = __builtin_frame_address(0);
garbage = __tls_enabled ? __get_tls()->tib_garbages : 0;
gi = garbage ? garbage->i : 0;

View file

@ -46,7 +46,6 @@ relegated void __check_fail(const char *suffix, //
int line, //
const char *fmt, //
...) {
char *p;
size_t i;
va_list va;
char hostname[32];

View file

@ -29,8 +29,8 @@
* Attaches GDB temporarily, to do something like print a variable.
*/
relegated int(gdbexec)(const char *cmd) {
int pid;
struct StackFrame *bp;
int pid, ttyin, ttyout;
const char *se, *elf, *gdb;
char pidstr[11], breakcmd[40];
if (!(gdb = GetGdbPath())) return -1;
@ -50,8 +50,8 @@ relegated int(gdbexec)(const char *cmd) {
"--nh",
"-p",
pidstr,
se,
elf,
(char *)se,
(char *)elf,
"-ex",
"set osabi GNU/Linux",
"-ex",
@ -64,7 +64,7 @@ relegated int(gdbexec)(const char *cmd) {
"-ex",
breakcmd,
"-ex",
cmd,
(char *)cmd,
"-ex",
"quit",
NULL,

View file

@ -24,7 +24,6 @@
* Returns name of function that called caller function.
*/
const char *GetCallerName(const struct StackFrame *bp) {
struct SymbolTable *st;
if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next;
if (bp) return GetSymbolByAddr(bp->addr);
return 0;

View file

@ -1,28 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/describeflags.internal.h"
#include "libc/log/log.h"
/**
* Returns symbolic name for siginfo::si_code value.
*/
const char *GetSiCodeName(int sig, int si_code) {
static char b[17];
return (DescribeSiCode)(b, sig, si_code);
}

View file

@ -45,7 +45,7 @@ __funline void *__repmovsb(void *di, const void *si, size_t cx) {
return di;
#else
volatile char *volatile d = di;
volatile char *volatile s = si;
volatile const char *volatile s = si;
while (cx--) *d++ = *s++;
return (void *)d;
#endif
@ -131,7 +131,6 @@ __funline char16_t *__strstr16(const char16_t *haystack,
}
__funline const char *__strchr(const char *s, unsigned char c) {
char *r;
for (;; ++s) {
if ((*s & 255) == c) return s;
if (!*s) return 0;

View file

@ -45,7 +45,6 @@ const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool);
bool IsRunningUnderMake(void);
const char *GetSiCodeName(int, int);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);

View file

@ -17,21 +17,21 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/stdio/dprintf.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/stdio/dprintf.h"
void _memsummary(int fd) {
struct mallinfo mi;
mi = mallinfo();
(dprintf)(fd,
"arena\t\t%,-12zu\t# space allocated from system\n"
"ordblks\t\t%,-12zu\t# number of free chunks\n"
"hblkhd\t\t%,-12zu\t# space in mmapped regions\n"
"usmblks\t\t%,-12zu\t# maximum total allocated space\n"
"uordblks\t%,-12zu\t# total allocated space\n"
"fordblks\t%,-12zu\t# total free space\n"
"keepcost\t%,-12zu\t# releasable (via malloc_trim) space\n\n",
mi.arena, mi.ordblks, mi.hblkhd, mi.usmblks, mi.uordblks,
mi.fordblks, mi.keepcost);
dprintf(fd,
"arena\t\t%,-12zu\t# space allocated from system\n"
"ordblks\t\t%,-12zu\t# number of free chunks\n"
"hblkhd\t\t%,-12zu\t# space in mmapped regions\n"
"usmblks\t\t%,-12zu\t# maximum total allocated space\n"
"uordblks\t%,-12zu\t# total allocated space\n"
"fordblks\t%,-12zu\t# total free space\n"
"keepcost\t%,-12zu\t# releasable (via malloc_trim) space\n\n",
mi.arena, mi.ordblks, mi.hblkhd, mi.usmblks, mi.uordblks, mi.fordblks,
mi.keepcost);
}

View file

@ -29,6 +29,7 @@
#include "libc/fmt/itoa.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kmalloc.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h"
@ -232,7 +233,7 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
(ctx->uc_mcontext.rsp >= GetStaticStackAddr(0) &&
ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + getauxval(AT_PAGESZ)))
? "Stack Overflow"
: GetSiCodeName(sig, si->si_code),
: DescribeSiCode(sig, si->si_code),
host, getpid(), gettid(), program_invocation_name, strerror(err),
names.sysname, names.version, names.nodename, names.release);
if (ctx) {

View file

@ -28,6 +28,7 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/ucontext.h"
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/internal.h"
#include "libc/log/log.h"
@ -132,9 +133,10 @@ static bool AppendFileLine(struct Buffer *b, const char *addr2line,
sys_close(pfd[0]);
sys_dup2(pfd[1], 1, 0);
sys_close(2);
__sys_execve(addr2line,
(char *const[]){addr2line, "-pifCe", debugbin, buf, 0},
(char *const[]){0});
__sys_execve(
addr2line,
(char *const[]){(char *)addr2line, "-pifCe", (char *)debugbin, buf, 0},
(char *const[]){0});
_Exit(127);
}
sys_close(pfd[1]);
@ -202,7 +204,7 @@ relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) {
(ctx->uc_mcontext.sp & (GetStackSize() - 1)) <= getauxval(AT_PAGESZ)) {
kind = "Stack Overflow";
} else {
kind = GetSiCodeName(sig, si->si_code);
kind = DescribeSiCode(sig, si->si_code);
}
Append(b,
"%serror%s: Uncaught %G (%s) on %s pid %d tid %d\n"
@ -216,7 +218,6 @@ relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) {
names.release);
if (ctx) {
long pc;
char line[256];
char *mem = 0;
size_t memsz = 0;
int addend, symbol;

View file

@ -56,7 +56,6 @@ static const char *DescribeNtMemType(char buf[64], uint32_t x) {
*/
void PrintWindowsMemory(const char *high, size_t size) {
char *p, b[5][64];
const char *start, *stop;
struct NtMemoryBasicInformation mi;
kprintf("%-12s %-12s %10s %16s %16s %32s %32s\n", "Allocation", "BaseAddress",
"RegionSize", "State", "Type", "AllocationProtect", "Protect");

View file

@ -51,7 +51,6 @@ static struct timespec vflogf_ts;
*/
static void vflogf_onfail(FILE *f) {
errno_t err;
int64_t size;
struct stat st;
if (IsTiny()) return;
err = ferror_unlocked(f);
@ -93,7 +92,6 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
char buf32[32];
const char *prog;
const char *sign;
bool issamesecond;
struct timespec t2;
if (!f) f = __log_file;
if (!f) return;

View file

@ -41,7 +41,6 @@ static dontinstrument inline void Copy(char *p, char *q, size_t n) {
}
static dontinstrument inline int Cmp(char *p, char *q, size_t n) {
int c;
if (n == 8) return READ64LE(p) != READ64LE(q);
if (n == 4) return READ32LE(p) != READ32LE(q);
for (; n; ++p, ++q, --n) {