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

@ -121,7 +121,6 @@ static void DrawSphere(double k, double ambient) {
int main() {
double ang;
struct termios old;
WRITE("\e[?25l");
if (!setjmp(jb_)) {
signal(SIGINT, OnCtrlC);

View file

@ -497,8 +497,9 @@ static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn,
CHECK_NE(-1, pipe2(pipefds, O_CLOEXEC));
if (!(pid = vfork())) {
dup2(pipefds[1], 1);
execv(convert, (char *const[]){"convert", path, "-resize", dim, "-depth",
"8", "-colorspace", "sRGB", "rgb:-", NULL});
execv(convert,
(char *const[]){"convert", (char *)path, "-resize", dim, "-depth",
"8", "-colorspace", "sRGB", "rgb:-", NULL});
abort();
}
CHECK_NE(-1, close(pipefds[1]));
@ -510,8 +511,7 @@ static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn,
static void LoadFile(const char *path, size_t yn, size_t xn, void *rgb) {
struct stat st;
size_t data2size, data3size;
void *map, *data, *data2, *data3;
void *map, *data;
int fd, gotx, goty, channels_in_file;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));
@ -585,7 +585,6 @@ int main(int argc, char *argv[]) {
int i;
void *rgb;
size_t size;
char *option;
unsigned yd, xd;
ShowCrashReports();
GetOpts(argc, argv);

View file

@ -63,12 +63,11 @@ int main(int argc, char *argv[]) {
float scale;
void *bitmap;
size_t ttfsize;
const char *dir;
unsigned char *ttf;
stbtt_fontinfo font;
unsigned char *present;
unsigned char *intotal;
int w, h, i, j, c, arg, opt, errs, line, count, maxcode, s = 40 * 4, rc = 0;
int w, h, i, c, arg, opt, errs, line, s = 40 * 4, rc = 0;
ShowCrashReports();
tcgetwinsize(0, &ws);
while ((opt = getopt(argc, argv, "vs:e:")) != -1) {
@ -103,7 +102,7 @@ int main(int argc, char *argv[]) {
continue;
}
bzero(present, m);
for (maxcode = errs = 0, c = start; c <= end; ++c) {
for (errs = 0, c = start; c <= end; ++c) {
if (!(line = setjmp(stbtt_jmpbuf))) {
if ((i = stbtt_FindGlyphIndex(&font, c)) > 0) {
w = h = 0;
@ -111,7 +110,6 @@ int main(int argc, char *argv[]) {
bitmap = stbtt_GetGlyphBitmap(&font, 0, scale, i, &w, &h, 0, 0);
if (w && h) {
intotal[c - start] = present[c - start] = 255;
maxcode = c;
}
free(bitmap);
}

View file

@ -104,7 +104,6 @@ int main(int argc, char *argv[]) {
char **rasters;
char **fasters;
size_t ttfsize;
const char *dir;
bool isdifferent;
unsigned char **ttf;
stbtt_fontinfo *font;

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/viz/lib/bilinearscale.h"
#include "dsp/core/twixt8.h"
#include "libc/intrin/bsr.h"
#include "libc/log/check.h"
@ -29,7 +30,6 @@
#include "libc/testlib/testlib.h"
#include "libc/tinymath/emod.h"
#include "libc/x/x.h"
#include "tool/viz/lib/bilinearscale.h"
static void ComputeScalingSolution(long dn, long sn, double r, double o,
unsigned char pct[dn + 1], int idx[dn + 1]) {
@ -52,7 +52,7 @@ static void BilinearScaler(long dcw, long dyw, long dxw,
int iy[dyn + 1], unsigned char py[dyn + 1],
int ix[dxn + 1], unsigned char px[dxn + 1],
unsigned char db[dxn], unsigned char sb[2][sxn]) {
long c, y, x, b;
long c, y, x;
ComputeScalingSolution(dxn, sxn, rx, ox, px, ix);
ComputeScalingSolution(dyn, syn, ry, oy, py, iy);
for (c = c0; c < cn; ++c) {

View file

@ -90,15 +90,14 @@ static void SerpentineDither(long yw, long xw, unsigned char rgb[3][yw][xw],
long yn, long xn, long y, long x, long r,
const struct Dither *d) {
void *c;
long b, e, i, j, n, m;
e = 0;
long b, i, j, n, m;
b = d->chunks[r].b;
c = d->chunks[r].c;
n = (yn - y) / b;
m = (xn - x) / b;
for (i = 0; i < n; ++i) {
for (j = 0; j < m; ++j) {
e = SerpentineDitherSq2(yw, xw, rgb, y + i * b, x + j * b, b, c, 0);
SerpentineDitherSq2(yw, xw, rgb, y + i * b, x + j * b, b, c, 0);
}
}
if (r) {

View file

@ -20,8 +20,8 @@
#include "libc/fmt/conv.h"
#include "libc/log/check.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/x/x.h"
#include "third_party/gdtoa/gdtoa.h"
#include "tool/viz/lib/formatstringtable.h"
@ -30,14 +30,13 @@
void *ConvertMatrixToStringTable(long yn, long xn, char *T[yn][xn],
const double M[yn][xn], double digs,
double rounder(double)) {
double f;
long y, x;
assert(yn && xn && !T[0][0]);
for (y = 0; y < yn; ++y) {
for (x = 0; x < xn; ++x) {
T[y][x] = xmalloc(40);
T[y][x][0] = '\0';
g_dfmt_p(T[y][x], &M[y][x], digs, 40, 0);
g_dfmt_p(T[y][x], (void *)&M[y][x], digs, 40, 0);
}
}
return T;

View file

@ -237,7 +237,7 @@ void YCbCr2Rgb(long yn, long xn, unsigned char RGB[restrict 3][yn][xn],
const unsigned char Cr[restrict cys][cxs], const int K[8][4],
const int L[6][4], const unsigned char T[256]) {
long i, j;
short y, u, v, r, g, b, A, B, C;
short y, u, v, r, g, b;
for (i = 0; i < yn; ++i) {
for (j = 0; j < xn; ++j) {
y = T[Y[i][j]];
@ -280,8 +280,8 @@ void YCbCr2RgbScaler(struct YCbCr *me, long dyn, long dxn,
long cyn, long cxn, double syn, double sxn, double pry,
double prx) {
long double ts;
long y, x, scyn, scxn;
double yry, yrx, cry, crx, yoy, yox, coy, cox, err, oy;
long scyn, scxn;
double yry, yrx, cry, crx, yoy, yox, coy, cox;
scyn = syn * cyn / yyn;
scxn = sxn * cxn / yxn;
if (HALF(yxn) > dxn && HALF(scxn) > dxn) {

View file

@ -572,7 +572,7 @@ static int GetChar(FILE *f) {
static int LoadFile(const char *path) {
FILE *f;
long c, y, x, i, j, n, yn, xn, yo, xo;
long c, y, x, i, n, yn, xn, yo, xo;
line = 0;
f = fopen(path, "r");
if (GetChar(f) != 'x') goto ReadError;
@ -1295,7 +1295,7 @@ static void OnWindowRbuttonup(int64_t hwnd, int64_t wParam, int64_t lParam) {
}
static void OnWindowMousemove(int64_t hwnd, int64_t wParam, int64_t lParam) {
int y, x, by, bx;
int y, x;
y = (lParam & 0xFFFF0000) >> 020;
x = (lParam & 0x0000FFFF) >> 000;
if (wParam & kNtMkLbutton) {

View file

@ -261,7 +261,6 @@ static void SetExtent(long lo, long hi) {
}
static void Open(void) {
int err;
if ((fd = open(path, O_RDONLY)) == -1) {
FailPath("open() failed", errno);
}

View file

@ -320,7 +320,7 @@ static void ProcessImage(long yn, long xn, unsigned char RGB[3][yn][xn]) {
void WithImageFile(const char *path,
void fn(long yn, long xn, unsigned char RGB[3][yn][xn])) {
struct stat st;
void *map, *data, *data2;
void *map, *data;
int fd, yn, xn, cn, dyn, dxn, syn, sxn;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));

View file

@ -178,8 +178,8 @@ static void GetOpts(int *argc, char *argv[]) {
g_winsize.ws_col = 80;
g_winsize.ws_row = 24;
if (!g_flags.full && (!g_flags.width || !g_flags.height)) {
tcgetwinsize(STDIN_FILENO, &g_winsize) != -1 ||
tcgetwinsize(STDOUT_FILENO, &g_winsize);
(void)(tcgetwinsize(STDIN_FILENO, &g_winsize) != -1 ||
tcgetwinsize(STDOUT_FILENO, &g_winsize));
}
ttyquantsetup(g_flags.quant, kTtyQuantRgb, g_flags.blocks);
}
@ -220,11 +220,10 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn],
long y0, long yn, long x0, long xn, long dy,
long dx) {
long y, x;
bool didhalfy, didfirstx;
bool didhalfy;
unsigned char a[3], b[3];
didhalfy = false;
for (y = y0; y < yn; y += dy) {
didfirstx = false;
if (y) printf("\e[0m\n");
for (x = x0; x < xn; x += dx) {
a[0] = RGB[0][y][x];
@ -239,7 +238,6 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn],
}
printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm%lc", a[0], a[1], a[2], b[0], b[1],
b[2], dy > 1 ? u'' : u'');
didfirstx = true;
}
printf("\e[0m");
if (g_flags.ruler) {
@ -363,7 +361,7 @@ static void ProcessImage(long yn, long xn, unsigned char RGB[3][yn][xn]) {
void WithImageFile(const char *path,
void fn(long yn, long xn, unsigned char RGB[3][yn][xn])) {
struct stat st;
void *map, *data, *data2;
void *map, *data;
int fd, yn, xn, cn, dyn, dxn, syn, sxn, wyn, wxn;
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
CHECK_NE(-1, fstat(fd, &st));

View file

@ -43,7 +43,7 @@
#include "tool/decode/lib/idname.h"
#if defined(__x86_64__) && SupportsWindows()
char *GetString(struct NtUnicodeString *s) {
char *GetString(const struct NtUnicodeString *s) {
static char buf[1024];
unsigned len = min(sizeof(buf) - 1, s->Length);
for (unsigned i = 0; i < len; ++i) {

View file

@ -278,15 +278,15 @@ static uint64_t t1, t2, t3, t4, t5, t6, t8;
static const char *sox_, *ffplay_, *patharg_;
static struct VtFrame vtframe_[2], *f1_, *f2_;
static struct Graphic graphic_[2], *g1_, *g2_;
static long double deadline_, dura_, starttime_;
static bool yes_, stats_, dither_, ttymode_, istango_;
static long double deadline_, dura_, skip_, starttime_;
static long double decode_start_, f1_start_, f2_start_;
static int16_t pcm_[PLM_AUDIO_SAMPLES_PER_FRAME * 2 / 8][8];
static int16_t pcmscale_[PLM_AUDIO_SAMPLES_PER_FRAME * 2 / 8][8];
static bool fullclear_, historyclear_, tuned_, yonly_, gotvideo_;
static int homerow_, lastrow_, playfd_, infd_, outfd_, nullfd_, speakerfails_;
static char host_[DNS_NAME_MAX + 1], status_[7][200], logpath_[PATH_MAX],
fifopath_[PATH_MAX], chansstr_[32], sratestr_[32], port_[32];
static int homerow_, lastrow_, playfd_, infd_, outfd_, speakerfails_;
static char status_[7][200], logpath_[PATH_MAX], fifopath_[PATH_MAX],
chansstr_[32], sratestr_[32];
static void OnCtrlC(void) {
longjmp(jb_, 1);
@ -324,7 +324,7 @@ static int GetNamedVector(const struct NamedVector *choices, size_t n,
const char *s) {
int i;
char name[sizeof(choices->name)];
strncpy(name, s, sizeof(name));
strlcpy(name, s, sizeof(name));
strntoupper(name, sizeof(name));
for (i = 0; i < n; ++i) {
if (memcmp(choices[i].name, name, sizeof(name)) == 0) {