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

@ -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);
}
}