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

@ -46,7 +46,7 @@ struct AcceptExBuffer {
textwindows int sys_accept_nt(struct Fd *fd, struct sockaddr_storage *addr,
int accept4_flags) {
int64_t handle;
int rc, client, oflags;
int client, oflags;
uint32_t bytes_received;
uint32_t completion_flags;
struct AcceptExBuffer buffer;

View file

@ -32,8 +32,8 @@
*/
const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) {
char *p;
unsigned char *ip;
int i, t, a, b, c, d;
const unsigned char *ip;
p = dst;
if (!size) return dst;
if ((ip = src)) {

View file

@ -46,7 +46,7 @@ static int inet_pton_inet6_impl(const char *src, uint8_t *dst) {
unsigned digitsLeft = 32;
bool zeroFound = false;
uint16_t currentSet = 0;
while (c = *src++) {
while ((c = *src++)) {
if (digitsLeft == 0) {
return 0;
}

View file

@ -37,7 +37,7 @@
struct NtWsaData kNtWsaData;
static textwindows void WinSockCleanup(void) {
int i, rc;
int rc;
(void)rc;
rc = WSACleanup();
NTTRACE("WSACleanup() → %d% lm", rc);

View file

@ -284,7 +284,6 @@ static int WaitForTrace(int main) {
int nointernet(void) {
int ws, act, main;
sigset_t set, old;
char path[PATH_MAX];
struct sock_fprog prog = {.filter = kInetBpf, .len = ARRAYLEN(kInetBpf)};
// seccomp bpf and ptrace are pretty much just linux for now.

View file

@ -60,7 +60,6 @@
int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask) {
int rc;
sigset_t oldmask;
struct timeval tv, *tvp;
struct timespec ts, *tsp;
struct {
@ -89,7 +88,8 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
ss.n = 8;
rc = sys_pselect(nfds, readfds, writefds, exceptfds, tsp, &ss);
} else if (!IsWindows()) {
rc = sys_pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask);
rc = sys_pselect(nfds, readfds, writefds, exceptfds,
(struct timespec *)timeout, sigmask);
} else {
if (timeout) {
tv.tv_sec = timeout->tv_sec;

View file

@ -42,7 +42,7 @@
* @restartable (unless SO_RCVTIMEO)
*/
ssize_t recv(int fd, void *buf, size_t size, int flags) {
ssize_t rc, got;
ssize_t rc;
BEGIN_CANCELLATION_POINT;
if (IsAsan() && !__asan_is_valid(buf, size)) {

View file

@ -54,12 +54,12 @@ ssize_t send(int fd, const void *buf, size_t size, int flags) {
rc = sys_sendto(fd, buf, size, flags, 0, 0);
} else if (__isfdopen(fd)) {
if (__isfdkind(fd, kFdSocket)) {
rc = sys_send_nt(fd, (struct iovec[]){{buf, size}}, 1, flags);
rc = sys_send_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, flags);
} else if (__isfdkind(fd, kFdFile)) {
if (flags) {
rc = einval();
} else {
rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, -1);
rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, -1);
}
} else {
rc = enotsock();

View file

@ -43,7 +43,6 @@
// sendfile() isn't specified as raising eintr
static textwindows int SendfileBlock(int64_t handle,
struct NtOverlapped *overlapped) {
int rc;
uint32_t i, got, flags = 0;
if (WSAGetLastError() != kNtErrorIoPending &&
WSAGetLastError() != WSAEINPROGRESS) {

View file

@ -74,15 +74,15 @@ ssize_t sendto(int fd, const void *buf, size_t size, int flags,
}
} else if (__isfdopen(fd)) {
if (__isfdkind(fd, kFdSocket)) {
rc = sys_sendto_nt(fd, (struct iovec[]){{buf, size}}, 1, flags, opt_addr,
addrsize);
rc = sys_sendto_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, flags,
opt_addr, addrsize);
} else if (__isfdkind(fd, kFdFile)) {
if (flags) {
rc = einval();
} else if (opt_addr) {
rc = eisconn();
} else {
rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, -1);
rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, -1);
}
} else {
rc = enotsock();

View file

@ -34,9 +34,9 @@ __msabi extern typeof(__sys_setsockopt_nt) *const __imp_setsockopt;
textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
const void *optval, uint32_t optlen) {
int64_t ms, micros;
struct timeval *tv;
struct linger *linger;
struct SockFd *sockfd;
const struct timeval *tv;
const struct linger *linger;
union {
uint32_t millis;
struct linger_nt linger;

View file

@ -32,7 +32,6 @@ const char *(DescribeSockaddr)(char buf[128], const struct sockaddr *sa,
size_t sasize) {
int e;
size_t n;
uint16_t port;
char *p, ip[72];
e = errno;
stpcpy(buf, "NULL");

View file

@ -33,8 +33,8 @@
textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) {
uint32_t mode;
int64_t hpipe, h1;
char16_t pipename[64];
int64_t hpipe, h1, h2;
int rc, reader, writer, oflags;
// Supports only AF_UNIX

View file

@ -19,7 +19,6 @@
#include "libc/sock/syslog.h"
#include "libc/calls/blockcancel.internal.h"
#include "libc/calls/calls.h"
#include "libc/stdio/dprintf.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"
@ -32,6 +31,7 @@
#include "libc/nt/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/sockaddr.h"
#include "libc/stdio/dprintf.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"
@ -261,7 +261,6 @@ int setlogmask(int maskpri) {
* @asyncsignalsafe
*/
void openlog(const char *ident, int opt, int facility) {
size_t n;
BLOCK_CANCELLATIONS;
if (log_facility == -1) __initlog();
if (!ident) ident = firstnonnull(program_invocation_short_name, "unknown");

View file

@ -43,8 +43,8 @@ static textwindows void __wsablock_abort(int64_t handle,
textwindows int __wsablock(struct Fd *fd, struct NtOverlapped *overlapped,
uint32_t *flags, int sigops, uint32_t timeout) {
int abort_errno;
uint32_t i, got;
int rc, abort_errno;
if (WSAGetLastError() != kNtErrorIoPending) {
// our i/o operation never happened because it failed
return __winsockerr();