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;

View file

@ -69,7 +69,7 @@ TEST(ParseHostsTxt, testIpv6_isIgnored) {
const char kInput[] = "::1 boop\n"
"203.0.113.2 cat # ignore me\n";
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+");
ASSERT_EQ(0, ParseHostsTxt(ht, f));
ASSERT_EQ(1, ht->entries.i);
EXPECT_STREQ("cat", &ht->strings.p[ht->entries.p[0].name]);

View file

@ -45,7 +45,7 @@ TEST(ParseResolvConf, testCorrectlyTokenizes) {
"nameserver 203.0.113.2 \n"
" nameserver 203.0.113.1\n";
struct ResolvConf *rv = calloc(1, sizeof(struct ResolvConf));
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+");
ASSERT_EQ(2, ParseResolvConf(rv, f));
ASSERT_EQ(2, rv->nameservers.i);
EXPECT_EQ(AF_INET, rv->nameservers.p[0].sin_family);

View file

@ -47,7 +47,7 @@ static const char kInput[] = "127.0.0.1 localhost\n"
TEST(ResolveHostsTxt, testBasicLookups) {
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+");
ASSERT_EQ(0, ParseHostsTxt(ht, f));
ASSERT_EQ(5, ht->entries.i);
EXPECT_STREQ("127.0.0.1", EzIp4Lookup(ht, "localhost"));
@ -63,7 +63,7 @@ TEST(ResolveHostsTxt, testBasicLookups) {
TEST(ResolveHostsTxt, testCanonicalize) {
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+");
ASSERT_EQ(0, ParseHostsTxt(ht, f));
ASSERT_EQ(5, ht->entries.i);
EXPECT_STREQ("localhost", EzCanonicalize(ht, "localhost"));

View file

@ -22,7 +22,7 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
char buf[19];
char buf[100];
void SetUp(void) {
memset(buf, 0x55, sizeof(buf));

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

View file

@ -99,7 +99,7 @@ TEST(realloc_in_place, test) {
BENCH(realloc_in_place, bench) {
volatile int i = 1000;
volatile char *x = malloc(i);
char *volatile x = malloc(i);
EZBENCH2("malloc", donothing, free(malloc(i)));
EZBENCH2("memalign", donothing, free(memalign(16, i)));
EZBENCH2("memalign", donothing, free(memalign(32, i)));
@ -116,10 +116,11 @@ void AppendStuff(char **p, size_t *n) {
}
TEST(malloc, test) {
size_t n;
char *big = 0;
size_t n, bigsize = 0;
static struct stat st;
static volatile int i, j, k, *A[4096], fds[M], *maps[M], mapsizes[M];
static int *A[4096], *maps[M];
static int i, j, k, fds[M], mapsizes[M];
memset(fds, -1, sizeof(fds));
memset(maps, -1, sizeof(maps));
for (i = 0; i < N * M; ++i) {

View file

@ -107,6 +107,8 @@ TEST(sortedints, fuzz) {
b = ContainsInt(&T, x);
b = ContainsInt(&T, -x);
y = CountInt(&T, x);
(void)b;
(void)y;
}
for (int i = 1; i < T.n; ++i) {
ASSERT_GE(T.p[i], T.p[i - 1]);
@ -123,4 +125,5 @@ BENCH(sortedints, bench) {
}
EZBENCH2("insert big", donothing, InsertInt(&T, lemur64(), true));
EZBENCH2("contains big", donothing, ContainsInt(&T, lemur64()));
(void)x;
}

View file

@ -82,7 +82,6 @@ TEST(gclongjmp, test) {
}
void crawl(const char *path) {
const char *dir;
if (!strcmp(path, "/") || !strcmp(path, ".")) return;
crawl(_gc(xdirname(path)));
}
@ -100,7 +99,6 @@ TEST(gc, torture) {
}
void crawl2(jmp_buf jb, const char *path) {
const char *dir;
if (!strcmp(path, "/") || !strcmp(path, ".")) _gclongjmp(jb, 1);
crawl2(jb, _gc(xdirname(path)));
}

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
void *_memset(void *, int, size_t) asm("memset");
@ -68,7 +68,7 @@ TEST(memset, size5) {
}
TEST(memset, wut) {
char buf[128], *p, *q;
char buf[128];
_memset(buf, -1, sizeof(buf));
EXPECT_EQ(255, buf[8] & 255);
}

View file

@ -30,14 +30,13 @@
char testlib_enable_tmp_setup_teardown;
TEST(daemon, test) {
int dirfd;
char buf[512];
SPAWN(fork);
ASSERT_SYS(0, 3, open(".", O_RDONLY | O_DIRECTORY));
ASSERT_SYS(0, 0, daemon(false, false));
ASSERT_SYS(0, 4, openat(3, "ok", O_WRONLY | O_CREAT | O_TRUNC, 0644));
ASSERT_NE(NULL, getcwd(buf, sizeof(buf)));
ASSERT_SYS(0, 0, write(4, buf, strlen(buf)));
ASSERT_SYS(0, 1, write(4, buf, strlen(buf)));
ASSERT_SYS(0, 0, close(4));
ASSERT_SYS(0, 0, close(3));
EXITS(0);

View file

@ -135,7 +135,6 @@ TEST(fork, childToChild) {
}
TEST(fork, preservesTlsMemory) {
int pid;
__get_tls()->tib_errno = 31337;
SPAWN(fork);
ASSERT_EQ(31337, __get_tls()->tib_errno);

View file

@ -354,8 +354,8 @@ TEST(mmap, cow) {
TEST(mmap, cowFileMapReadonlyFork) {
char *p;
int fd, pid, ws;
char path[PATH_MAX], lol[6];
int fd, ws;
char path[PATH_MAX];
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(6, write(fd, "hello", 6));
@ -380,7 +380,7 @@ TEST(mmap, cowFileMapReadonlyFork) {
TEST(mmap, cowFileMapFork) {
char *p;
int fd, pid, ws;
int fd, ws;
char path[PATH_MAX], lol[6];
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
@ -409,8 +409,8 @@ TEST(mmap, cowFileMapFork) {
// SHARED ANONYMOUS MEMORY BETWEEN PROCESSES
TEST(mmap, sharedAnonMapFork) {
int ws;
char *p;
int pid, ws;
EXPECT_NE(MAP_FAILED, (p = mmap(NULL, 6, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0)));
strcpy(p, "parnt");
@ -432,7 +432,7 @@ TEST(mmap, sharedAnonMapFork) {
TEST(mmap, sharedFileMapFork) {
char *p;
int fd, pid, ws;
int fd, ws;
char path[PATH_MAX], lol[6];
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));

View file

@ -22,6 +22,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
@ -85,7 +86,7 @@ void OnSigBus(int sig, struct siginfo *si, void *vctx) {
kprintf("si->si_signo = %G%n", si->si_signo);
kprintf("si->si_errno = %s (%d)%n", _strerrno(si->si_errno),
si->si_errno);
kprintf("si->si_code = %s (%d)%n", GetSiCodeName(sig, si->si_code),
kprintf("si->si_code = %s (%d)%n", DescribeSiCode(sig, si->si_code),
si->si_code);
kprintf("┌si->si_addr = %p%n", si->si_addr);
kprintf("┼─────────────────%n");
@ -133,14 +134,15 @@ TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) {
p[0] = 1;
EXPECT_FALSE(gotsegv);
EXPECT_FALSE(gotbusted);
EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ));
EXPECT_NE(-1, mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ));
__expropriate(p[0]);
EXPECT_FALSE(gotsegv);
EXPECT_FALSE(gotbusted);
p[0] = 2;
EXPECT_TRUE(gotsegv | gotbusted);
EXPECT_EQ(1, p[0]);
EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE));
EXPECT_NE(-1,
mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE));
}
TEST(mprotect, testExecOnly_canExecute) {
@ -161,10 +163,11 @@ TEST(mprotect, testExecOnly_canExecute) {
TEST(mprotect, testProtNone_cantEvenRead) {
volatile char *p;
p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ)));
EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_NONE));
EXPECT_NE(-1, mprotect((void *)p, getauxval(AT_PAGESZ), PROT_NONE));
__expropriate(p[0]);
EXPECT_TRUE(gotsegv | gotbusted);
EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE));
EXPECT_NE(-1,
mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE));
}
TEST(mprotect, testExecJit_actuallyWorks) {
@ -223,13 +226,13 @@ TEST(mprotect, testFileMap_canChangeToExecWhileOpenInRdwrMode) {
TEST(mprotect, testBadProt_failsEinval) {
volatile char *p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ)));
EXPECT_EQ(-1, mprotect(p, 9999, -1));
EXPECT_EQ(-1, mprotect((void *)p, 9999, -1));
EXPECT_EQ(EINVAL, errno);
}
TEST(mprotect, testZeroSize_doesNothing) {
volatile char *p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ)));
EXPECT_NE(-1, mprotect(p, 0, PROT_READ));
EXPECT_NE(-1, mprotect((void *)p, 0, PROT_READ));
p[0] = 1;
EXPECT_FALSE(gotsegv);
EXPECT_FALSE(gotbusted);

View file

@ -34,9 +34,7 @@
#include "libc/thread/thread.h"
TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) {
int ws, pid;
char buf[16] = {0};
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
.sin_family = AF_INET,
@ -81,9 +79,7 @@ TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) {
}
TEST(O_NONBLOCK, canBeTunedWithFcntl_toMakeReadNonBlocking) {
int ws, pid;
char buf[16] = {0};
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
.sin_family = AF_INET,

View file

@ -32,8 +32,6 @@
// two clients send a udp packet containing their local address
// server verifies content of packet matches the peer's address
TEST(recvfrom, test) {
int ws, pid;
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in server = {
.sin_family = AF_INET,

View file

@ -54,7 +54,6 @@ int64_t GetFileOffset(int fd) {
TEST(sendfile, testSeeking) {
char buf[1024];
int rc, ws, fds[2];
int64_t inoffset = 0;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
@ -94,6 +93,7 @@ TEST(sendfile, testSeeking) {
ASSERT_SYS(0, 500, read(3, buf + 12, 700));
ASSERT_EQ(0, memcmp(buf, kHyperion, 512));
ASSERT_SYS(0, 0, close(3));
int ws;
ASSERT_NE(-1, wait(&ws));
ASSERT_TRUE(WIFEXITED(ws));
ASSERT_EQ(0, WEXITSTATUS(ws));
@ -102,7 +102,6 @@ TEST(sendfile, testSeeking) {
TEST(sendfile, testPositioning) {
// TODO(jart): fix test regression on windows
if (IsWindows()) return;
int ws, fds[2];
char buf[1024];
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
@ -141,6 +140,7 @@ TEST(sendfile, testPositioning) {
ASSERT_SYS(0, 0, read(3, buf, 12));
ASSERT_EQ(0, memcmp(buf, kHyperion, 12));
ASSERT_SYS(0, 0, close(3));
int ws;
ASSERT_NE(-1, wait(&ws));
ASSERT_TRUE(WIFEXITED(ws));
ASSERT_EQ(0, WEXITSTATUS(ws));

View file

@ -44,9 +44,9 @@ TEST(sendrecvmsg, testPingPong) {
memset(&msg, 0, sizeof(msg));
memset(&data[0], 0, sizeof(data));
data[0].iov_base = hello;
data[0].iov_base = (void *)hello;
data[0].iov_len = strlen(hello);
data[1].iov_base = world;
data[1].iov_base = (void *)world;
data[1].iov_len = strlen(world); /* Don't send the '\0' */
msg.msg_iov = &data[0];

View file

@ -34,9 +34,7 @@
#include "libc/testlib/testlib.h"
TEST(ipv4, test) {
int ws, pid;
char buf[16] = {0};
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
.sin_family = AF_INET,
@ -61,7 +59,6 @@ TEST(ipv4, test) {
TEST(ipv6, test) {
char buf[16] = {0};
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in6);
struct sockaddr_in6 addr = {
.sin6_family = AF_INET6,
@ -116,7 +113,6 @@ TEST(getsockname, copiesSafely_givesFullSize) {
TEST(socket, canBeInheritedByForkedWorker) {
char buf[16] = {0};
int64_t inoffset;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
.sin_family = AF_INET,
@ -156,7 +152,6 @@ __attribute__((__constructor__)) static void StdioPro(int argc, char *argv[]) {
TEST(socket, canBeUsedAsExecutedStdio) {
char buf[16] = {0};
int64_t inoffset;
const char *prog;
uint32_t addrsize = sizeof(struct sockaddr_in);
struct sockaddr_in addr = {
@ -173,7 +168,7 @@ TEST(socket, canBeUsedAsExecutedStdio) {
accept4(3, (struct sockaddr *)&addr, &addrsize, SOCK_CLOEXEC));
ASSERT_SYS(0, 1, dup2(4, 1));
SPAWN(vfork);
execve(prog, (char *[]){prog, "StdioProg", 0}, (char *[]){0});
execve(prog, (char *[]){(void *)prog, "StdioProg", 0}, (char *[]){0});
abort();
PARENT();
ASSERT_SYS(0, 0, close(4));

View file

@ -120,7 +120,6 @@ TEST(unix, stream) {
TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine
if (IsWindows()) return;
if (IsCygwin()) return;
int ws, rc;
char buf[8] = {0};
uint32_t len = sizeof(struct sockaddr_un);
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};
@ -138,7 +137,7 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine
ASSERT_SYS(0, 0, unlink(addr.sun_path));
ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_DGRAM, 0));
ASSERT_SYS(0, 0, bind(3, (void *)&addr, len));
rc = write(4, "hello", 5);
int rc = write(4, "hello", 5);
ASSERT_TRUE(rc == -1 && (errno == ECONNRESET || //
errno == ENOTCONN || //
errno == ECONNREFUSED || //
@ -156,7 +155,6 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine
TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier
if (IsWindows()) return;
if (IsCygwin()) return;
int ws, rc;
char buf[8] = {0};
uint32_t len = sizeof(struct sockaddr_un);
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};

View file

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

View file

@ -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;

View file

@ -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;

View file

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

View file

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

View file

@ -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};

View file

@ -24,8 +24,6 @@
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
static char buffer[128];
#define Format(...) _gc(xasprintf(__VA_ARGS__))
/**

View file

@ -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"));

View file

@ -31,9 +31,3 @@ TEST(memcasecmp, test) {
EXPECT_EQ(0, memcasecmp("\0ELLo\0ELLo", "\0ELLO\0ELLO", 10));
EXPECT_NE(0, memcasecmp("\0ELLo\0ELLo", "\0ELL-\0ELL-", 10));
}
BENCH(memcasecmp, bench) {
volatile char *copy = gc(strdup(kHyperion));
EZBENCH2("memcasecmp", donothing,
__expropriate(memcasecmp(kHyperion, copy, kHyperionSize)));
}

View file

@ -136,30 +136,6 @@ TEST(memcpy, overlapping_isFineIfCopyingBackwards) {
}
}
TEST(stpcpy, test) {
volatile char *p;
volatile char b[16];
volatile const char *s1 = "hello";
volatile const char *s2 = "there";
p = b;
p = stpcpy(p, s1);
EXPECT_EQ((intptr_t)b + 5, (intptr_t)p);
EXPECT_STREQ("hello", b);
p = stpcpy(p, s2);
EXPECT_EQ((intptr_t)b + 10, (intptr_t)p);
EXPECT_STREQ("hellothere", b);
}
TEST(memcpy, testBackwardsOverlap3) {
volatile char *c;
c = malloc(3);
memcpy(c, "\e[C", 3);
memcpy(c, c + 1, __veil("r", 3) - 1);
EXPECT_EQ('[', c[0]);
EXPECT_EQ('C', c[1]);
free(c);
}
#define B(F, N) \
do { \
char *d = rngset(malloc(N), N, _rand64, -1); \

View file

@ -31,7 +31,7 @@
void *memmem_naive(const void *haystk, size_t haystklen, //
const void *needle, size_t needlelen) {
size_t i, j;
if (!needlelen) return haystk;
if (!needlelen) return (void *)haystk;
if (needlelen > haystklen) return 0;
for (i = 0; i < haystklen; ++i) {
for (j = 0;; ++j) {
@ -155,7 +155,7 @@ TEST(memmem, testWut) {
}
TEST(memmem, fuzz) {
int i, j, k, n, m;
int i, n, m;
char a[128], b[128], *p, *q;
for (i = 0; i < 10000; ++i) {
rngset(a, sizeof(a), lemur64, -1);

View file

@ -33,8 +33,7 @@
char *strcasestr_naive(const char *haystack, const char *needle) {
size_t i;
unsigned k, m;
if (haystack == needle || !*needle) return haystack;
if (haystack == needle || !*needle) return (void *)haystack;
for (;;) {
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char *)haystack;

View file

@ -32,8 +32,7 @@
char *strstr_naive(const char *haystack, const char *needle) {
size_t i;
unsigned k, m;
if (haystack == needle || !*needle) return haystack;
if (haystack == needle || !*needle) return (void *)haystack;
for (;;) {
for (i = 0;; ++i) {
if (!needle[i]) return (/*unconst*/ char *)haystack;

View file

@ -76,6 +76,5 @@ TEST(strwidth, testTextDelimitingControlCodes_dontHaveSubstance) {
}
BENCH(wcwidth, bench) {
volatile int x;
EZBENCH2("wcwidth", donothing, x = wcwidth(__veil("r", u'')));
EZBENCH2("wcwidth", donothing, __expropriate(wcwidth(__veil("r", u''))));
}

View file

@ -68,7 +68,6 @@ TEST(pthread_cancel, self_deferred_waitsForCancellationPoint) {
}
void *Worker(void *arg) {
int n;
char buf[8];
pthread_cleanup_push(OnCleanup, 0);
read(pfds[0], buf, sizeof(buf));
@ -224,8 +223,10 @@ void *CpuBoundWorker(void *arg) {
CheckStackIsAligned();
wouldleak = malloc(123);
wontleak1 = malloc(123);
(void)wontleak1;
pthread_cleanup_push(free, wontleak1);
wontleak2 = _gc(malloc(123));
(void)wontleak2;
ASSERT_EQ(0, pthread_setspecific(key, (void *)31337));
ASSERT_EQ(0, pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0));
#ifdef __x86_64__
@ -262,7 +263,6 @@ TEST(pthread_cancel, async) {
}
void *CancelSelfWorkerAsync(void *arg) {
char buf[8];
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
pthread_cleanup_push(OnCleanup, 0);
pthread_cancel(pthread_self());

View file

@ -40,7 +40,6 @@
#include "libc/thread/thread2.h"
void OnUsr1(int sig, struct siginfo *si, void *vctx) {
struct ucontext *ctx = vctx;
}
void SetUp(void) {
@ -83,7 +82,7 @@ TEST(pthread_create, testCreateExitJoin) {
}
static void *CheckSchedule(void *arg) {
int rc, policy;
int policy;
struct sched_param prio;
ASSERT_EQ(0, pthread_getschedparam(pthread_self(), &policy, &prio));
ASSERT_EQ(SCHED_OTHER, policy);

View file

@ -27,7 +27,6 @@
#include "libc/thread/thread.h"
void OnUsr1(int sig, struct siginfo *si, void *vctx) {
struct ucontext *ctx = vctx;
}
void SetUp(void) {

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/errno.h"
@ -44,54 +45,53 @@ TEST(sem_init, einval) {
TEST(sem_post, afterDestroyed_isUndefinedBehavior) {
if (!IsModeDbg()) return;
int val;
sem_t sem;
SPAWN(fork);
signal(SIGABRT, SIG_DFL);
ASSERT_SYS(0, 0, sem_init(&sem, 0, 0));
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_post(&sem);
EXITS(128 + SIGABRT); // see __assert_fail
TERMS(SIGABRT);
}
TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) {
if (!IsModeDbg()) return;
int val;
sem_t sem;
SPAWN(fork);
signal(SIGABRT, SIG_DFL);
ASSERT_SYS(0, 0, sem_init(&sem, 0, 0));
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_trywait(&sem);
EXITS(128 + SIGABRT); // see __assert_fail
TERMS(SIGABRT);
}
TEST(sem_wait, afterDestroyed_isUndefinedBehavior) {
if (!IsModeDbg()) return;
int val;
sem_t sem;
SPAWN(fork);
signal(SIGABRT, SIG_DFL);
ASSERT_SYS(0, 0, sem_init(&sem, 0, 0));
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_wait(&sem);
EXITS(128 + SIGABRT); // see __assert_fail
TERMS(SIGABRT);
}
TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) {
if (!IsModeDbg()) return;
int val;
sem_t sem;
SPAWN(fork);
signal(SIGABRT, SIG_DFL);
ASSERT_SYS(0, 0, sem_init(&sem, 0, 0));
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_timedwait(&sem, 0);
EXITS(128 + SIGABRT); // see __assert_fail
TERMS(SIGABRT);
}
void *Worker(void *arg) {
int rc;
sem_t **s = arg;
struct timespec ts;
ASSERT_SYS(0, 0, clock_gettime(CLOCK_REALTIME, &ts));

View file

@ -58,9 +58,9 @@ BENCH(sincos, bench) {
double _sincos(double, double*, double*) asm("sincos");
float _sincosf(float, float*, float*) asm("sincosf");
long double _sincosl(long double, long double*, long double*) asm("sincosl");
volatile float sinef, cosinef;
volatile double sine, cosine;
volatile long double sinel, cosinel;
float sinef, cosinef;
double sine, cosine;
long double sinel, cosinel;
EZBENCH2("sin+cos", donothing, (_sin(NUM), _cos(NUM)));
EZBENCH2("sincos", donothing, _sincos(NUM, &sine, &cosine));
EZBENCH2("sinf+cosf", donothing, (_sinf(NUM), _cosf(NUM)));