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

@ -93,10 +93,8 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
}
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
bool slashed;
const char *q, *b;
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
for (b = p, q = (p += strlen(p)); p > b; --p) {
if (!isalnum(p[-1]) &&
(p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' &&
p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) {
@ -143,8 +141,8 @@ int main(int argc, char *argv[]) {
char *prog, path[PATH_MAX];
sigset_t chldmask, savemask;
int stdoutflags, stderrflags;
int n, rc, ws, child, killcount;
const char *stdoutpath, *stderrpath;
int n, rc, ws, pid, child, killcount;
struct sigaction sa, saveint, savequit;
char *p, *line, **args, *arg, *start, *state, prompt[1024];
linenoiseSetFreeHintsCallback(free);

View file

@ -36,6 +36,7 @@ dontubsan int main(int argc, char *argv[]) {
volatile double a = 0;
volatile double b = 23;
volatile double c = exp(b) / a;
(void)c;
volatile int64_t x;
return 1 / (x = 0);

View file

@ -43,7 +43,6 @@
*/
int main(int argc, char *argv[]) {
volatile int64_t x;
ShowCrashReports();
printf("please press ctrl+\\ and see what happens...\n");
sigsuspend(0);

View file

@ -35,8 +35,7 @@ void PrintUsage(int rc, FILE *f) {
void PrintUri(const char *path) {
size_t n;
void *img, *src, *mime;
int opt, i;
void *img;
if (!(img = gc(xslurp(path, &n)))) exit(2);
fputs("data:", stdout);
fputs(FindContentType(path, -1), stdout);

View file

@ -7,15 +7,15 @@
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/mem/mem.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
/**
* Cosmopolitan C is just as awesome as Go!
* Example contributed by @Keithcat1 (#266)
*/
main() {
int main() {
_defer(printf, "Done!\n");
for (long i = 0; i < 100000; i++) {
printf("%i ", i);

View file

@ -11,7 +11,6 @@
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
int pid;
if (argc < 3) {
fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
return 1;

View file

@ -11,8 +11,6 @@
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
int pid;
volatile void *p;
if (argc < 3) {
fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
return 1;

View file

@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
struct tm tm;
struct timeval tv;
rc = gettimeofday(&tv, 0);
assert(!rc);
unassert(!rc);
t = tv.tv_sec;
gmtime_r(&t, &tm);
FormatHttpDateTime(p, &tm);

View file

@ -148,14 +148,13 @@ void *Worker(void *id) {
while (!closingtime) {
struct tm tm;
int64_t unixts;
struct Url url;
ssize_t got, sent;
struct timespec ts;
struct HttpMessage msg;
uint32_t clientaddrsize;
struct sockaddr_in clientaddr;
char inbuf[1500], outbuf[512], *p, *q;
int clientip, client, inmsglen, outmsglen;
int client, inmsglen, outmsglen;
// this slows the server down a lot but is needed on non-Linux to
// react to keyboard ctrl-c

View file

@ -38,8 +38,8 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/time/time.h"
@ -178,8 +178,7 @@ void youwon()
printf("you win, the word is %s\n",realword);
}
main(argc,argv)
char **argv;
int main(int argc,char **argv)
{
if(argc==1) dictfile=DICT;
else dictfile=argv[1];

View file

@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
luaL_openlibs(L);
lua_pushcfunction(L, NativeAdd);
lua_setglobal(L, "NativeAdd");
luaL_dofile(L, "/zip/examples/hellolua.lua");
(void)luaL_dofile(L, "/zip/examples/hellolua.lua");
lua_close(L);
return 0;
}

View file

@ -44,14 +44,14 @@ void PrintUsage(int rc, FILE *f) {
void PrintImg(const char *path) {
size_t n;
int opt, i, yn, xn, cn, w, h;
void *img, *pix, *src, *mime;
int yn, xn, cn, w, h;
void *img, *pix, *src;
if (!(img = _gc(xslurp(path, &n)))) exit(2);
if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
if (linktag) {
printf("<a href=\"%s\"\n >", path);
}
src = path;
src = (void *)path;
if (datauri) {
src = xasprintf("data:%s;base64,%s", FindContentType(path, -1),
_gc(EncodeBase64(img, n, &n)));

View file

@ -413,9 +413,9 @@ void editorUpdateSyntax(erow *row) {
int i, prev_sep, in_string, in_comment;
char *p;
const char *const *keywords = E.syntax->keywords;
char *scs = E.syntax->singleline_comment_start;
char *mcs = E.syntax->multiline_comment_start;
char *mce = E.syntax->multiline_comment_end;
const char *scs = E.syntax->singleline_comment_start;
const char *mcs = E.syntax->multiline_comment_start;
const char *mce = E.syntax->multiline_comment_end;
/* Point to the first non-space char. */
p = row->render;
@ -575,7 +575,7 @@ int editorSyntaxToColor(int hl) {
* setting it in the global state E.syntax. */
void editorSelectSyntaxHighlight(char *filename) {
for (unsigned j = 0; j < HLDB_ENTRIES; j++) {
struct editorSyntax *s = HLDB + j;
const struct editorSyntax *s = HLDB + j;
unsigned i = 0;
while (s->filematch[i]) {
char *p;
@ -898,7 +898,7 @@ struct abuf {
};
static void abAppend(struct abuf *ab, const char *s, int len) {
CONCAT(&ab->p, &ab->i, &ab->n, s, len);
CONCAT(&ab->p, &ab->i, &ab->n, (void *)s, len);
}
/* This function writes the whole screen using VT100 escape characters

View file

@ -18,7 +18,7 @@
int main(int argc, char *argv[]) {
long i, ns;
struct timespec x, y, w;
struct timespec x, y;
timespec_sleep(timespec_fromnanos(0)); // warmup
printf("\nrelative sleep\n");

View file

@ -45,10 +45,10 @@
int main(int argc, char *argv[]) {
ssize_t rc;
size_t i, got;
int opt, sock;
char buf[1500];
bool halfclose = true;
const char *host, *port;
int opt, err, toto, sock;
struct addrinfo *ai = NULL;
struct linger linger = {true, 1};
struct pollfd fds[2] = {{-1, POLLIN}, {-1, POLLIN}};

View file

@ -164,7 +164,6 @@ static struct TtyRgb* ttyrgb_;
static unsigned char *R, *G, *B;
static struct ZipGames zipgames_;
static struct Action arrow_, button_;
static struct SamplingSolution* asx_;
static struct SamplingSolution* ssy_;
static struct SamplingSolution* ssx_;
static unsigned char pixels_[3][DYN][DXN];
@ -585,7 +584,6 @@ void Raster(void) {
f->p = stpcpy(f->p, "\e[0m\e[H");
f->p = stpcpy(f->p, status_.text);
}
CHECK_LT(f->p - f->mem, vtsize_);
PollAndSynchronize();
}
@ -599,7 +597,6 @@ void FlushScanline(unsigned py) {
}
static void PutPixel(unsigned px, unsigned py, unsigned pixel, int offset) {
unsigned rgb;
static unsigned prev;
pixels_[0][py][px] = palette_[offset][prev % 64][pixel][2];
pixels_[1][py][px] = palette_[offset][prev % 64][pixel][1];
@ -1811,8 +1808,8 @@ void GetOpts(int argc, char* argv[]) {
size_t FindZipGames(void) {
char* name;
size_t i, cf;
struct Zipos* zipos;
size_t i, cf, namesize;
if ((zipos = __zipos_get())) {
for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir);
i < ZIP_CDIR_RECORDS(zipos->cdir);
@ -1834,14 +1831,14 @@ int SelectGameFromZip(void) {
int i, rc;
char *line, *uri;
fputs("\nCOSMOPOLITAN NESEMU1\n\n", stdout);
for (i = 0; i < zipgames_.i; ++i) {
for (i = 0; i < (int)zipgames_.i; ++i) {
printf(" [%d] %s\n", i, zipgames_.p[i]);
}
fputs("\nPlease choose a game (or CTRL-C to quit) [default 0]: ", stdout);
fflush(stdout);
rc = 0;
if ((line = GetLine())) {
i = MAX(0, MIN(zipgames_.i - 1, atoi(line)));
i = MAX(0, MIN((int)zipgames_.i - 1, atoi(line)));
uri = zipgames_.p[i];
rc = PlayGame(uri, NULL);
free(uri);

View file

@ -122,7 +122,7 @@ void Clear(void) {
}
void Layout(void) {
long i, j;
long i;
i = txn >> 1;
pan.left.top = 0;
pan.left.left = 0;

View file

@ -113,9 +113,9 @@ main(int argc, char *argv[])
static char obuf[BUFSIZ];
static char ibuf[BUFSIZ];
fd_set rfd;
int fm_fd;
int aflg, Fflg, kflg, pflg, ch, k, n;
int flushtime, readstdin;
int fm_fd, fm_log;
aflg = Fflg = kflg = pflg = 0;
usesleep = 1;
@ -125,6 +125,8 @@ main(int argc, char *argv[])
warning. (not needed w/clang) */
showexit = 0;
(void)fm_fd;
while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
switch(ch) {
case 'a':

View file

@ -1026,7 +1026,6 @@ struct t_op {
cosmopolitan § the unbourne shell » bss
*/
static int inter;
static char **argptr; /* argument list for builtin commands */
static char **gargv;
static char **t_wp;
@ -5747,7 +5746,7 @@ static void CompleteCommand(const char *p, const char *q, const char *b,
}
closedir(d);
}
free(path);
free((void *)path);
}
}
}
@ -5784,7 +5783,6 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
bool slashed;
const char *q, *b;
struct tblentry **pp, *cmdp;
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
if (!isalnum(p[-1]) &&

View file

@ -75,7 +75,6 @@ char *GetHost(void) {
}
char *GetTime(void) {
int64_t t;
struct tm tm;
struct timespec ts;
clock_gettime(0, &ts);