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

@ -52,7 +52,7 @@
*/
char *DescribeSyn(char *q, size_t m, const char *p, size_t n) {
char *e;
int i, j, k, r, iplen, tcplen, ttl, wsize, mss;
int i, j, k, iplen, tcplen, ttl, wsize, mss;
if (n >= 20 + 20 && n >= (iplen = (p[0] & 0x0F) * 4) + 20 &&
n >= iplen + (tcplen = ((p[iplen + 12] & 0xF0) >> 4) * 4)) {
e = q + m;

View file

@ -27,7 +27,7 @@
*/
uint32_t FingerSyn(const char *p, size_t n) {
uint32_t h = 0;
int i, j, k, q, r, iplen, tcplen, ttl;
int i, j, k, iplen, tcplen, ttl;
if (n >= 20 + 20 && n >= (iplen = (p[0] & 0x0F) * 4) + 20 &&
n >= iplen + (tcplen = ((p[iplen + 12] & 0xF0) >> 4) * 4)) {
n = iplen + tcplen;

View file

@ -53,7 +53,7 @@ char *DecodeLatin1(const char *p, size_t n, size_t *z) {
*q++ = c;
} else {
*q++ = 0300 | c >> 6;
*q++ = 0200 | c & 077;
*q++ = 0200 | (c & 077);
}
}
if (z) *z = q - r;

View file

@ -51,7 +51,7 @@ char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) {
c = p[i++] & 0xff;
if (c >= 0300) {
if ((c <= 0303) && i < n && (p[i] & 0300) == 0200) {
c = (c & 037) << 6 | p[i++] & 077;
c = (c & 037) << 6 | (p[i++] & 077);
} else {
goto Invalid;
}

View file

@ -45,7 +45,7 @@ char *EscapeUrl(const char *p, size_t n, size_t *z, const char T[256]) {
if (n == -1) n = p ? strlen(p) : 0;
if (z) *z = 0;
if ((q = r = malloc(n * 6 + 1))) {
v.p = p, v.n = n;
v.p = (char *)p, v.n = n;
q = EscapeUrlView(r, &v, T);
if (z) *z = q - r;
*q++ = '\0';

View file

@ -24,7 +24,7 @@
/**
* Collapses repeating headers onto a single line.
*/
char *FoldHeader(struct HttpMessage *msg, char *b, int h, size_t *z) {
char *FoldHeader(struct HttpMessage *msg, const char *b, int h, size_t *z) {
char *p, *p2;
size_t i, n, m;
struct HttpHeader *x;

View file

@ -214,7 +214,7 @@ bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, char *, int, size_t *);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -33,7 +33,7 @@
char *IndentLines(const char *p, size_t n, size_t *z, size_t j) {
char *r, *q;
const char *l;
size_t i, t, m, a;
size_t t, m, a;
if (n == -1) n = p ? strlen(p) : 0;
r = 0;
t = 0;

View file

@ -39,7 +39,7 @@ static const char kNoCompressExts[][8] = {
};
static bool BisectNoCompressExts(uint64_t ext) {
int c, m, l, r;
int m, l, r;
l = 0;
r = ARRAYLEN(kNoCompressExts) - 1;
while (l <= r) {

View file

@ -17,8 +17,8 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/time/time.h"
#include "libc/str/str.h"
#include "libc/time/time.h"
#include "net/http/http.h"
static unsigned ParseMonth(const char *p) {
@ -41,7 +41,7 @@ static unsigned ParseMonth(const char *p) {
* @see FormatHttpDateTime()
*/
int64_t ParseHttpDateTime(const char *p, size_t n) {
unsigned weekday, year, month, day, hour, minute, second, yday, leap;
unsigned year, month, day, hour, minute, second, yday, leap;
if (n == -1) n = p ? strlen(p) : 0;
if (n != 29) return 0;
day = (p[5] - '0') * 10 + (p[6] - '0') - 1;

View file

@ -33,7 +33,7 @@ struct UrlParser {
static void EmitLatin1(char **p, int c) {
(*p)[0] = 0300 | c >> 6;
(*p)[1] = 0200 | c & 077;
(*p)[1] = 0200 | (c & 077);
*p += 2;
}
@ -149,7 +149,7 @@ static void ParseAuthority(struct UrlParser *u, struct Url *h) {
if (c) {
h->user.p = u->q;
h->user.n = c - 1 - u->q;
h->pass.p = c;
h->pass.p = (char *)c;
h->pass.n = u->p - c;
c = NULL;
t = 1;
@ -169,7 +169,7 @@ static void ParseAuthority(struct UrlParser *u, struct Url *h) {
if (t == 2) {
h->host.p = u->q;
h->host.n = c - 1 - u->q;
h->port.p = c;
h->port.p = (char *)c;
h->port.n = u->p - c;
c = NULL;
} else {

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/atomic.h"
#include "net/http/tokenbucket.h"
#include "libc/intrin/atomic.h"
/**
* Atomically increments all signed bytes in array, without overflowing.
@ -40,7 +40,7 @@ void ReplenishTokens(atomic_uint_fast64_t *w, size_t n) {
if (a == 0x7f7f7f7f7f7f7f7f) continue;
uint64_t b = 0x8080808080808080;
uint64_t c = 0x7f7f7f7f7f7f7f7f ^ a;
uint64_t d = ((c >> 1 | b) - c & b ^ b) >> 7;
uint64_t d = ((((c >> 1 | b) - c) & b) ^ b) >> 7;
atomic_fetch_add_explicit(w + i, d, memory_order_relaxed);
}
}

View file

@ -19,7 +19,7 @@
#include "libc/log/check.h"
#include "net/https/https.h"
char *FormatX509Name(mbedtls_x509_name *name) {
char *FormatX509Name(const mbedtls_x509_name *name) {
char *s = calloc(1, 1000);
CHECK_GT(mbedtls_x509_dn_gets(s, 1000, name), 0);
return s;

View file

@ -24,7 +24,7 @@ void FormatSslTime(char[restrict hasatleast 16], struct tm *);
void ChooseCertificateLifetime(char[16], char[16]);
void LogCertificate(const char *, mbedtls_x509_crt *);
bool IsSelfSigned(mbedtls_x509_crt *);
char *FormatX509Name(mbedtls_x509_name *);
char *FormatX509Name(const mbedtls_x509_name *);
void TlsDie(const char *, int) wontreturn;
bool ChainCertificate(mbedtls_x509_crt *, mbedtls_x509_crt *);
bool CertHasIp(const mbedtls_x509_crt *, uint32_t);

View file

@ -22,9 +22,7 @@
mbedtls_pk_context *InitializeKey(struct Cert *ca,
mbedtls_x509write_cert *wcert,
mbedtls_md_type_t md_alg, int type) {
mbedtls_pk_context *k;
mbedtls_ctr_drbg_context kr;
k = calloc(1, sizeof(mbedtls_pk_context));
mbedtls_pk_context *k = calloc(1, sizeof(mbedtls_pk_context));
mbedtls_x509write_crt_init(wcert);
mbedtls_x509write_crt_set_issuer_key(wcert, ca ? ca->key : k);
mbedtls_x509write_crt_set_subject_key(wcert, k);

View file

@ -22,7 +22,7 @@
#include "third_party/mbedtls/ctr_drbg.h"
void InitializeRng(mbedtls_ctr_drbg_context *r) {
volatile unsigned char b[64];
unsigned char b[64];
mbedtls_ctr_drbg_init(r);
CHECK(getrandom(b, 64, 0) == 64);
CHECK(!mbedtls_ctr_drbg_seed(r, GetEntropy, 0, b, 64));

View file

@ -40,7 +40,7 @@
#define PROT (PROT_READ | PROT_WRITE)
#define FLAGS MAP_SHARED
static uint32_t HashSslSession(mbedtls_ssl_session *session) {
static uint32_t HashSslSession(const mbedtls_ssl_session *session) {
int i;
uint32_t h;
h = session->ciphersuite;

View file

@ -214,7 +214,7 @@ void GetOpts(int argc, char *argv[]) {
}
void OnTerm(int sig) {
char tmp[15];
char tmp[21];
LOG("got %s", strsignal_r(sig, tmp));
g_shutdown = sig;
}
@ -231,12 +231,12 @@ void BlockIp(uint32_t ip) {
if (g_iptables) {
execve(g_iptables,
(char *const[]){
"iptables", //
"-t", "raw", //
"-I", g_chain, //
"-s", FormatIp(ip), //
"-j", "DROP", //
0, //
"iptables", //
"-t", "raw", //
"-I", (char *)g_chain, //
"-s", FormatIp(ip), //
"-j", "DROP", //
0, //
},
(char *const[]){0});
} else if (g_pfctl) {

View file

@ -629,7 +629,7 @@ int GetClaims(struct Claims *q, struct Claim *out, int len) {
// parses request uri query string and extracts ?name=value
static bool GetNick(char *inbuf, struct HttpMessage *msg, struct Claim *v) {
size_t i, n;
size_t i;
struct Url url;
void *f[2] = {0};
bool found = false;
@ -826,7 +826,6 @@ void *HttpWorker(void *arg) {
// connection loop
while (GetClient(&g_clients, &client)) {
struct Data d;
struct Url url;
ssize_t got, sent;
uint32_t ip, clientip;
int tok, inmsglen, outmsglen;
@ -1890,7 +1889,6 @@ void *Supervisor(void *arg) {
}
void CheckDatabase(void) {
int rc;
sqlite3 *db;
if (g_integrity) {
CHECK_SQL(DbOpen("db.sqlite3", &db));