mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
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:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -62,7 +62,6 @@ TEST(fgetln, testEvilLastLine) {
|
|||
}
|
||||
|
||||
TEST(fgetln, testReadingFromStdin_doesntLeakMemory) {
|
||||
FILE *f;
|
||||
int oldstdin, pfds[2];
|
||||
oldstdin = dup(0);
|
||||
EXPECT_SYS(0, 0, pipe(pfds));
|
||||
|
|
|
@ -56,7 +56,7 @@ TEST(getline, testOneWithoutLineFeed) {
|
|||
|
||||
TEST(getline, testTwoLines) {
|
||||
const char *s = "hello\nthere\n";
|
||||
FILE *f = fmemopen(s, strlen(s), "r+");
|
||||
FILE *f = fmemopen((void *)s, strlen(s), "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_EQ(6, getline(&line, &linesize, f));
|
||||
|
@ -72,7 +72,7 @@ TEST(getline, testTwoLines) {
|
|||
|
||||
TEST(getline, testBinaryLine_countExcludesOnlyTheBonusNul) {
|
||||
const char s[] = "he\0\3o\n";
|
||||
FILE *f = fmemopen(s, sizeof(s), "r+");
|
||||
FILE *f = fmemopen((void *)s, sizeof(s), "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_EQ(6, getline(&line, &linesize, f));
|
||||
|
@ -96,7 +96,6 @@ void ReadHyperionLines(void) {
|
|||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_NE(NULL, (f = fopen("hyperion.txt", "r")));
|
||||
int i = 0;
|
||||
for (;;) {
|
||||
rc = getline(&line, &linesize, f);
|
||||
if (rc == -1) break;
|
||||
|
|
|
@ -63,7 +63,7 @@ TEST(getentropy, test) {
|
|||
pthread_t child;
|
||||
double e, w = 7.7;
|
||||
struct sigaction sa;
|
||||
int i, j, k, m, n = 999;
|
||||
int i, k, m, n = 999;
|
||||
char *buf = _gc(calloc(1, n));
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = OnSig;
|
||||
|
|
|
@ -68,8 +68,8 @@ void *TortureWorker(void *arg) {
|
|||
}
|
||||
|
||||
TEST(getrandom, test) {
|
||||
int i, n = 999;
|
||||
double e, w = 7.7;
|
||||
int i, j, n = 999;
|
||||
char *buf = _gc(calloc(1, n));
|
||||
ASSERT_SYS(0, 0, getrandom(0, 0, 0));
|
||||
ASSERT_SYS(0, n, getrandom(buf, n, 0));
|
||||
|
@ -91,7 +91,7 @@ TEST(getrandom, test2) {
|
|||
pthread_t child;
|
||||
double e, w = 7.7;
|
||||
struct sigaction sa;
|
||||
int i, j, k, m, n = 999;
|
||||
int i, k, m, n = 999;
|
||||
char *buf = _gc(calloc(1, n));
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = OnSig;
|
||||
|
@ -307,7 +307,7 @@ static const struct RandomFunction {
|
|||
TEST(getrandom, sanityTest) {
|
||||
uint64_t q;
|
||||
size_t i, j, k;
|
||||
double montepi, chip, scc, mean, chisq, ent;
|
||||
double montepi, scc, mean, chisq, ent;
|
||||
for (k = 0; k < 1; ++k) {
|
||||
for (j = 0; j < ARRAYLEN(kRandomFunctions); ++j) {
|
||||
rt_init(0);
|
||||
|
@ -316,8 +316,8 @@ TEST(getrandom, sanityTest) {
|
|||
rt_add(&q, 8);
|
||||
}
|
||||
rt_end(&ent, &chisq, &mean, &montepi, &scc);
|
||||
chip = pochisq(chisq, 255);
|
||||
#if 0
|
||||
double chip = pochisq(chisq, 255);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "/* %-32s */\n", kRandomFunctions[j].s);
|
||||
fprintf(stderr, "/* entropy: %-12g */\n", ent);
|
||||
|
|
|
@ -47,7 +47,6 @@ int GetEntropy1(void *c, unsigned char *p, size_t n) {
|
|||
}
|
||||
|
||||
void ctrdrbg1(void *p, size_t n) {
|
||||
int rc;
|
||||
size_t i, m;
|
||||
mbedtls_ctr_drbg_context rng;
|
||||
mbedtls_ctr_drbg_init(&rng);
|
||||
|
@ -65,7 +64,6 @@ int GetEntropy2(void *c, unsigned char *p, size_t n) {
|
|||
}
|
||||
|
||||
void ctrdrbg2(void *p, size_t n) {
|
||||
int rc;
|
||||
size_t i, m;
|
||||
mbedtls_ctr_drbg_context rng;
|
||||
mbedtls_ctr_drbg_init(&rng);
|
||||
|
@ -153,63 +151,3 @@ TEST(mt19937, test) {
|
|||
ASSERT_EQ(want[i], _mt19937());
|
||||
}
|
||||
}
|
||||
|
||||
BENCH(mt19937, bench8) {
|
||||
volatile uint64_t x;
|
||||
EZBENCH2("lemur64", donothing, x = lemur64());
|
||||
EZBENCH2("_rand64", donothing, x = _rand64());
|
||||
EZBENCH2("vigna", donothing, x = vigna());
|
||||
EZBENCH2("vigna_r", donothing, vigna_r(&x));
|
||||
EZBENCH2("xorshift", donothing, x = xorshift());
|
||||
EZBENCH2("knuth", donothing, x = knuth());
|
||||
EZBENCH2("random", donothing, x = urandom());
|
||||
EZBENCH2("mt19937", donothing, x = _mt19937());
|
||||
EZBENCH2("rand64char", donothing, x = _rand64());
|
||||
size_t i = 0;
|
||||
volatile uint8_t *p = gc(malloc(3 * 2048 * 2 * 8));
|
||||
EZBENCH3("rdrand", 2048, donothing, p[i++] = rdrand());
|
||||
EZBENCH3("rdseed", 2048, donothing, p[i++] = rdseed());
|
||||
EZBENCH3("getrandom", 2048, donothing, GetRandom(p + i++, 8));
|
||||
}
|
||||
|
||||
BENCH(mt19937, bench32k) {
|
||||
volatile char *p = gc(malloc(32768));
|
||||
EZBENCH_N("rngset(_rand64,-1)", 32768, rngset(p, 32768, _rand64, -1));
|
||||
EZBENCH_N("rngset(rdseed,512)", 32768, rngset(p, 32768, rdseed, 512));
|
||||
EZBENCH_N("ctrdrbg+rdseed [blk]", 32768, ctrdrbg1(p, 32768));
|
||||
EZBENCH_N("getrandom [block]", 32768, GetRandom(p, 32768));
|
||||
EZBENCH_N("vigna [word]", 32768, rngset(p, 32768, vigna, 0));
|
||||
EZBENCH_N("xorshift [word]", 32768, xorshifta(p, 32768));
|
||||
EZBENCH_N("knuth [word]", 32768, knutha(p, 32768));
|
||||
EZBENCH_N("random [word]", 32768, rngset(p, 32768, urandom, 0));
|
||||
EZBENCH_N("mt19937 [word]", 32768, rngset(p, 32768, _mt19937, 0));
|
||||
EZBENCH_N("_rand64 [word]", 32768, rngset(p, 32768, _rand64, 0));
|
||||
EZBENCH_N("rdrand [word]", 32768, rngset(p, 32768, rdrand, 0));
|
||||
EZBENCH_N("rdseed [word]", 32768, rngset(p, 32768, rdseed, 0));
|
||||
}
|
||||
|
||||
BENCH(mt19937, bench48) {
|
||||
volatile char *p = gc(malloc(48));
|
||||
EZBENCH_N("rngset(rdrand,0)", 48, rngset(p, 48, rdrand, 0));
|
||||
EZBENCH_N("rngset(rdseed,0)", 48, rngset(p, 48, rdseed, 0));
|
||||
EZBENCH_N("getrandom", 48, GetRandom(p, 48));
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(mt19937, test) {
|
||||
int i;
|
||||
uint64_t init[4] = {0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL};
|
||||
uint64_t length = 4;
|
||||
mt19937_init_by_array64(init, length);
|
||||
printf("1000 outputs of genrand64_int64()\n");
|
||||
for (i = 0; i < 1000; i++) {
|
||||
printf("%20llu ", mt19937_genrand64_int64());
|
||||
if (i % 5 == 4) printf("\n");
|
||||
}
|
||||
printf("\n1000 outputs of genrand64_real2()\n");
|
||||
for (i = 0; i < 1000; i++) {
|
||||
printf("%10.8f ", mt19937_genrand64_real2());
|
||||
if (i % 5 == 4) printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,7 @@ __attribute__((__constructor__)) static void init(void) {
|
|||
}
|
||||
|
||||
TEST(posix_spawn, test) {
|
||||
int rc, ws, pid;
|
||||
int ws, pid;
|
||||
char *prog = GetProgramExecutableName();
|
||||
char *args[] = {prog, NULL};
|
||||
char *envs[] = {"THE_DOGE=42", NULL};
|
||||
|
@ -73,7 +73,8 @@ TEST(posix_spawn, pipe) {
|
|||
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[0]));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, p[1], 1));
|
||||
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[1]));
|
||||
ASSERT_EQ(0, posix_spawnp(&pid, pn, &fa, 0, (char *[]){pn, "hello", 0}, 0));
|
||||
ASSERT_EQ(
|
||||
0, posix_spawnp(&pid, pn, &fa, 0, (char *[]){(void *)pn, "hello", 0}, 0));
|
||||
ASSERT_SYS(0, 0, close(p[1]));
|
||||
ASSERT_SYS(0, pid, waitpid(pid, &status, 0));
|
||||
ASSERT_SYS(0, 6, read(p[0], buf, sizeof(buf)));
|
||||
|
@ -91,7 +92,6 @@ void OhMyGoth(int sig) {
|
|||
TEST(posix_spawn, torture) {
|
||||
int n = 10;
|
||||
int ws, pid;
|
||||
short flags;
|
||||
sigset_t allsig;
|
||||
posix_spawnattr_t attr;
|
||||
posix_spawn_file_actions_t fa;
|
||||
|
@ -157,7 +157,7 @@ TEST(posix_spawn, agony) {
|
|||
*/
|
||||
|
||||
void BenchmarkProcessLifecycle(void) {
|
||||
int rc, ws, pid;
|
||||
int ws, pid;
|
||||
char *prog = "/tmp/tiny64";
|
||||
char *args[] = {"tiny64", NULL};
|
||||
char *envs[] = {NULL};
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
|
||||
static char buffer[128];
|
||||
|
||||
#define Format(...) _gc(xasprintf(__VA_ARGS__))
|
||||
|
||||
/**
|
||||
|
|
|
@ -171,7 +171,6 @@ TEST(appendd, nontrivialAmountOfMemory) {
|
|||
}
|
||||
|
||||
BENCH(vappendf, bench) {
|
||||
const char t[] = {0};
|
||||
char *b = 0;
|
||||
EZBENCH2("appendf", donothing, appendf(&b, "hello"));
|
||||
EZBENCH2("kappendf", donothing, kappendf(&b, "hello"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue