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

@ -5,7 +5,7 @@ COSMOPOLITAN_C_START_
__funline unsigned char C121(unsigned char al, unsigned char bl,
unsigned char cl) {
unsigned short ax, bx;
unsigned short ax;
ax = al;
ax += bl;
ax += bl;

View file

@ -3,7 +3,7 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
__funline signed char C121S(signed char al, signed char bl, signed char cl) {
short ax, bx;
short ax;
ax = al;
ax += bl;
ax += bl;

View file

@ -31,13 +31,14 @@
* @param y needs to be 16-byte aligned
*/
void sad16x8n(size_t n, short x[n][8], const short y[n][8]) {
size_t i, j;
size_t i;
for (i = 0; i < n; ++i) {
#ifdef __x86_64__
*(__m128i *)x[i] = _mm_adds_epi16(*(__m128i *)x[i], *(__m128i *)y[i]);
#elif defined(__aarch64__)
*(int16x4_t *)x[i] = vqadd_s16(*(int16x4_t *)x[i], *(int16x4_t *)y[i]);
#else
size_t j;
for (j = 0; j < 8; ++j) {
x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX);
}

View file

@ -41,7 +41,7 @@ asm(".include \"libc/disclaimer.inc\"");
* @note discovered by Nasir Ahmed
*/
void plm_video_idct(int block[8][8]) {
int i, j, t1, t2, m0;
int i, t1, t2, m0;
int b1, b3, b4, b6, b7;
int y3, y4, y5, y6, y7;
int x0, x1, x2, x3, x4;

View file

@ -1105,12 +1105,12 @@ plm_video_t *plm_video_create_with_buffer(plm_buffer_t *buffer,
static textstartup void plm_video_init(void) {
PLM_VIDEO_MACROBLOCK_TYPE[0] = NULL;
PLM_VIDEO_MACROBLOCK_TYPE[1] = PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
PLM_VIDEO_MACROBLOCK_TYPE[2] = PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE,
PLM_VIDEO_MACROBLOCK_TYPE[3] = PLM_VIDEO_MACROBLOCK_TYPE_B;
PLM_VIDEO_DCT_SIZE[0] = PLM_VIDEO_DCT_SIZE_LUMINANCE;
PLM_VIDEO_DCT_SIZE[1] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
PLM_VIDEO_DCT_SIZE[2] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
PLM_VIDEO_MACROBLOCK_TYPE[1] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
PLM_VIDEO_MACROBLOCK_TYPE[2] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE;
PLM_VIDEO_MACROBLOCK_TYPE[3] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_B;
PLM_VIDEO_DCT_SIZE[0] = (void *)PLM_VIDEO_DCT_SIZE_LUMINANCE;
PLM_VIDEO_DCT_SIZE[1] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
PLM_VIDEO_DCT_SIZE[2] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
}
const void *const plm_video_init_ctor[] initarray = {plm_video_init};

View file

@ -55,10 +55,10 @@ void *cDecimate2xUint8x8(unsigned long n, unsigned char A[n],
K[4], K[5], K[4], K[5], K[4], K[5], K[4], K[5]};
signed char kMadd4[16] = {K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7],
K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7]};
unsigned char in1[16], in2[16], in3[16], in4[32];
unsigned char bv0[16], bv1[16], bv2[16], bv3[16];
unsigned char in1[16], in2[16], in3[16];
short wv0[8], wv1[8], wv2[8], wv3[8];
unsigned long i, j, v, w, o;
unsigned long i, j, w;
if (n >= STRIDE) {
i = 0;
w = (n + RATIO / 2) / RATIO;

View file

@ -82,7 +82,6 @@ static bool IsNormalized(int n, double A[n]) {
}
void FreeSamplingSolution(struct SamplingSolution *ss) {
long i;
if (ss) {
free(ss->indices);
free(ss->weights);
@ -93,7 +92,7 @@ void FreeSamplingSolution(struct SamplingSolution *ss) {
struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar,
double off, double par) {
double *fweights;
double sum, hw, w, x, f;
double sum, hw, x, f;
short *weights, *indices;
struct SamplingSolution *res;
long j, i, k, n, min, max, s, N[6];
@ -151,8 +150,8 @@ static void GyaradosImpl(long dyw, long dxw, int dst[dyw][dxw], long syw,
const short fyi[dyn][yfn], const short fyw[dyn][yfn],
const short fxi[dxn][xfn], const short fxw[dxn][xfn],
bool sharpen) {
long i, j;
int eax, dy, dx, sy, sx;
long i;
int eax, dy, dx, sx;
for (sx = 0; sx < sxn; ++sx) {
for (dy = 0; dy < dyn; ++dy) {
for (eax = i = 0; i < yfn; ++i) {

View file

@ -98,8 +98,8 @@ static int uncube(int x) {
}
static textstartup void rgb2ansi_init(void) {
uint8_t c, y;
uint32_t i, j;
uint8_t c;
uint32_t i;
memcpy(g_ansi2rgb_, &kCgaPalette, sizeof(kCgaPalette));
for (i = 16; i < 232; ++i) {
g_ansi2rgb_[i].r = kXtermCube[((i - 020) / 044) % 06];

View file

@ -609,7 +609,7 @@ static struct Pick PickBlockUnicodeAnsi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb tr2 = GetQuant(tr);
struct TtyRgb bl2 = GetQuant(bl);
struct TtyRgb br2 = GetQuant(br);
unsigned i, p1, p2;
unsigned p1, p2;
uint16_t picks1[96] forcealign(32);
uint16_t picks2[32] forcealign(32);
memset(picks1, 0x79, sizeof(picks1));
@ -646,7 +646,7 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb tr2 = GetQuant(tr);
struct TtyRgb bl2 = GetQuant(bl);
struct TtyRgb br2 = GetQuant(br);
unsigned i, p1, p2;
unsigned p1, p2;
uint16_t picks1[32] forcealign(32);
uint16_t picks2[32] forcealign(32);
memset(picks1, 0x79, sizeof(picks1));
@ -660,7 +660,6 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr,
struct TtyRgb bl, struct TtyRgb br) {
unsigned i;
uint16_t picks[32] forcealign(32);
memset(picks, 0x79, sizeof(picks));
PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br);

View file

@ -38,8 +38,8 @@
* @return 0 on success, or -1 w/ errno
*/
ssize_t ttywrite(int fd, const void *data, size_t size) {
char *p;
ssize_t rc;
const char *p;
size_t wrote, n;
p = data;
n = size;