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

@ -63,7 +63,6 @@ TEST(access, test) {
TEST(access, testRequestWriteOnReadOnly_returnsEaccess) {
return; /* TODO(jart): maybe we need root to help? */
int fd;
ASSERT_SYS(ENOENT, -1, access("file", F_OK));
ASSERT_SYS(0, 0, close(creat("file", 0444)));
ASSERT_SYS(0, 0, access("file", F_OK));

View file

@ -37,12 +37,12 @@ TEST(clock_gettime, fault) {
}
TEST(clock_gettime, test) {
bool isfast;
struct timespec ts = {0};
ASSERT_EQ(0, clock_gettime(0, &ts));
ASSERT_NE(0, ts.tv_sec);
ASSERT_NE(0, ts.tv_nsec);
#ifndef __aarch64__
bool isfast;
// we support vdso on aarch64 but qemu-aarch64 won't let us test it
if (__is_linux_2_6_23()) {
ASSERT_GT((intptr_t)__clock_gettime_get(&isfast),

View file

@ -45,7 +45,6 @@ void SetUpOnce(void) {
}
void SetUp(void) {
static int x;
mkdir("bin", 0755);
mkdir("home", 0755);
oldpath = strdup(nulltoempty(getenv("PATH")));

View file

@ -111,7 +111,7 @@ TEST(execve, ziposAPE) {
void ExecvTinyElf(const char *path) {
int ws;
if (!vfork()) {
execv(path, (char *[]){path, 0});
execv(path, (char *[]){(char *)path, 0});
abort();
}
ASSERT_NE(-1, wait(&ws));
@ -121,7 +121,7 @@ void ExecvTinyElf(const char *path) {
void ExecvpTinyElf(const char *path) {
int ws;
if (!vfork()) {
execvp(path, (char *[]){path, 0});
execvp(path, (char *[]){(char *)path, 0});
abort();
}
ASSERT_NE(-1, wait(&ws));
@ -131,7 +131,7 @@ void ExecvpTinyElf(const char *path) {
void ExecveTinyElf(const char *path) {
int ws;
if (!vfork()) {
execve(path, (char *[]){path, 0}, (char *[]){0});
execve(path, (char *[]){(char *)path, 0}, (char *[]){0});
abort();
}
ASSERT_NE(-1, wait(&ws));

View file

@ -42,7 +42,6 @@ TEST(siocgifconf, test) {
int socketfd;
struct ifreq *ifr;
struct ifconf conf;
char addrbuf[1024];
uint32_t ip, netmask;
bool foundloopback = false;
data = gc(malloc((n = 4096)));

View file

@ -31,7 +31,6 @@
char testlib_enable_tmp_setup_teardown;
TEST(lock, wholeFile) {
char buf[512];
ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644));
ASSERT_SYS(0, 0, fcntl(3, F_SETLK, &(struct flock){.l_type = F_RDLCK}));
ASSERT_SYS(0, 0, fcntl(3, F_SETLK, &(struct flock){.l_type = F_UNLCK}));
@ -39,7 +38,6 @@ TEST(lock, wholeFile) {
}
TEST(lock, testUpgradeFromReadToWriteLock) {
char buf[512];
ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644));
ASSERT_SYS(0, 0,
fcntl(3, F_SETLK,
@ -59,7 +57,6 @@ TEST(lock, testUpgradeFromReadToWriteLock) {
}
TEST(lock, testUpgradeWriteToWriteLock) {
char buf[512];
ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644));
ASSERT_SYS(0, 0,
fcntl(3, F_SETLK,

View file

@ -72,7 +72,7 @@ TEST(makedirs, pathExists_isSuccess) {
TEST(mkdir, enametoolong) {
int i;
size_t n = 2048;
char *d, *s = gc(calloc(1, n));
char *s = gc(calloc(1, n));
for (i = 0; i < n - 1; ++i) s[i] = 'x';
s[i] = 0;
EXPECT_SYS(ENAMETOOLONG, -1, mkdir(s, 0644));

View file

@ -365,7 +365,7 @@ TEST(pledge, inet_forbidsOtherSockets) {
TEST(pledge, anet_forbidsUdpSocketsAndConnect) {
if (IsOpenbsd()) return; // b/c testing linux bpf
int ws, pid, yes = 1;
int ws, pid;
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
ASSERT_SYS(0, 0, pledge("stdio anet", 0));
@ -612,7 +612,7 @@ int LockWorker(void *arg, int tid) {
TEST(pledge, threadWithLocks_canCodeMorph) {
struct spawn worker;
int ws, pid;
int ws;
// not sure how this works on OpenBSD but it works!
if (!fork()) {
__enable_threads();
@ -627,7 +627,7 @@ TEST(pledge, threadWithLocks_canCodeMorph) {
}
TEST(pledge, everything) {
int ws, pid;
int ws;
if (!fork()) {
// contains 591 bpf instructions [2022-07-24]
ASSERT_SYS(0, 0,
@ -668,7 +668,6 @@ TEST(pledge, execWithoutRpath) {
}
BENCH(pledge, bench) {
int pid;
if (!fork()) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
EZBENCH2("sched_yield", donothing, sched_yield());

View file

@ -131,6 +131,7 @@ TEST(poll, pipe_hasInput) {
char buf[2];
sigset_t chldmask, savemask;
int ws, pid, sync[2], pipefds[2];
(void)sync;
EXPECT_EQ(0, sigemptyset(&chldmask));
EXPECT_EQ(0, sigaddset(&chldmask, SIGCHLD));
EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &chldmask, &savemask));

View file

@ -99,7 +99,7 @@ TEST(raise, test) {
if (IsXnu()) return; // no support for realtime signals yet
if (IsWindows()) return; // TODO(jart): why does it exit 128+SIGRTMIN?
void *p;
int r, i, s;
int r, i;
pthread_t t;
if (signal(SIGRTMIN, handler0) == SIG_ERR)
t_error("registering signal handler failed: %s\n", strerror(errno));

View file

@ -50,7 +50,7 @@ TEST(readlink, enotdir) {
}
TEST(readlinkat, test) {
char buf[128], *p, *q;
char buf[128];
memset(buf, -1, sizeof(buf));
ASSERT_NE(-1, xbarf("hello→", "hi", -1));
ASSERT_STREQ("hi", gc(xslurp("hello→", 0)));
@ -103,7 +103,6 @@ TEST(readlinkat, statReadsNameLength) {
}
TEST(readlinkat, realpathReturnsLongPath) {
struct stat st;
char buf[PATH_MAX];
if (!IsWindows()) return;
if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return;

View file

@ -120,19 +120,3 @@ int Worker(void *p, int tid) {
}
return 0;
}
TEST(reservefd, tortureTest) {
int i;
struct spawn th[THREADS];
struct sigaction oldsa;
struct itimerval oldit;
struct itimerval it = {{0, 10000}, {0, 100}};
struct sigaction sa = {.sa_sigaction = OnSigAlrm,
.sa_flags = 0 /* SA_NODEFER */};
// ASSERT_SYS(0, 0, sigaction(SIGALRM, &sa, &oldsa));
// ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &it, &oldit));
for (i = 0; i < THREADS; ++i) _spawn(Worker, 0, th + i);
for (i = 0; i < THREADS; ++i) _join(th + i);
// EXPECT_SYS(0, 0, sigaction(SIGALRM, &oldsa, 0));
// EXPECT_SYS(0, 0, setitimer(ITIMER_REAL, &oldit, 0));
}

View file

@ -91,11 +91,11 @@ __attribute__((__constructor__)) static void init(void) {
#ifdef __x86_64__
TEST(sched_setaffinity, isInheritedAcrossExecve) {
cpu_set_t x, y;
cpu_set_t x;
CPU_ZERO(&x);
CPU_SET(0, &x);
ASSERT_SYS(0, 0, sched_setaffinity(0, sizeof(x), &x));
int rc, ws, pid;
int ws, pid;
char *prog = GetProgramExecutableName();
char *args[] = {program_invocation_name, NULL};
char *envs[] = {"THE_DOGE=42", NULL};

View file

@ -55,8 +55,7 @@ void OnSigxfsz(int sig) {
}
TEST(setrlimit, testCpuLimit) {
char *p;
int i, wstatus;
int wstatus;
long double start;
struct rlimit rlim;
double matrices[3][3][3];
@ -84,7 +83,6 @@ TEST(setrlimit, testCpuLimit) {
}
TEST(setrlimit, testFileSizeLimit) {
char *p;
char junkdata[512];
int i, fd, wstatus;
struct rlimit rlim;
@ -129,7 +127,7 @@ TEST(setrlimit, testMemoryLimit) {
ASSERT_NE(-1, (wstatus = xspawn(0)));
if (wstatus == -2) {
ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM));
for (gotsome = i = 0; i < (MEM * 2) / getauxval(AT_PAGESZ); ++i) {
for (gotsome = false, i = 0; i < (MEM * 2) / getauxval(AT_PAGESZ); ++i) {
p = mmap(0, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0);
if (p != MAP_FAILED) {
@ -228,7 +226,7 @@ wontreturn void OnVfork(void *ctx) {
}
TEST(setrlimit, isVforkSafe) {
int pid, ws;
int ws;
struct rlimit rlim[2];
if (IsWindows()) return; /* of course it doesn't work on windows */
ASSERT_EQ(0, getrlimit(RLIMIT_CPU, rlim));

View file

@ -37,7 +37,6 @@ void OnSig(int sig, siginfo_t *si, void *ctx) {
}
TEST(sigprocmask, testMultipleBlockedDeliveries) {
int pid, ws;
sigset_t neu, old;
struct sigaction oldusr1, oldusr2;
struct sigaction sa = {.sa_sigaction = OnSig, .sa_flags = SA_SIGINFO};
@ -58,7 +57,6 @@ TEST(sigprocmask, testMultipleBlockedDeliveries) {
}
TEST(sigprocmask, testMultipleBlockedDeliveriesOfSameSignal) {
int pid, ws;
sigset_t neu, old;
struct sigaction oldusr2;
struct sigaction sa = {.sa_sigaction = OnSig, .sa_flags = SA_SIGINFO};

View file

@ -102,7 +102,6 @@ TEST(timespec_sub, math) {
for (int i = 0; i < 1000; ++i) {
struct timespec x = {mod(lemur64(), 10), mod(lemur64(), 10)};
struct timespec y = {mod(lemur64(), 10), mod(lemur64(), 10)};
struct timespec z = timespec_add(timespec_sub(x, y), y);
EXPECT_TRUE(!timespec_cmp(x, timespec_add(timespec_sub(x, y), y)));
}
}

View file

@ -40,8 +40,8 @@ void *Worker(void *arg) {
TEST(tkill, test) {
if (IsWindows()) return; // TODO(jart): fix me
int tid;
void *res;
int i, tid;
pthread_t t;
sigset_t ss, oldss;
sighandler_t oldsig;