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

@ -33,7 +33,6 @@ static bool IsSymbolChar2(char c) {
}
static bool IsSymbolString(const char *s) {
int i;
if (!IsSymbolChar1(*s++)) return false;
while (*s) {
if (!IsSymbolChar2(*s++)) return false;
@ -54,7 +53,8 @@ static bool IsSymbolString(const char *s) {
*/
struct Asmdown *ParseAsmdown(const char *code, size_t size) {
struct Asmdown *ad;
char *p1, *p2, *p3, *symbol, *alias;
const char *p1;
char *p2, *p3, *symbol, *alias;
enum { BOL, COM, SYM, OTHER } state;
int i, j, line, start_line, start_docstring, end_docstring, start_symbol;
ad = calloc(1, sizeof(struct Asmdown));

View file

@ -27,7 +27,7 @@
/* TODO(jart): replace with new append*() library */
void AppendData(struct Buffer *b, char *data, unsigned len) {
void AppendData(struct Buffer *b, const char *data, size_t len) {
char *p;
unsigned n;
if (b->i + len + 1 > b->n) {
@ -63,7 +63,6 @@ void AppendWide(struct Buffer *b, wint_t wc) {
int AppendFmt(struct Buffer *b, const char *fmt, ...) {
int n;
char *p;
va_list va, vb;
va_start(va, fmt);
va_copy(vb, va);

View file

@ -9,7 +9,7 @@ struct Buffer {
};
void AppendChar(struct Buffer *, char);
void AppendData(struct Buffer *, char *, unsigned);
void AppendData(struct Buffer *, const char *, size_t);
void AppendStr(struct Buffer *, const char *);
void AppendWide(struct Buffer *, wint_t);
int AppendFmt(struct Buffer *, const char *, ...);

View file

@ -47,7 +47,7 @@ void SpawnCxxFilt(void) {
if (!(g_cxxfilt.pid = vfork())) {
dup2(pipefds[1][0], 0);
dup2(pipefds[0][1], 1);
execv(path, (char *const[]){cxxfilt, NULL});
execv(path, (char *const[]){(char *)cxxfilt, 0});
abort();
}
g_cxxfilt.reader = pipefds[0][0];
@ -87,7 +87,7 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) {
if (!g_cxxfilt.pid) SpawnCxxFilt();
if (g_cxxfilt.pid == -1) return NULL;
buf[0] = '\n';
iov[0].iov_base = s;
iov[0].iov_base = (void *)s;
iov[0].iov_len = sn;
iov[1].iov_base = buf;
iov[1].iov_len = 1;

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/eztls.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/errno.h"
@ -27,7 +28,6 @@
#include "net/https/https.h"
#include "third_party/mbedtls/net_sockets.h"
#include "third_party/mbedtls/ssl.h"
#include "tool/build/lib/eztls.h"
struct EzTlsBio ezbio;
mbedtls_ssl_config ezconf;
@ -72,7 +72,7 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) {
if (len || bio->c > 0) {
v[0].iov_base = bio->u;
v[0].iov_len = MAX(0, bio->c);
v[1].iov_base = buf;
v[1].iov_base = (void *)buf;
v[1].iov_len = len;
if (EzWritevAll(bio->fd, v, 2) != -1) {
if (bio->c > 0) bio->c = 0;
@ -90,7 +90,6 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) {
static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) {
int rc;
struct iovec v[2];
struct EzTlsBio *bio = ctx;
if (bio->c >= 0 && bio->c + len <= sizeof(bio->u)) {
memcpy(bio->u + bio->c, buf, len);
@ -103,7 +102,6 @@ static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) {
static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) {
int r;
ssize_t s;
struct iovec v[2];
struct EzTlsBio *bio = ctx;
if ((r = EzTlsFlush(bio, 0, 0)) < 0) return r;

View file

@ -117,7 +117,6 @@ const char *getargs_next(struct GetArgs *ga) {
int fd;
char *p;
size_t k;
unsigned m;
ssize_t size;
for (;;) {
if (ga->map) {
@ -128,6 +127,7 @@ const char *getargs_next(struct GetArgs *ga) {
}
k = 0;
#if defined(__SSE2__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
unsigned m;
typedef unsigned char xmm_t
__attribute__((__vector_size__(16), __aligned__(1)));
for (; ga->j + k + 16 <= ga->mapsize; k += 16) {

View file

@ -94,8 +94,8 @@ size_t interncount(const struct Interner *t) {
size_t internobj(struct Interner *t, const void *data, size_t size) {
char *p2;
size_t n2;
char *item;
unsigned hash;
const char *item;
struct InternerObject *it;
size_t i, off, step, need, bytes;
step = 0;

View file

@ -120,7 +120,6 @@ static void SplitLines(struct Lines *lines, char *p) {
}
static bool ConsumeFileOverview(struct Lines *lines) {
int i;
if (lines->n && lines->p[0].n >= strlen(FILEOVERVIEW) &&
startswith(lines->p[0].p, FILEOVERVIEW)) {
lines->p[0].p += strlen(FILEOVERVIEW);
@ -192,10 +191,9 @@ static int ExtractText(struct Javadown *jd, struct Lines *lines, int i) {
}
static void ExtractTags(struct Javadown *jd, struct Lines *lines, int i) {
size_t n;
char *p, *tag, *text, *p2;
char *tag, *text, *p2;
unsigned taglen, textlen, n2;
for (p = NULL, n = 0; i < lines->n; ++i) {
for (; i < lines->n; ++i) {
if (!lines->p[i].n) continue;
if (lines->p[i].p[0] != '@') continue;
tag = lines->p[i].p + 1;

View file

@ -65,7 +65,6 @@ static int tpdecode(const char *s, wint_t *out) {
ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
wint_t wc;
ssize_t rc;
size_t wrote;
struct Buffer b, *l;
int x, y, i, j, width;
enum { kUtf8, kAnsi, kAnsiCsi } state;