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

@ -203,8 +203,8 @@ static dontinline int ReturnString(lua_State *L, const char *x) {
}
int LuaUnixSysretErrno(lua_State *L, const char *call, int olderr) {
int unixerr, winerr;
struct UnixErrno *ep;
int i, unixerr, winerr;
unixerr = errno;
winerr = IsWindows() ? GetLastError() : 0;
if (!IsTiny() && !(0 < unixerr && unixerr < (!IsWindows() ? 4096 : 65536))) {
@ -591,7 +591,7 @@ static int LuaUnixExecve(lua_State *L) {
return LuaUnixSysretErrno(L, "execve", olderr);
}
} else {
ezargs[0] = prog;
ezargs[0] = (char *)prog;
ezargs[1] = 0;
argv = ezargs;
envp = environ;
@ -736,7 +736,7 @@ static int LuaUnixWait(lua_State *L) {
// └─→ nil, unix.Errno
static int LuaUnixFcntl(lua_State *L) {
struct flock lock;
int rc, fd, cmd, olderr = errno;
int fd, cmd, olderr = errno;
fd = luaL_checkinteger(L, 1);
cmd = luaL_checkinteger(L, 2);
if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) {
@ -920,7 +920,6 @@ static int LuaUnixSetresgid(lua_State *L) {
// ├─→ 0
// └─→ nil, unix.Errno
static int LuaUnixUtimensat(lua_State *L) {
struct timespec ts;
int olderr = errno;
return SysretInteger(
L, "utimensat", olderr,
@ -937,7 +936,6 @@ static int LuaUnixUtimensat(lua_State *L) {
// ├─→ 0
// └─→ nil, unix.Errno
static int LuaUnixFutimens(lua_State *L) {
struct timespec ts;
int olderr = errno;
return SysretInteger(
L, "futimens", olderr,
@ -953,7 +951,7 @@ static int LuaUnixFutimens(lua_State *L) {
// └─→ nil, unix.Errno
static int LuaUnixGettime(lua_State *L) {
struct timespec ts;
int rc, olderr = errno;
int olderr = errno;
if (!clock_gettime(luaL_optinteger(L, 1, CLOCK_REALTIME), &ts)) {
lua_pushinteger(L, ts.tv_sec);
lua_pushinteger(L, ts.tv_nsec);
@ -1178,14 +1176,14 @@ static bool IsSockoptBool(int l, int x) {
x == SO_KEEPALIVE || //
x == SO_ACCEPTCONN || //
x == SO_DONTROUTE; //
} else if (l = SOL_TCP) {
} else if (l == SOL_TCP) {
return x == TCP_NODELAY || //
x == TCP_CORK || //
x == TCP_QUICKACK || //
x == TCP_SAVE_SYN || //
x == TCP_FASTOPEN_CONNECT || //
x == TCP_DEFER_ACCEPT; //
} else if (l = SOL_IP) {
} else if (l == SOL_IP) {
return x == IP_HDRINCL; //
} else {
return false;
@ -1198,7 +1196,7 @@ static bool IsSockoptInt(int l, int x) {
x == SO_RCVBUF || //
x == SO_RCVLOWAT || //
x == SO_SNDLOWAT; //
} else if (l = SOL_TCP) {
} else if (l == SOL_TCP) {
return x == TCP_FASTOPEN || //
x == TCP_KEEPCNT || //
x == TCP_MAXSEG || //
@ -1207,7 +1205,7 @@ static bool IsSockoptInt(int l, int x) {
x == TCP_WINDOW_CLAMP || //
x == TCP_KEEPIDLE || //
x == TCP_KEEPINTVL; //
} else if (l = SOL_IP) {
} else if (l == SOL_IP) {
return x == IP_TOS || //
x == IP_MTU || //
x == IP_TTL; //
@ -1230,7 +1228,7 @@ static int LuaUnixSetsockopt(lua_State *L) {
struct linger l;
uint32_t optsize;
struct timeval tv;
int rc, fd, level, optname, optint, olderr = errno;
int fd, level, optname, optint, olderr = errno;
fd = luaL_checkinteger(L, 1);
level = luaL_checkinteger(L, 2);
optname = luaL_checkinteger(L, 3);
@ -1281,7 +1279,7 @@ static int LuaUnixGetsockopt(lua_State *L) {
uint32_t size;
struct linger l;
struct timeval tv;
int rc, fd, level, optname, optval, olderr = errno;
int fd, level, optname, optval, olderr = errno;
fd = luaL_checkinteger(L, 1);
level = luaL_checkinteger(L, 2);
optname = luaL_checkinteger(L, 3);
@ -1547,7 +1545,7 @@ static int LuaUnixPoll(lua_State *L) {
struct sigset *mask;
struct timespec ts, *tsp;
struct pollfd *fds, *fds2;
int i, fd, events, olderr = errno;
int i, events, olderr = errno;
luaL_checktype(L, 1, LUA_TTABLE);
if (!lua_isnoneornil(L, 2)) {
ts = timespec_frommillis(luaL_checkinteger(L, 2));
@ -1633,7 +1631,7 @@ static int LuaUnixRecv(lua_State *L) {
size_t got;
ssize_t rc;
lua_Integer bufsiz;
int fd, flags, pushed, olderr = errno;
int fd, flags, olderr = errno;
fd = luaL_checkinteger(L, 1);
bufsiz = luaL_optinteger(L, 2, 1500);
bufsiz = MIN(bufsiz, 0x7ffff000);
@ -1655,9 +1653,8 @@ static int LuaUnixRecv(lua_State *L) {
// ├─→ sent:int
// └─→ nil, unix.Errno
static int LuaUnixSend(lua_State *L) {
char *data;
ssize_t rc;
size_t sent, size;
size_t size;
const char *data;
int fd, flags, olderr = errno;
fd = luaL_checkinteger(L, 1);
data = luaL_checklstring(L, 2, &size);
@ -1670,9 +1667,9 @@ static int LuaUnixSend(lua_State *L) {
// ├─→ sent:int
// └─→ nil, unix.Errno
static int LuaUnixSendto(lua_State *L) {
char *data;
size_t size;
uint32_t salen;
const char *data;
struct sockaddr_storage ss;
int i, fd, flags, olderr = errno;
fd = luaL_checkinteger(L, 1);
@ -1697,7 +1694,6 @@ static int LuaUnixShutdown(lua_State *L) {
// ├─→ oldmask:unix.Sigset
// └─→ nil, unix.Errno
static int LuaUnixSigprocmask(lua_State *L) {
uint64_t imask;
int olderr = errno;
struct sigset oldmask;
if (!sigprocmask(luaL_checkinteger(L, 1),
@ -2734,7 +2730,7 @@ static int LuaUnixMemoryWrite(lua_State *L) {
if (lua_isnoneornil(L, b)) {
// unix.Memory:write(data:str[, offset:int])
// writes binary data, plus a nul terminator
if (i < n < m->size) {
if (i < n && n < m->size) {
// include lua string's implicit nul so this round trips with
// unix.Memory:read(offset:int) even when we're overwriting a
// larger string that was previously inserted
@ -2842,7 +2838,7 @@ static int LuaUnixMemoryXor(lua_State *L) {
static int LuaUnixMemoryWait(lua_State *L) {
lua_Integer expect;
int rc, olderr = errno;
struct timespec ts, now, *deadline;
struct timespec ts, *deadline;
expect = luaL_checkinteger(L, 3);
if (!(INT32_MIN <= expect && expect <= INT32_MAX)) {
luaL_argerror(L, 3, "must be an int32_t");
@ -3351,7 +3347,8 @@ static const luaL_Reg kLuaUnix[] = {
{0}, //
};
static void LoadMagnums(lua_State *L, struct MagnumStr *ms, const char *pfx) {
static void LoadMagnums(lua_State *L, const struct MagnumStr *ms,
const char *pfx) {
int i;
char b[64], *p;
p = stpcpy(b, pfx);