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

@ -222,12 +222,11 @@ TEST(ksnprintf, testSymbols) {
}
TEST(ksnprintf, fuzzTheUnbreakable) {
int e;
size_t i;
uint64_t x;
char *f, b[32];
_Alignas(FRAMESIZE) static const char weasel[FRAMESIZE];
f = __veil("r", weasel);
f = (void *)__veil("r", weasel);
EXPECT_SYS(0, 0, mprotect(f, FRAMESIZE, PROT_READ | PROT_WRITE));
strcpy(f, "hello %s\n");
EXPECT_EQ(12, ksnprintf(b, sizeof(b), f, "world"));
@ -245,7 +244,6 @@ TEST(ksnprintf, fuzzTheUnbreakable) {
TEST(kprintf, testFailure_wontClobberErrnoAndBypassesSystemCallSupport) {
int n;
const char *s = 0;
ASSERT_EQ(0, errno);
EXPECT_SYS(0, 3, dup(2));
// <LIMBO>

View file

@ -43,7 +43,7 @@ static void *golden(void *a, const void *b, size_t n) {
}
TEST(memmove, hug) {
char *a, *b, *c;
char *a, *b;
int i, o1, o2;
int N[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 31, 32, 33, 63, 64, 65, 80, 81, 1000, 1024, 1025};
@ -63,7 +63,7 @@ TEST(memmove, hug) {
}
TEST(memmove, bighug) {
char *a, *b, *c;
char *a, *b;
int i, o1, o2;
int N[] = {5 * 1024 * 1024};
a = gc(malloc(6291456));
@ -82,19 +82,18 @@ TEST(memmove, bighug) {
}
BENCH(memmove, bench) {
volatile char *r;
int n, max = 128 * 1024 * 1024;
char *volatile p = gc(calloc(max, 1));
char *volatile q = gc(calloc(max, 1));
EZBENCH_N("memmove", 0, memmove(p, q, 0));
for (n = 0; n < 127; ++n) {
EZBENCH_N("memmove", n, r = memmove(p, q, n));
EZBENCH_N("memmove", n, memmove(p, q, n));
}
for (n = 128; n <= max; n *= 2) {
EZBENCH_N("memmove", n - 1, r = memmove(p, q, n - 1));
EZBENCH_N("memmove", n, r = memmove(p, q, n));
EZBENCH_N("memmove", n - 1, memmove(p, q, n - 1));
EZBENCH_N("memmove", n, memmove(p, q, n));
}
for (n = 500; n <= 1000; n += 100) {
EZBENCH_N("memmove", n, r = memmove(p, q, n));
EZBENCH_N("memmove", n, memmove(p, q, n));
}
}

View file

@ -88,14 +88,13 @@ BENCH(memset, bench) {
}
BENCH(strlen, bench) {
volatile size_t r;
int n, max = 8 * 1024 * 1024;
char *volatile p = gc(calloc(max + 1, 1));
EZBENCH_N("strlen", 0, strlen(p));
for (n = 2; n <= max; n *= 2) {
memset(p, -1, n - 1);
EZBENCH_N("strlen", n - 1, r = strlen(p));
EZBENCH_N("strlen", n - 1, strlen(p));
p[n - 1] = -1;
EZBENCH_N("strlen", n, r = strlen(p));
EZBENCH_N("strlen", n, strlen(p));
}
}

View file

@ -44,7 +44,6 @@ void *ForceThreadingMode(void *arg) {
}
TEST(pthread_atfork, test) {
int pid;
__enable_threads();
SPAWN(fork);
ASSERT_EQ(0, pthread_atfork(prepare1, parent1, child1));

View file

@ -57,14 +57,6 @@ void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio rpath", 0));
}
TEST(pthread_mutex_lock, initializer) {
struct sqlite3_mutex {
pthread_mutex_t mutex;
} mu[] = {{
PTHREAD_MUTEX_INITIALIZER,
}};
}
TEST(pthread_mutex_lock, normal) {
pthread_mutex_t lock;
pthread_mutexattr_t attr;

View file

@ -58,7 +58,7 @@ int Thrasher(void *arg, int tid) {
TEST(_rand64, testLcg_doesntProduceIdenticalValues) {
int i, j;
bzero(A, sizeof(A));
bzero((void *)A, sizeof(A));
for (i = 0; i < ARRAYLEN(A); ++i) {
A[i] = _rand64();
}
@ -72,13 +72,13 @@ TEST(_rand64, testLcg_doesntProduceIdenticalValues) {
}
TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) {
int i, j, rc, ws;
int i, j;
sigset_t ss, oldss;
struct sigaction oldsa;
struct spawn th[THREADS];
struct sigaction sa = {.sa_handler = OnChld, .sa_flags = SA_RESTART};
EXPECT_NE(-1, sigaction(SIGCHLD, &sa, &oldsa));
bzero(A, sizeof(A));
bzero((void *)A, sizeof(A));
sigemptyset(&ss);
sigaddset(&ss, SIGCHLD);
EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &ss, &oldss));

View file

@ -72,7 +72,6 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) {
}
char *strchr_pure(const char *s, int c) {
char *r;
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
if (!*s) return NULL;
@ -108,7 +107,7 @@ BENCH(strchr, bench) {
char *memchr_pure(const char *m, int c, size_t n) {
const unsigned char *p, *pe;
for (c &= 0xff, p = (const unsigned char *)m, pe = p + n; p < pe; ++p) {
if (*p == c) return p;
if (*p == c) return (void *)p;
}
return NULL;
}
@ -127,10 +126,9 @@ TEST(memchr, fuzz) {
}
char *strchrnul_pure(const char *s, int c) {
char *r;
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
if (!*s) return s;
if (!*s) return (void *)s;
}
}
@ -150,7 +148,7 @@ TEST(strchrnul, fuzz) {
void *rawmemchr_pure(const void *m, int c) {
const unsigned char *s;
for (c &= 255, s = m;; ++s) {
if (*s == c) return s;
if (*s == c) return (void *)s;
}
}

View file

@ -602,10 +602,10 @@ BENCH(bench_01_strcasecmp, bench) {
BENCH(memcmp, bench) {
volatile char *copy = gc(strdup(kHyperion));
EZBENCH2("memcmp big", donothing,
__expropriate(memcmp(kHyperion, copy, kHyperionSize)));
__expropriate(memcmp(kHyperion, (void *)copy, kHyperionSize)));
copy = gc(strdup("tough little ship"));
EZBENCH2("memcmp 18", donothing,
__expropriate(memcmp("tough little ship", copy, 18)));
__expropriate(memcmp("tough little ship", (void *)copy, 18)));
}
/* jart