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

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