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

@ -55,7 +55,7 @@ void FreeZipArgs(void) {
}
int LoadZipArgsImpl(int *argc, char ***argv, char *data) {
int i, n, fd;
int i, n;
bool founddots;
char *arg, **args, *state, *start;
assert(!g_zipargs.loaded);

View file

@ -861,8 +861,6 @@ void FixupPeImage(char *map, size_t size, //
Elf64_Sxword off_skew) {
assert(!(rva_skew & 65535));
Elf64_Sxword skew = rva_skew;
// fixup pe header
if (ckd_sub(&pe->OptionalHeader.ImageBase, //
pe->OptionalHeader.ImageBase, rva_skew))
@ -972,7 +970,6 @@ static void AddLoader(const char *path) {
}
static void GetOpts(int argc, char *argv[]) {
char *endptr;
int opt, bits;
bool got_support_vector = false;
while ((opt = getopt(argc, argv, "hvgsGBo:l:S:M:V:")) != -1) {
@ -1282,7 +1279,7 @@ static char *GenerateMachoSegment(char *p, struct Input *in, Elf64_Phdr *phdr) {
load = (struct MachoLoadSegment *)p;
load->command = MAC_LC_SEGMENT_64;
load->size = sizeof(*load);
FormatInt32(stpcpy(load->name, "__APE"), macholoadcount);
FormatInt32(__veil("r", stpcpy(load->name, "__APE")), macholoadcount);
++macholoadcount;
load->vaddr = phdr->p_vaddr;
load->memsz = phdr->p_memsz;
@ -1482,9 +1479,7 @@ static char *SecondPass2(char *p, struct Input *in) {
// focusing on embedding the executable files passed via the flags.
static Elf64_Off ThirdPass(Elf64_Off offset, struct Input *in) {
int i;
char *data;
Elf64_Addr vaddr;
Elf64_Phdr *phdr;
Elf64_Xword image_align;
// determine microprocessor page size
@ -1814,9 +1809,8 @@ static void CopyZips(Elf64_Off offset) {
int main(int argc, char *argv[]) {
char *p;
int i, j, opt;
int i, j;
Elf64_Off offset;
char empty[64] = {0};
Elf64_Xword prologue_bytes;
#ifndef NDEBUG
ShowCrashReports();

View file

@ -318,7 +318,7 @@ int main(int argc, char *argv[]) {
if (argc < 3) {
ShowUsage(1, 2);
}
const char *flags = argv[1];
char *flags = argv[1];
const char *outpath = argv[2];
// we only support one mode of operation, which is creating a new

View file

@ -22,6 +22,7 @@
#include "libc/dce.h"
#include "libc/elf/def.h"
#include "libc/elf/struct/ehdr.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/bits.h"
#include "libc/limits.h"
@ -36,7 +37,6 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "third_party/getopt/getopt.internal.h"
#include "libc/errno.h"
#include "third_party/regex/regex.h"
#define VERSION \
@ -194,7 +194,7 @@ static int GetElfArch(void) {
static void GetElfHeader(Elf64_Ehdr *ehdr, const char *image, size_t n) {
int c, i;
char *p, *e;
const char *p, *e;
for (p = image, e = p + MIN(n, 8192); p < e; ++p) {
TryAgain:
if (READ64LE(p) != READ64LE("printf '")) continue;
@ -383,7 +383,7 @@ static int GetMode(int fd) {
}
static void CopyFile(int infd, const char *map, size_t size, //
void *hdr, size_t hdrsize) {
const void *hdr, size_t hdrsize) {
int outfd;
if (!outpath) return;
if ((outfd = creat(outpath, GetMode(infd))) == -1) DieSys(outpath);
@ -393,7 +393,7 @@ static void CopyFile(int infd, const char *map, size_t size, //
}
static void WriteOutput(int infd, const char *map, size_t size, //
void *hdr, size_t hdrsize) {
const void *hdr, size_t hdrsize) {
int outfd, oflags, omode;
if (outpath) {
CopyFile(infd, map, size, hdr, hdrsize);

View file

@ -31,10 +31,8 @@
void PrintMultiplyKernel(int n, int m) {
bool cf, of;
uint128_t x;
bool *Rs, *Ra;
int j, i, k1, k2, g;
uint64_t *R, *H;
printf("\
/**\n\
* Computes %d-bit product of %d-bit and %d-bit numbers.\n\
@ -67,7 +65,7 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) {
(printf)("\
asm(\"xorl\\t%%k0,%%k0\" : \"=r\"(z), \"+m\"(cf), \"+m\"(of));\n",
j);
for (cf = of = i = 0; i < n; ++i) {
for (cf = of = false, i = 0; i < n; ++i) {
if (!i) {
if (!Rs[i + j] && !Rs[i + j + 1]) {
assert(!cf);

View file

@ -58,7 +58,7 @@ static void GetOpts(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
int i, mode;
char buf[PATH_MAX], *endptr;
char *endptr;
prog = argv[0];
if (!prog) prog = "chmod";
GetOpts(argc, argv);

View file

@ -313,7 +313,6 @@ void PrintReset(void) {
}
void PrintMakeCommand(void) {
const char *s;
appends(&output, "make MODE=");
appends(&output, mode);
appends(&output, " -j");
@ -476,14 +475,15 @@ void AddArg(char *actual) {
}
appends(&command, s);
if (!args.n) {
appends(&shortened, StripPrefix(basename(s), "x86_64-linux-musl-"));
appends(&shortened,
StripPrefix(basename(gc(strdup(s))), "x86_64-linux-musl-"));
} else if (*s != '-') {
appendw(&shortened, ' ');
if ((isar || isbfd || ispkg) &&
(strcmp(args.p[args.n - 1], "-o") &&
(endswith(s, ".o") || endswith(s, ".pkg") ||
(endswith(s, ".a") && !isar)))) {
appends(&shortened, basename(s));
appends(&shortened, basename(gc(strdup(s))));
} else {
appends(&shortened, s);
}
@ -511,11 +511,11 @@ static int GetBaseCpuFreqMhz(void) {
}
void SetCpuLimit(int secs) {
int mhz, lim;
struct rlimit rlim;
if (secs <= 0) return;
if (IsWindows()) return;
#ifdef __x86_64__
int mhz, lim;
struct rlimit rlim;
if (!(mhz = GetBaseCpuFreqMhz())) return;
lim = ceil(3100. / mhz * secs);
rlim.rlim_cur = lim;
@ -851,13 +851,12 @@ char *MakeTmpOut(const char *path) {
}
int main(int argc, char *argv[]) {
int columns;
uint64_t us;
bool isineditor;
size_t i, j, n, m;
bool isproblematic;
char *s, *q, **envp;
int ws, opt, exitcode;
char *s, *p, *q, **envp;
#ifndef NDEBUG
ShowCrashReports();
@ -1070,7 +1069,7 @@ int main(int argc, char *argv[]) {
#ifdef __x86_64__
} else if (!strcmp(argv[i], "-march=native")) {
struct X86ProcessorModel *model;
const struct X86ProcessorModel *model;
if (X86_HAVE(XOP)) AddArg("-mxop");
if (X86_HAVE(SSE4A)) AddArg("-msse4a");
if (X86_HAVE(SSE3)) AddArg("-msse3");

View file

@ -35,7 +35,7 @@ __attribute__((__constructor__)) void init(void) {
for (i = j = 0; i < 2; ++i) {
while ((c = s[j] & 255)) {
++j;
if ('0' <= c & c <= '9') {
if ('0' <= c && c <= '9') {
arg[i] *= 10;
arg[i] += c - '0';
} else {

View file

@ -49,6 +49,8 @@
// see tool/hello/hello-pe.c for an example program this can link
// make -j8 m=tiny o/tiny/tool/hello/hello-pe.com
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#define VERSION \
"elf2pe v0.1\n" \
"copyright 2023 justine tunney\n" \
@ -273,7 +275,6 @@ static void RelocateRela(struct Elf *elf, struct Segment *segment,
RelocateVaddrWithinSegment(elf, rela->r_offset, segment);
Elf64_Addr symbol_vaddr = elf->symtab[ELF64_R_SYM(rela->r_info)].st_value;
char *place_ptr = segment->ptr_new + (place_vaddr - segment->vaddr_new_min);
Elf64_Sxword addend = rela->r_addend;
switch (ELF64_R_TYPE(rela->r_info)) {
case R_X86_64_NONE: // do nothing
case R_X86_64_COPY: // do nothing
@ -1032,7 +1033,6 @@ static struct ImagePointer GeneratePe(struct Elf *elf, char *fp, int64_t vp) {
static void GetOpts(int argc, char *argv[]) {
int opt;
char *endptr;
while ((opt = getopt(argc, argv, "ho:D:")) != -1) {
switch (opt) {
case 'o':

View file

@ -35,7 +35,6 @@ int main(int argc, char *argv[]) {
int line;
char *l1, *l2;
FILE *f1, *f2;
int differences;
if (argc < 3) {
fprintf(stderr, "usage: %s FILE1 FILE2\n", argv[0]);
exit(1);
@ -48,7 +47,7 @@ int main(int argc, char *argv[]) {
perror(argv[2]);
exit(1);
}
for (differences = 0, line = 1;; ++line) {
for (line = 1;; ++line) {
l1 = fgets(line1, sizeof(line1), f1);
l2 = fgets(line2, sizeof(line2), f2);
if (!l1 && !l2) {

View file

@ -51,7 +51,7 @@
#define MRS_TPIDR_EL0 0xd53bd040u
#define MOV_REG(DST, SRC) (0xaa0003e0u | (SRC) << 16 | (DST))
static const unsigned char kFatNops[8][8] = {
const unsigned char kFatNops[8][8] = {
{}, //
{0x90}, // nop
{0x66, 0x90}, // xchg %ax,%ax
@ -68,9 +68,9 @@ static char *symstrs;
static char *secstrs;
static ssize_t esize;
static Elf64_Sym *syms;
static Elf64_Ehdr *elf;
static const char *epath;
static Elf64_Xword symcount;
static const Elf64_Ehdr *elf;
static wontreturn void Die(const char *reason) {
tinyprint(2, epath, ": ", reason, "\n", NULL);
@ -139,11 +139,10 @@ static void GetOpts(int argc, char *argv[]) {
}
static void CheckPrivilegedCrossReferences(void) {
long i;
unsigned long x;
Elf64_Shdr *shdr;
const char *secname;
Elf64_Rela *rela, *erela;
const Elf64_Shdr *shdr;
const Elf64_Rela *rela, *erela;
shdr = FindElfSectionByName(elf, esize, secstrs, ".rela.privileged");
if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr))) return;
erela = rela + shdr->sh_size / sizeof(*rela);
@ -170,7 +169,7 @@ static void CheckPrivilegedCrossReferences(void) {
// Modify ARM64 code to use x28 for TLS rather than tpidr_el0.
static void RewriteTlsCode(void) {
int i, dest;
int i;
Elf64_Shdr *shdr;
uint32_t *p, *pe;
for (i = 0; i < elf->e_shnum; ++i) {
@ -205,7 +204,6 @@ static void RewriteTlsCode(void) {
static void OptimizePatchableFunctionEntries(void) {
#ifdef __x86_64__
long i, n;
int nopcount;
Elf64_Shdr *shdr;
unsigned char *p, *pe;
for (i = 0; i < symcount; ++i) {
@ -365,7 +363,7 @@ static void FixupObject(void) {
}
int main(int argc, char *argv[]) {
int i, opt;
int i;
if (!IsOptimized()) {
ShowCrashReports();
}

View file

@ -135,7 +135,7 @@ void GetOpts(int argc, char *argv[]) {
void Compress(const char *inpath) {
FILE *input;
gzFile output;
int rc, n, errnum;
int rc, errnum;
const char *outpath;
char *p, openflags[5];
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {

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;

View file

@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
const char *lz4path = "/dev/stdin";
const char *outpath = "/dev/stdout";
const char *initprio = "400,_init_";
const unsigned char *lz4data;
unsigned char *lz4data;
int opt;
FILE *fin, *fout;
@ -140,7 +140,7 @@ int main(int argc, char *argv[]) {
fprintf(fout, "\n");
fprintf(fout, "\t.init.start %s%s\n", initprio, symbol);
fprintf(fout, "\tpush\t%%rsi\n");
fprintf(fout, "\tmov\t$%u,%%edx\n", size);
fprintf(fout, "\tmov\t$%zu,%%edx\n", size);
fprintf(fout, "\tcall\tlz4cpy\n");
if (misalign) {
fprintf(fout, "\tlea\t%zu(%%rax),%%rdi\n", misalign);
@ -148,7 +148,7 @@ int main(int argc, char *argv[]) {
fprintf(fout, "\tmov\t%%rax,%%rdi\n");
}
fprintf(fout, "\tpop\t%%rsi\n");
fprintf(fout, "\tadd\t$%u,%%rsi\n", ROUNDUP(size, 8));
fprintf(fout, "\tadd\t$%zu,%%rsi\n", ROUNDUP(size, 8));
fprintf(fout, "\t.init.end %s%s\n", initprio, symbol);
fprintf(fout, "\n");

View file

@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
if (X86_HAVE(BMI2)) Puts("-mbmi2");
if (X86_HAVE(ADX)) Puts("-madx");
if (X86_HAVE(FXSR)) Puts("-mfxsr");
if ((model = getx86processormodel(kX86ProcessorModelKey))) {
if ((model = (void *)getx86processormodel(kX86ProcessorModelKey))) {
switch (model->march) {
case X86_MARCH_CORE2:
Puts("-march=core2");

View file

@ -206,8 +206,8 @@ static void Crunch(void) {
free(sources.p);
sources.p = 0;
sources.i = j;
if (radix_sort_int64((const long *)sauces, sources.i) == -1 ||
radix_sort_int64((const long *)edges.p, edges.i) == -1) {
if (radix_sort_int64((long *)sauces, sources.i) == -1 ||
radix_sort_int64((long *)edges.p, edges.i) == -1) {
DieOom();
}
}
@ -266,7 +266,7 @@ static void LoadRelationships(int argc, char *argv[]) {
char *map;
ssize_t rc;
struct GetArgs ga;
size_t i, n, size, inclen;
size_t n, size, inclen;
unsigned srcid, dependency;
const char *p, *pe, *src, *path, *pathend;
getargs_init(&ga, argv + optind);
@ -368,7 +368,6 @@ static bool IsObjectSource(const char *name) {
}
__funline bool Bts(uint32_t *p, size_t i) {
bool r;
uint32_t k;
k = 1u << (i & 31);
if (p[i >> 5] & k) return true;

View file

@ -158,7 +158,7 @@ char *Join(const char *a, const char *b) {
void Mv(char *src, char *dst) {
ssize_t rc;
const char *s, *d;
const char *d;
if (strlen(src) + 1 > PATH_MAX) _Exit(2);
if (strlen(dst) + 1 > PATH_MAX) _Exit(2);
basename(src);

View file

@ -325,7 +325,6 @@ static void HandleElf(const char *inpath, Elf64_Ehdr *elf, size_t esize) {
int i, loadcount;
Elf64_Off maxoff;
Elf64_Phdr *phdr;
char empty[64] = {0};
Elf64_Shdr *macho_shdr;
struct MachoHeader *macho;
struct MachoLoadCommand *loadcommand;
@ -416,7 +415,7 @@ static void HandleInput(const char *inpath) {
}
int main(int argc, char *argv[]) {
int i, opt;
int i;
prog = argv[0];
if (!prog) prog = "objbincopy";
GetOpts(argc, argv);

View file

@ -204,7 +204,7 @@ static void PrintObject(struct Package *pkg, struct Object *obj) {
}
static void PrintPackage(struct Package *pkg) {
int i, j, o;
int i;
kprintf("- %s\n", pkg->strings.p + pkg->path);
kprintf(" objects=%d\n", pkg->objects.i);
for (i = 0; i < pkg->objects.i; ++i) {
@ -224,7 +224,7 @@ static void PrintPackages(struct Package *p, int n) {
static struct Package *LoadPackage(const char *path) {
int fd;
ssize_t i, size;
ssize_t size;
struct Package *pkg;
if ((fd = open(path, O_RDONLY)) == -1) {
SysExit(path, "open");
@ -339,7 +339,7 @@ FLAGS\n\
static void GetOpts(struct Package *pkg, struct Packages *deps, int argc,
char *argv[]) {
long i, si, opt;
long opt;
const char *arg;
struct GetArgs ga;
pkg->path = -1;
@ -381,10 +381,8 @@ static void GetOpts(struct Package *pkg, struct Packages *deps, int argc,
static void IndexSections(struct Package *pkg, struct Object *obj) {
int i;
const char *name;
const uint8_t *code;
struct Section sect;
const Elf64_Shdr *shdr;
struct XedDecodedInst xedd;
obj->section_offset = pkg->sections.i;
for (i = 0; i < obj->elf->e_shnum; ++i) {
bzero(&sect, sizeof(sect));
@ -566,7 +564,7 @@ static struct Symbol *BisectSymbol(struct Package *pkg, const char *name) {
static bool FindSymbol(const char *name, struct Package *pkg,
struct Packages *directdeps, struct Package **out_pkg,
struct Symbol **out_sym) {
size_t i, j;
size_t i;
struct Symbol *sym;
if ((sym = BisectSymbol(pkg, name))) {
if (out_sym) *out_sym = sym;
@ -607,7 +605,7 @@ static void CheckStrictDeps(struct Package *pkg, struct Packages *deps) {
}
static void CheckYourPrivilege(struct Package *pkg, struct Packages *deps) {
int i, j, o, f;
int i, f;
const char *name;
struct Symbol *sym;
struct Package *dep;
@ -634,7 +632,7 @@ static bool IsSymbolDirectlyReachable(struct Package *pkg,
static void Package(int argc, char *argv[], struct Package *pkg,
struct Packages *deps) {
size_t i, j;
size_t i;
GetOpts(pkg, deps, argc, argv);
LoadObjects(pkg);
CheckStrictDeps(pkg, deps);

View file

@ -583,9 +583,7 @@ Finish:
int main(int argc, char *argv[]) {
const char *s;
bool hasfunbits;
int fdin, fdout;
char buf[PATH_MAX];
int e, zipfd, memfd;
int useruid, usergid;
int owneruid, ownergid;
int oldfsuid, oldfsgid;

View file

@ -62,7 +62,7 @@ void Process(const char *p, const char *pe, const char *path, bool isheader) {
int level;
bool noformat;
const char *p2, *dq, *name;
for (noformat = level = 0; p < pe; p = p2) {
for (noformat = false, level = 0; p < pe; p = p2) {
p2 = memchr(p, '\n', pe - p);
p2 = p2 ? p2 + 1 : pe;
if (LOOKINGAT(p, pe, "#if")) {

View file

@ -230,15 +230,12 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
bool SendRequest(int tmpfd) {
int fd;
char *p;
size_t i;
bool okall;
ssize_t rc;
uint32_t crc;
struct stat st;
const char *name;
unsigned char *hdr, *q;
size_t progsize, namesize, hdrsize;
unsigned have;
CHECK_NE(-1, (fd = open(g_prog, O_RDONLY)));
CHECK_NE(-1, fstat(fd, &st));
CHECK_NE(MAP_FAILED, (p = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
@ -302,8 +299,7 @@ bool Recv(unsigned char *p, size_t n) {
int ReadResponse(void) {
int res;
ssize_t rc;
size_t n, m;
size_t n;
uint32_t size;
unsigned char b[512];
for (res = -1; res == -1;) {
@ -378,7 +374,7 @@ bool ShouldRunInParallel(void) {
int SpawnSubprocesses(int argc, char *argv[]) {
const char *tpath;
sigset_t chldmask, savemask;
int i, rc, ws, pid, tmpfd, *pids, exitcode;
int i, ws, pid, tmpfd, *pids, exitcode;
struct sigaction ignore, saveint, savequit;
char *args[5] = {argv[0], argv[1], argv[2]};

View file

@ -275,8 +275,7 @@ void SendOutputFragmentMessage(enum RunitCommand kind, unsigned char *buf,
}
void Recv(void *output, size_t outputsize) {
int rc;
ssize_t tx, chunk, received, totalgot;
ssize_t chunk, received, totalgot;
static bool once;
static int zstatus;
static char buf[32768];
@ -294,7 +293,6 @@ void Recv(void *output, size_t outputsize) {
totalgot = 0;
for (;;) {
if (rbuf.len >= outputsize) {
tx = MIN(outputsize, rbuf.len);
memcpy(output, rbuf.data + rbuf.off, outputsize);
rbuf.len -= outputsize;
rbuf.off += outputsize;
@ -362,17 +360,15 @@ void Recv(void *output, size_t outputsize) {
}
void HandleClient(void) {
const size_t kMaxNameSize = 128;
const size_t kMaxFileSize = 10 * 1024 * 1024;
ssize_t got;
uint32_t crc;
sigset_t sigmask;
ssize_t got, wrote;
struct sockaddr_in addr;
struct timespec now, deadline;
char *addrstr, *exename, *exe;
unsigned char msg[4 + 1 + 4 + 4 + 4];
uint32_t addrsize, namesize, filesize, remaining;
int rc, events, exitcode, wstatus, child, pipefds[2];
uint32_t addrsize, namesize, filesize;
int events, exitcode, wstatus, child, pipefds[2];
/* read request to run program */
addrsize = sizeof(addr);
@ -436,7 +432,7 @@ void HandleClient(void) {
exe = g_exepath;
} else {
exe = "ape-m1.com";
args[i++] = exe;
args[i++] = (char *)exe;
args[i++] = "-";
args[i++] = g_exepath;
}

View file

@ -60,7 +60,7 @@ void Execute(char *argv[]) {
int Visit(const char *fpath, const struct stat *sb, int tflag,
struct FTW *ftwbuf) {
if (tflag == FTW_F && endswith(fpath, ".gz")) {
Execute((char *[]){"build/bootstrap/gzip.com", "-d", fpath, 0});
Execute((char *[]){"build/bootstrap/gzip.com", "-d", (char *)fpath, 0});
strcpy(binpath, fpath);
binpath[strlen(binpath) - 3] = 0;
chmod(binpath, 0755);

View file

@ -114,7 +114,7 @@ static void CopyZip(void) {
int rela, recs;
Elf64_Ehdr *ehdr;
unsigned long ldest, cdest, ltotal, ctotal, length;
unsigned char *szip, *ineof, *stop, *eocd, *cdir, *lfile, *cfile;
unsigned char *ineof, *stop, *eocd, *cdir, *lfile, *cfile;
// find zip eocd header
//
@ -211,7 +211,6 @@ static void CopyZip(void) {
}
int main(int argc, char *argv[]) {
int i, opt;
#ifndef NDEBUG
ShowCrashReports();
#endif

View file

@ -138,7 +138,6 @@ void GetOpts(int *argc, char ***argv) {
void ProcessFile(struct ElfWriter *elf, const char *path) {
int fd;
void *map;
size_t pathlen;
struct stat st;
const char *name;
if (stat(path, &st)) {
@ -167,7 +166,7 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
name = name_;
} else {
name = path;
if (basenamify_) name = basename(name);
if (basenamify_) name = basename(gc(xstrdup(name)));
name = StripComponents(name, strip_components_);
if (path_prefix_) name = gc(xjoinpaths(path_prefix_, name));
}

View file

@ -94,8 +94,8 @@ static void PrintHeader(uint8_t *p) {
static void Print(void) {
int arsize;
uint8_t *b, *p;
uint64_t offset;
uint8_t *b, *p, *e;
uint32_t i, n, o, table, entries, symbols, symbolslen;
arsize = atoi((char *)(data + 8 + 48));
CHECK_LE(4, arsize);

View file

@ -31,6 +31,8 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -53,8 +55,8 @@ static struct stat st[1];
static Elf64_Ehdr *elf;
static void startfile(void) {
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf", basename(path),
NULL, &kModelineAsm);
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf",
basename(gc(strdup(path))), NULL, &kModelineAsm);
printf("#include \"libc/elf.h\"\n\n", path);
}
@ -224,7 +226,6 @@ static void printelfgroups(void) {
section->sh_name)
: 0);
}
shdr->sh_offset;
}
}
}

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/arraylist2.internal.h"
#include "tool/decode/lib/flagger.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/decode/lib/flagger.h"
/**
* Formats numeric flags integer as symbolic code.
@ -46,7 +46,7 @@ dontdiscard char *RecreateFlags(const struct IdName *names, unsigned long id) {
} else {
first = false;
}
CONCAT(&bufp, &bufi, &bufn, names->name, strlen(names->name));
CONCAT(&bufp, &bufi, &bufn, (char *)names->name, strlen(names->name));
}
}
if (id) {

View file

@ -23,6 +23,8 @@
#include "libc/fmt/libgen.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macho.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -56,7 +58,7 @@ static void showmachoheader(void) {
exit(1);
}
#endif
showtitle(basename(path), "macho", "header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "macho", "header", NULL, NULL);
printf("\n");
showinthex(macho->magic);
show(".long",
@ -171,7 +173,7 @@ static void showmacholoaduuid(struct MachoLoadUuid *lu) {
#define COLS 8
static void showmacholoadgeneric(struct MachoLoadCommand *lc) {
int i, c, col = 0;
int c, col = 0;
int need_newline = 0;
char16_t glyphs[COLS + 1];
const unsigned char *p, *pe;

View file

@ -23,6 +23,8 @@
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nt/struct/imagedosheader.internal.h"
#include "libc/nt/struct/imagentheaders.internal.h"
#include "libc/nt/struct/imageoptionalheader.internal.h"
@ -99,7 +101,7 @@ static void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize,
}
static void showmzheader(void) {
showtitle(basename(path), "dos", "mz header",
showtitle(basename(gc(strdup(path))), "dos", "mz header",
"\tMZ = Mark 'Zibo' Joseph Zbikowski\n"
"\te_cblp: bytes on last page\n"
"\te_cp: 512-byte pages in file\n"
@ -152,7 +154,8 @@ static void showdosstub(void) {
static void showpeoptionalheader(struct NtImageOptionalHeader *opt) {
int i;
showtitle(basename(path), "windows", "pe \"optional\" header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "windows", "pe \"optional\" header",
NULL, NULL);
printf("\n");
show(".short",
firstnonnull(findnamebyid(kNtPeOptionalHeaderMagicNames, opt->Magic),
@ -248,7 +251,8 @@ static void ShowIlt(uint32_t rva) {
static void ShowIdt(char *idt, size_t size) {
char *p, *e;
printf("\n");
showtitle(basename(path), "windows", "import descriptor table (idt)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import descriptor table (idt)", 0, 0);
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
printf("\n");
show(".long", format(b1, "%#x", READ32LE(p)),
@ -266,14 +270,16 @@ static void ShowIdt(char *idt, size_t size) {
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
if (READ32LE(p)) {
printf("\n");
showtitle(basename(path), "windows", "import lookup table (ilt)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import lookup table (ilt)", 0, 0);
ShowIlt(READ32LE(p));
}
}
for (p = idt, e = idt + size; p + 20 <= e; p += 20) {
if (READ32LE(p)) {
printf("\n");
showtitle(basename(path), "windows", "import address table (iat)", 0, 0);
showtitle(basename(gc(strdup(path))), "windows",
"import address table (iat)", 0, 0);
ShowIlt(READ32LE(p + 16));
}
}
@ -316,14 +322,14 @@ static void ShowSections(struct NtImageSectionHeader *s, size_t n) {
sections = s;
section_count = n;
printf("\n");
showtitle(basename(path), "windows", "sections", 0, 0);
showtitle(basename(gc(strdup(path))), "windows", "sections", 0, 0);
for (i = 0; i < n; ++i) {
ShowSection(s + i);
}
}
static void showpeheader(struct NtImageNtHeaders *pe) {
showtitle(basename(path), "windows", "pe header", NULL, NULL);
showtitle(basename(gc(strdup(path))), "windows", "pe header", NULL, NULL);
printf("\n");
showorg(mz->e_lfanew);
show(".ascii", format(b1, "%`'.*s", 4, (const char *)&pe->Signature),

View file

@ -419,7 +419,7 @@ uint8_t *GetZipCdir64(const uint8_t *p, size_t n) {
do {
if (READ32LE(p + i) == kZipCdir64LocatorMagic &&
(j = ZIP_LOCATE64_OFFSET(p + i)) + kZipCdir64HdrMinSize <= n) {
return p + j;
return (uint8_t *)p + j;
}
} while (i--);
}
@ -430,7 +430,7 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) {
size_t pos;
uint16_t i;
static int records;
uint8_t *eocd32, *eocd64, *cdir, *cf, *lf, *q;
uint8_t *eocd32, *eocd64, *cdir, *cf, *lf;
eocd32 = GetZipCdir32(p, n);
eocd64 = GetZipCdir64(p, n);
CHECK(eocd32 || eocd64);

View file

@ -225,7 +225,7 @@ static int Need(void) {
static struct Node *Parse1(void) {
wint_t c;
int i, oldsp;
struct Node *r, *p, *q, *s;
struct Node *r, *p, *q;
do {
if ((c = Greed()) == EOF) return 0;
} while (iswspace(c));
@ -288,9 +288,7 @@ static struct Node *Parse1(void) {
}
static struct Node *Parse(void) {
wint_t c;
int i, oldsp;
struct Node *r, *p, *q, *s;
struct Node *r, *p, *q;
p = r = Parse1();
if (!p) Error(6, "empty expression");
while ((q = Parse1())) {

View file

@ -218,7 +218,7 @@ static int Need(void) {
static struct Node *Parse1(void) {
wint_t c;
int i, oldsp;
struct Node *r, *p, *q, *s;
struct Node *r, *p, *q;
if ((c = Greed()) == EOF) return 0;
if (c == L'λ' || c == '\\') {
oldsp = sp;
@ -269,9 +269,7 @@ static struct Node *Parse1(void) {
}
static struct Node *Parse(void) {
wint_t c;
int i, oldsp;
struct Node *r, *p, *q, *s;
struct Node *r, *p, *q;
p = r = Parse1();
if (!p) Error(6, "empty expression");
while ((q = Parse1())) {

View file

@ -45,7 +45,7 @@ int GetDepth(struct Closure *env) {
}
void PrintClosure(struct Closure *c, const char *name, int indent, FILE *f) {
int i, j;
int j;
char ibuf[21];
while (c && c != &root) {
for (j = 0; j < indent; ++j) {
@ -71,7 +71,6 @@ void PrintMachineState(FILE *f) {
int i;
char buf[256];
static int op;
struct Closure *c;
fputc('\n', f);
for (i = 0; i < 80; ++i) fputwc(L'', f);
ksnprintf(buf, sizeof(buf),

View file

@ -11,13 +11,13 @@
static int LuaFetch(lua_State *L) {
#define ssl nope // TODO(jart): make this file less huge
char *p;
ssize_t rc;
bool usingssl;
uint32_t ip;
struct Url url;
int t, ret, sock = -1, methodidx, hdridx;
char *host, *port, *request;
const char *host, *port;
char *request;
struct TlsBio *bio;
struct addrinfo *addr;
struct Buffer inbuf; // shadowing intentional
@ -26,13 +26,13 @@ static int LuaFetch(lua_State *L) {
const char *urlarg, *body, *method;
char *conlenhdr = "";
char *headers = 0;
char *hosthdr = 0;
char *connhdr = 0;
char *agenthdr = brand;
char *key, *val, *hdr;
const char *hosthdr = 0;
const char *connhdr = 0;
const char *agenthdr = brand;
const char *key, *val, *hdr;
size_t keylen, vallen;
size_t urlarglen, requestlen, paylen, bodylen;
size_t i, g, n, hdrsize;
size_t i, g, hdrsize;
int keepalive = kaNONE;
int imethod, numredirects = 0, maxredirects = 5;
bool followredirect = true;
@ -41,6 +41,9 @@ static int LuaFetch(lua_State *L) {
.ai_protocol = IPPROTO_TCP,
.ai_flags = AI_NUMERICSERV};
(void)ret;
(void)usingssl;
/*
* Get args: url [, body | {method = "PUT", body = "..."}]
*/
@ -204,7 +207,7 @@ static int LuaFetch(lua_State *L) {
url.host.p = 0, url.host.n = 0;
url.port.p = 0, url.port.n = 0;
if (!url.path.n || url.path.p[0] != '/') {
p = _gc(xmalloc(1 + url.path.n));
void *p = _gc(xmalloc(1 + url.path.n));
mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n);
url.path.p = p;
++url.path.n;
@ -258,6 +261,7 @@ static int LuaFetch(lua_State *L) {
}
}
(void)bio;
#ifndef UNSECURE
if (usingssl) {
if (sslcliused) {

View file

@ -358,7 +358,6 @@ int LuaBsf(lua_State *L) {
}
int LuaHighwayHash64(lua_State *L) {
long i;
size_t n;
uint64_t k[4];
const char *p;
@ -390,8 +389,8 @@ int LuaCrc32c(lua_State *L) {
}
int LuaIndentLines(lua_State *L) {
void *p;
size_t n, j;
const void *p;
if (!lua_isnoneornil(L, 1)) {
p = luaL_checklstring(L, 1, &n);
j = luaL_optinteger(L, 2, 1);
@ -399,9 +398,9 @@ int LuaIndentLines(lua_State *L) {
luaL_argerror(L, 2, "not in range 0..65535");
__builtin_unreachable();
}
p = IndentLines(p, n, &n, j);
lua_pushlstring(L, p, n);
free(p);
char *q = IndentLines(p, n, &n, j);
lua_pushlstring(L, q, n);
free(q);
return 1;
} else {
return lua_gettop(L);
@ -493,8 +492,8 @@ int LuaSlurp(lua_State *L) {
// ├─→ true
// └─→ nil, unix.Errno
int LuaBarf(lua_State *L) {
char *data;
ssize_t rc;
const char *data;
lua_Number offset;
size_t i, n, wrote;
int fd, mode, flags, olderr;
@ -588,13 +587,14 @@ int LuaHasControlCodes(lua_State *L) {
int LuaEncodeLatin1(lua_State *L) {
int f;
char *p;
char *q;
size_t n;
const char *p;
p = luaL_checklstring(L, 1, &n);
f = LuaCheckControlFlags(L, 2);
if ((p = EncodeLatin1(p, n, &n, f))) {
lua_pushlstring(L, p, n);
free(p);
if ((q = EncodeLatin1(p, n, &n, f))) {
lua_pushlstring(L, q, n);
free(q);
return 1;
} else {
luaL_error(L, "out of memory");
@ -659,11 +659,10 @@ int LuaGetHttpReason(lua_State *L) {
int LuaGetCryptoHash(lua_State *L) {
size_t hl, pl, kl;
uint8_t d[64];
mbedtls_md_context_t ctx;
// get hash name, payload, and key
void *h = luaL_checklstring(L, 1, &hl);
void *p = luaL_checklstring(L, 2, &pl);
void *k = luaL_optlstring(L, 3, "", &kl);
const void *h = luaL_checklstring(L, 1, &hl);
const void *p = luaL_checklstring(L, 2, &pl);
const void *k = luaL_optlstring(L, 3, "", &kl);
const mbedtls_md_info_t *digest = mbedtls_md_info_from_string(h);
if (!digest) return luaL_argerror(L, 1, "unknown hash type");
if (kl == 0) {
@ -707,13 +706,14 @@ int LuaIsAcceptablePort(lua_State *L) {
static dontinline int LuaCoderImpl(lua_State *L,
char *C(const char *, size_t, size_t *)) {
void *p;
void *q;
size_t n;
const void *p;
if (!lua_isnoneornil(L, 1)) {
p = luaL_checklstring(L, 1, &n);
if ((p = C(p, n, &n))) {
lua_pushlstring(L, p, n);
free(p);
if ((q = C(p, n, &n))) {
lua_pushlstring(L, q, n);
free(q);
} else {
luaL_error(L, "out of memory");
__builtin_unreachable();
@ -782,12 +782,13 @@ int LuaEscapeFragment(lua_State *L) {
}
int LuaEscapeLiteral(lua_State *L) {
char *p, *q = 0;
const char *p;
char *z, *q = 0;
size_t n, y = 0;
p = luaL_checklstring(L, 1, &n);
if ((p = EscapeJsStringLiteral(&q, &y, p, n, &n))) {
lua_pushlstring(L, p, n);
free(q);
if ((z = EscapeJsStringLiteral(&q, &y, p, n, &n))) {
lua_pushlstring(L, z, n);
free(z);
return 1;
} else {
luaL_error(L, "out of memory");
@ -801,9 +802,9 @@ int LuaVisualizeControlCodes(lua_State *L) {
static dontinline int LuaHasherImpl(lua_State *L, size_t k,
int H(const void *, size_t, uint8_t *)) {
void *p;
size_t n;
uint8_t d[64];
const void *p;
if (!lua_isnoneornil(L, 1)) {
p = luaL_checklstring(L, 1, &n);
H(p, n, d);
@ -884,7 +885,7 @@ int LuaBenchmark(lua_State *L) {
uint64_t t1, t2;
int64_t interrupts;
double avgticks, overhead;
int core, iter, count, tries, attempts, maxattempts;
int core, iter, count, attempts, maxattempts;
luaL_checktype(L, 1, LUA_TFUNCTION);
count = luaL_optinteger(L, 2, 100);
maxattempts = luaL_optinteger(L, 3, 10);

View file

@ -28,6 +28,7 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/calls/weirdtypes.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "third_party/lua/lauxlib.h"
@ -120,7 +121,6 @@ struct sdb {
static const char *const sqlite_meta = ":sqlite3";
static const char *const sqlite_vm_meta = ":sqlite3:vm";
static const char *const sqlite_bu_meta = ":sqlite3:bu";
static const char *const sqlite_ctx_meta = ":sqlite3:ctx";
static int sqlite_ctx_meta_ref;
#ifdef SQLITE_ENABLE_SESSION
@ -1264,7 +1264,6 @@ static void db_update_hook_callback(void *user, int op, char const *dbname, char
sdb *db = (sdb*)user;
lua_State *L = db->L;
int top = lua_gettop(L);
lua_Number n;
/* setup lua callback call */
lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_cb); /* get callback */
@ -1777,7 +1776,7 @@ static int db_deserialize(lua_State *L) {
return 0;
const char *sqlbuf = memcpy(sqlite3_malloc(size), buffer, size);
sqlite3_deserialize(db->db, "main", sqlbuf, size, size,
sqlite3_deserialize(db->db, "main", (void *)sqlbuf, size, size,
SQLITE_DESERIALIZE_FREEONCLOSE + SQLITE_DESERIALIZE_RESIZEABLE);
return 0;
}
@ -1917,7 +1916,6 @@ static int liter_next(lua_State *L) {
}
static int liter_pk(lua_State *L) {
const char *zTab;
int n, rc, nCol;
unsigned char *abPK;
liter *litr = lsqlite_checkiter(L, 1);
@ -2255,13 +2253,13 @@ static int db_create_session(lua_State *L) {
static int db_iterate_changeset(lua_State *L) {
sqlite3_changeset_iter *p;
sdb *db = lsqlite_checkdb(L, 1);
lsqlite_checkdb(L, 1);
const char *cset = luaL_checkstring(L, 2);
int nset = lua_rawlen(L, 2);
int flags = luaL_optinteger(L, 3, 0);
int rc;
if ((rc = sqlite3changeset_start_v2(&p, nset, cset, flags)) != SQLITE_OK) {
if ((rc = sqlite3changeset_start_v2(&p, nset, (void *)cset, flags)) != SQLITE_OK) {
return pusherr(L, rc);
}
(void)lsqlite_makeiter(L, p, 1);
@ -2269,7 +2267,7 @@ static int db_iterate_changeset(lua_State *L) {
}
static int db_invert_changeset(lua_State *L) {
sdb *db = lsqlite_checkdb(L, 1);
lsqlite_checkdb(L, 1);
const char *cset = luaL_checkstring(L, 2);
int nset = lua_rawlen(L, 2);
int rc;
@ -2285,7 +2283,7 @@ static int db_invert_changeset(lua_State *L) {
}
static int db_concat_changeset(lua_State *L) {
sdb *db = lsqlite_checkdb(L, 1);
lsqlite_checkdb(L, 1);
int size, nset;
void *buf, *cset;
sqlite3_changegroup *pGrp;
@ -2295,7 +2293,7 @@ static int db_concat_changeset(lua_State *L) {
int rc = sqlite3changegroup_new(&pGrp);
for (int i = 1; rc == SQLITE_OK && i <= n; i++) {
lua_rawgeti(L, 2, i);
cset = lua_tostring(L, -1);
cset = gc(strdup(lua_tostring(L, -1)));
nset = lua_rawlen(L, -1);
rc = sqlite3changegroup_add(pGrp, nset, cset);
lua_pop(L, 1); // pop the string
@ -2311,7 +2309,7 @@ static int db_concat_changeset(lua_State *L) {
static int db_apply_changeset(lua_State *L) {
sdb *db = lsqlite_checkdb(L, 1);
const char *cset = luaL_checkstring(L, 2);
char *cset = gc(strdup(luaL_checkstring(L, 2)));
int nset = lua_rawlen(L, 2);
int top = lua_gettop(L);
int rc;

View file

@ -51,6 +51,7 @@
#include "libc/math.h"
#include "libc/mem/alloca.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/nt2sysv.h"
@ -139,6 +140,8 @@
#include "tool/net/luacheck.h"
#include "tool/net/sandbox.h"
#pragma GCC diagnostic ignored "-Wunused-variable"
STATIC_STACK_SIZE(0x80000);
__static_yoink("zipos");
@ -440,7 +443,6 @@ static bool daemonize;
static bool logrusage;
static bool logbodies;
static bool requiressl;
static bool isterminal;
static bool sslcliused;
static bool loglatency;
static bool terminated;
@ -448,7 +450,6 @@ static bool uniprocess;
static bool invalidated;
static bool logmessages;
static bool isinitialized;
static bool checkedmethod;
static bool sslinitialized;
static bool sslfetchverify;
static bool selfmodifiable;
@ -465,7 +466,6 @@ static bool ishandlingrequest;
static bool listeningonport443;
static bool hasonprocesscreate;
static bool hasonprocessdestroy;
static bool loggednetworkorigin;
static bool ishandlingconnection;
static bool hasonclientconnection;
static bool evadedragnetsurveillance;
@ -486,6 +486,7 @@ static int sslticketlifetime;
static uint32_t clientaddrsize;
static atomic_int terminatemonitor;
static char *brand;
static size_t zsize;
static lua_State *GL;
static lua_State *YL;
@ -493,25 +494,21 @@ static uint8_t *zmap;
static uint8_t *zcdir;
static size_t hdrsize;
static size_t amtread;
static char *replstack;
static reader_f reader;
static writer_f writer;
static char *extrahdrs;
static const char *zpath;
static const char *brand;
static char *monitorstack;
static char *serverheader;
static char gzip_footer[8];
static long maxpayloadsize;
static const char *pidpath;
static const char *logpath;
static uint32_t *interfaces;
static const char *histpath;
static struct pollfd *polls;
static size_t payloadlength;
static int64_t cacheseconds;
static const char *cachedirective;
static char *cachedirective;
static const char *monitortty;
static const char *serverheader;
static struct Strings stagedirs;
static struct Strings hidepaths;
static const char *launchbrowser;
@ -664,7 +661,7 @@ static char *MergePaths(const char *p, size_t n, const char *q, size_t m,
}
static long FindRedirect(const char *s, size_t n) {
int c, m, l, r, z;
int c, m, l, r;
l = 0;
r = redirects.n - 1;
while (l <= r) {
@ -941,7 +938,6 @@ static bool IsTrustedIp(uint32_t ip) {
static void DescribeAddress(char buf[40], uint32_t addr, uint16_t port) {
char *p;
const char *s;
p = buf;
p = FormatUint32(p, (addr & 0xFF000000) >> 030), *p++ = '.';
p = FormatUint32(p, (addr & 0x00FF0000) >> 020), *p++ = '.';
@ -965,7 +961,6 @@ static inline int GetClientAddr(uint32_t *ip, uint16_t *port) {
}
static inline int GetRemoteAddr(uint32_t *ip, uint16_t *port) {
char str[40];
GetClientAddr(ip, port);
if (HasHeader(kHttpXForwardedFor)) {
if (IsTrustedIp(*ip)) {
@ -1051,7 +1046,7 @@ static void ProgramTimeout(long ms) {
static void ProgramCache(long x, const char *s) {
cacheseconds = x;
if (s) cachedirective = s;
if (s) cachedirective = strdup(s);
}
static void SetDefaults(void) {
@ -1084,7 +1079,7 @@ static bool HasString(struct Strings *l, const char *s, size_t n) {
return false;
}
static const char *DEFAULTLUAPATH = "/zip/.lua/?.lua;/zip/.lua/?/init.lua";
const char *DEFAULTLUAPATH = "/zip/.lua/?.lua;/zip/.lua/?/init.lua";
static void UpdateLuaPath(const char *s) {
#ifndef STATIC
@ -1096,8 +1091,8 @@ static void UpdateLuaPath(const char *s) {
lua_getglobal(L, "package");
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "path");
curpath = luaL_optstring(L, -1, "");
if (t = strstr(curpath, DEFAULTLUAPATH)) {
curpath = (void *)luaL_optstring(L, -1, "");
if ((t = strstr(curpath, DEFAULTLUAPATH))) {
// if the DEFAULT path is found, prepend the path in front of it
respath = xasprintf("%.*s%s/.lua/?.lua;%s/.lua/?/init.lua;%s",
t - curpath, curpath, s, s, t);
@ -1127,7 +1122,7 @@ static void ProgramDirectory(const char *path) {
}
static void ProgramHeader(const char *s) {
char *p, *v, *h;
char *p, *v;
if ((p = strchr(s, ':')) && IsValidHttpToken(s, p - s) &&
(v = EncodeLatin1(p + 1, -1, 0, kControlC0 | kControlC1 | kControlWs))) {
switch (GetHttpHeader(s, p - s)) {
@ -1202,7 +1197,7 @@ static void Daemonize(void) {
umask(0);
}
static void LogLuaError(char *hook, char *err) {
static void LogLuaError(const char *hook, const char *err) {
ERRORF("(lua) failed to run %s: %s", hook, err);
}
@ -1511,7 +1506,7 @@ static int TlsFlush(struct TlsBio *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 (WritevAll(bio->fd, v, 2) != -1) {
if (bio->c > 0) bio->c = 0;
@ -1533,7 +1528,6 @@ static int TlsFlush(struct TlsBio *bio, const unsigned char *buf, size_t len) {
static int TlsSend(void *ctx, const unsigned char *buf, size_t len) {
int rc;
struct iovec v[2];
struct TlsBio *bio = ctx;
if (bio->c >= 0 && bio->c + len <= sizeof(bio->u)) {
memcpy(bio->u + bio->c, buf, len);
@ -1546,7 +1540,6 @@ static int TlsSend(void *ctx, const unsigned char *buf, size_t len) {
static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) {
int r;
ssize_t s;
struct iovec v[2];
struct TlsBio *bio = ctx;
if ((r = TlsFlush(bio, 0, 0)) < 0) return r;
@ -1580,7 +1573,6 @@ static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) {
static int TlsRecv(void *ctx, unsigned char *buf, size_t len, uint32_t tmo) {
int rc;
struct TlsBio *bio = ctx;
if (oldin.n) {
rc = MIN(oldin.n, len);
memcpy(buf, oldin.p, rc);
@ -1711,7 +1703,6 @@ static void CertsDestroy(void) {
}
static void WipeServingKeys(void) {
size_t i;
if (uniprocess) return;
mbedtls_ssl_ticket_free(&ssltick);
mbedtls_ssl_key_cert_free(conf.key_cert), conf.key_cert = 0;
@ -1906,9 +1897,8 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca,
const char *s;
bool isduplicate;
size_t i, j, k, nsan;
struct HostsTxt *htxt;
struct mbedtls_san *san;
const mbedtls_x509_name *xname;
const struct HostsTxt *htxt;
char *name, *subject, *issuer, notbefore[16], notafter[16], hbuf[256];
san = 0;
nsan = 0;
@ -1922,7 +1912,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca,
if (ips.p[j] == READ32BE(htxt->entries.p[i].ip)) {
isduplicate = false;
s = htxt->strings.p + htxt->entries.p[i].name;
if (!name) name = s;
if (!name) name = (void *)s;
for (k = 0; k < nsan; ++k) {
if (san[k].tag == MBEDTLS_X509_SAN_DNS_NAME &&
!strcasecmp(s, san[k].val)) {
@ -2175,7 +2165,7 @@ static void IndexAssets(void) {
hash = Hash(ZIP_CFILE_NAME(zmap + cf), ZIP_CFILE_NAMESIZE(zmap + cf));
step = 0;
do {
i = (hash + (step * (step + 1)) >> 1) & (m - 1);
i = (hash + ((step * (step + 1)) >> 1)) & (m - 1);
++step;
} while (p[i].hash);
GetZipCfileTimestamps(zmap + cf, &lm, 0, 0, gmtoff);
@ -2193,8 +2183,8 @@ static void IndexAssets(void) {
static bool OpenZip(bool force) {
int fd;
size_t n;
uint8_t *m, *d;
struct stat st;
uint8_t *m, *d, *p;
if (stat(zpath, &st) != -1) {
if (force || st.st_ino != zst.st_ino || st.st_size > zst.st_size) {
if (st.st_ino == zst.st_ino) {
@ -2241,7 +2231,7 @@ static struct Asset *GetAssetZip(const char *path, size_t pathlen) {
if (pathlen > 1 && path[0] == '/') ++path, --pathlen;
hash = Hash(path, pathlen);
for (step = 0;; ++step) {
i = (hash + (step * (step + 1)) >> 1) & (assets.n - 1);
i = (hash + ((step * (step + 1)) >> 1)) & (assets.n - 1);
if (!assets.p[i].hash) return NULL;
if (hash == assets.p[i].hash &&
pathlen == ZIP_CFILE_NAMESIZE(zmap + assets.p[i].cf) &&
@ -2275,7 +2265,6 @@ static struct Asset *GetAssetFile(const char *path, size_t pathlen) {
}
static struct Asset *GetAsset(const char *path, size_t pathlen) {
char *path2;
struct Asset *a;
if (!(a = GetAssetFile(path, pathlen))) {
if (!(a = GetAssetZip(path, pathlen))) {
@ -2386,7 +2375,6 @@ static void *Deflate(const void *data, size_t size, size_t *out_size) {
}
static void *LoadAsset(struct Asset *a, size_t *out_size) {
int mode;
size_t size;
uint8_t *data;
if (S_ISDIR(GetMode(a))) {
@ -2657,11 +2645,9 @@ static int LuaCallWithYield(lua_State *L) {
static ssize_t DeflateGenerator(struct iovec v[3]) {
int i, rc;
size_t no;
void *res;
int level;
i = 0;
if (!dg.t) {
v[0].iov_base = kGzipHeader;
v[0].iov_base = (void *)kGzipHeader;
v[0].iov_len = sizeof(kGzipHeader);
++dg.t;
++i;
@ -2713,7 +2699,6 @@ static ssize_t DeflateGenerator(struct iovec v[3]) {
static char *ServeAssetCompressed(struct Asset *a) {
char *p;
uint32_t crc;
LockInc(&shared->c.deflates);
LockInc(&shared->c.compressedresponses);
DEBUGF("(srvr) ServeAssetCompressed()");
@ -2739,7 +2724,6 @@ static char *ServeAssetCompressed(struct Asset *a) {
static ssize_t InflateGenerator(struct iovec v[3]) {
int i, rc;
size_t no;
void *res;
i = 0;
if (!dg.t) {
++dg.t;
@ -2777,7 +2761,6 @@ static ssize_t InflateGenerator(struct iovec v[3]) {
static char *ServeAssetDecompressed(struct Asset *a) {
char *p;
size_t size;
uint32_t crc;
LockInc(&shared->c.inflates);
LockInc(&shared->c.decompressedresponses);
size = GetZipCfileUncompressedSize(zmap + a->cf);
@ -2853,12 +2836,13 @@ static char *ServeAssetRange(struct Asset *a) {
}
static char *GetAssetPath(uint8_t *zcf, size_t *out_size) {
char *p1, *p2;
char *p2;
size_t n1, n2;
const char *p1;
p1 = ZIP_CFILE_NAME(zcf);
n1 = ZIP_CFILE_NAMESIZE(zcf);
p2 = xmalloc(1 + n1 + 1);
n2 = 1 + n1 + 1;
p2 = xmalloc(n2);
p2[0] = '/';
memcpy(p2 + 1, p1, n1);
p2[1 + n1] = '\0';
@ -2937,7 +2921,7 @@ static void LaunchBrowser(const char *path) {
sigaction(SIGINT, &saveint, 0);
sigaction(SIGQUIT, &savequit, 0);
sigprocmask(SIG_SETMASK, &savemask, 0);
execv(prog, (char *const[]){prog, u, 0});
execv(prog, (char *const[]){(char *)prog, (char *)u, 0});
_Exit(127);
}
while (wait4(pid, &ws, 0, 0) == -1) {
@ -2988,12 +2972,11 @@ static char *ServeListing(void) {
int w[3];
uint8_t *zcf;
struct tm tm;
char *p, *path;
const char *and;
struct rusage ru;
char *p, *q, *path;
struct timespec lastmod;
size_t n, pathlen, rn[6];
char rb[8], tb[20], *rp[6];
size_t i, n, pathlen, rn[6];
LockInc(&shared->c.listingrequests);
if (cpm.msg.method != kHttpGet && cpm.msg.method != kHttpHead)
return BadMethod();
@ -3272,7 +3255,7 @@ static char *ServeLua(struct Asset *a, const char *s, size_t n) {
size_t codelen;
lua_State *L = GL;
LockInc(&shared->c.dynamicrequests);
effectivepath.p = s;
effectivepath.p = (void *)s;
effectivepath.n = n;
if ((code = FreeLater(LoadAsset(a, &codelen)))) {
int status =
@ -3446,9 +3429,10 @@ static int LuaServeIndex(lua_State *L) {
}
static int LuaServeRedirect(lua_State *L) {
size_t loclen;
const char *location, *eval;
int code;
char *eval;
size_t loclen;
const char *location;
OnlyCallDuringRequest(L, "ServeRedirect");
code = luaL_checkinteger(L, 1);
@ -3639,16 +3623,15 @@ static void GetDosLocalTime(int64_t utcunixts, uint16_t *out_time,
*out_date = DOS_DATE(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday + 1);
}
static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
int mode) {
static void StoreAsset(const char *path, size_t pathlen, const char *data,
size_t datalen, int mode) {
int64_t ft;
int i;
uint32_t crc;
char *comp, *p;
struct timespec now;
struct Asset *a;
struct iovec v[13];
uint8_t *cdir, era;
uint8_t era;
const char *use;
uint16_t gflags, iattrs, mtime, mdate, dosmode, method, disk;
size_t oldcdirsize, oldcdiroffset, records, cdiroffset, cdirsize, complen,
@ -3722,10 +3705,10 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
p = WRITE16LE(p, pathlen);
p = WRITE16LE(p, v[2].iov_len);
v[1].iov_len = pathlen;
v[1].iov_base = path;
v[1].iov_base = (void *)path;
// file data
v[3].iov_len = uselen;
v[3].iov_base = use;
v[3].iov_base = (void *)use;
// old central directory entries
oldcdirsize = GetZipCdirSize(zcdir);
oldcdiroffset = GetZipCdirOffset(zcdir);
@ -3788,7 +3771,7 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
p = WRITE16LE(p, mode);
p = WRITE32LE(p, MIN(zsize, 0xffffffff));
v[7].iov_len = pathlen;
v[7].iov_base = path;
v[7].iov_base = (void *)path;
// zip64 end of central directory
cdiroffset =
zsize + v[0].iov_len + v[1].iov_len + v[2].iov_len + v[3].iov_len;
@ -3817,7 +3800,7 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
v[10].iov_base = 0;
}
// end of central directory
v[12].iov_base = GetZipCdirComment(zcdir);
v[12].iov_base = (void *)GetZipCdirComment(zcdir);
v[12].iov_len = GetZipCdirCommentSize(zcdir);
v[11].iov_base = p = alloca((v[11].iov_len = kZipCdirHdrMinSize));
p = WRITE32LE(p, kZipCdirHdrMagic);
@ -3836,11 +3819,11 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen,
free(comp);
}
static void StoreFile(char *path) {
static void StoreFile(const char *path) {
char *p;
size_t plen, tlen;
struct stat st;
char *target = path;
size_t plen, tlen;
const char *target = path;
if (startswith(target, "./")) target += 2;
tlen = strlen(target);
if (!IsReasonablePath(target, tlen))
@ -3857,8 +3840,9 @@ static void StorePath(const char *dirpath) {
DIR *d;
char *path;
struct dirent *e;
if (!isdirectory(dirpath) && !endswith(dirpath, "/"))
if (!isdirectory(dirpath) && !endswith(dirpath, "/")) {
return StoreFile(dirpath);
}
if (!(d = opendir(dirpath))) FATALF("(cfg) error: can't open %`'s", dirpath);
while ((e = readdir(d))) {
if (strcmp(e->d_name, ".") == 0) continue;
@ -4137,10 +4121,9 @@ static int LuaGetUser(lua_State *L) {
OnlyCallDuringRequest(L, "GetUser");
if (url.user.p) {
LuaPushUrlView(L, &url.user);
} else if ((p = GetBasicAuthorization(&n))) {
} else if ((p = gc(GetBasicAuthorization(&n)))) {
if (!(q = memchr(p, ':', n))) q = p + n;
lua_pushlstring(L, p, q - p);
free(p);
} else {
lua_pushnil(L);
}
@ -4153,13 +4136,12 @@ static int LuaGetPass(lua_State *L) {
OnlyCallDuringRequest(L, "GetPass");
if (url.user.p) {
LuaPushUrlView(L, &url.pass);
} else if ((p = GetBasicAuthorization(&n))) {
} else if ((p = gc(GetBasicAuthorization(&n)))) {
if ((q = memchr(p, ':', n))) {
lua_pushlstring(L, q + 1, p + n - (q + 1));
} else {
lua_pushnil(L);
}
free(p);
} else {
lua_pushnil(L);
}
@ -4245,10 +4227,10 @@ static int LuaGetHeaders(lua_State *L) {
static int LuaSetHeader(lua_State *L) {
int h;
ssize_t rc;
char *eval;
char *p, *q;
const char *key, *val, *eval;
size_t i, keylen, vallen, evallen;
const char *key, *val;
size_t keylen, vallen, evallen;
OnlyCallDuringRequest(L, "SetHeader");
key = luaL_checklstring(L, 1, &keylen);
val = luaL_optlstring(L, 2, 0, &vallen);
@ -4365,7 +4347,7 @@ static int LuaSetCookie(lua_State *L) {
expires =
FormatUnixHttpDateTime(FreeLater(xmalloc(30)), lua_tonumber(L, -1));
} else {
expires = lua_tostring(L, -1);
expires = (void *)lua_tostring(L, -1);
if (!ParseHttpDateTime(expires, -1)) {
luaL_argerror(L, 3, "invalid data format in Expires");
__builtin_unreachable();
@ -4384,7 +4366,7 @@ static int LuaSetCookie(lua_State *L) {
if (lua_getfield(L, 3, "samesite") == LUA_TSTRING ||
lua_getfield(L, 3, "SameSite") == LUA_TSTRING) {
samesite = lua_tostring(L, -1); // also used in the Secure check
samesite = (void *)lua_tostring(L, -1); // also used in the Secure check
appends(&buf, "; SameSite=");
appends(&buf, samesite);
}
@ -4588,7 +4570,7 @@ static int LuaProgramBrand(lua_State *L) {
static int LuaProgramDirectory(lua_State *L) {
struct stat st;
char *path = luaL_checkstring(L, 1);
const char *path = luaL_checkstring(L, 1);
// check to raise a Lua error, to allow it to be handled
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
return luaL_argerror(L, 1, "not a directory");
@ -4637,7 +4619,7 @@ static int LuaProgramSslPresharedKey(lua_State *L) {
}
static int LuaProgramSslCiphersuite(lua_State *L) {
mbedtls_ssl_ciphersuite_t *suite;
const mbedtls_ssl_ciphersuite_t *suite;
OnlyCallFromInitLua(L, "ProgramSslCiphersuite");
if (!(suite = GetCipherSuite(luaL_checkstring(L, 1)))) {
luaL_argerror(L, 1, "unsupported or unknown ciphersuite");
@ -4741,7 +4723,7 @@ static int LuaGetZipPaths(lua_State *L) {
char *path;
uint8_t *zcf;
size_t i, n, pathlen, prefixlen;
char *prefix = luaL_optlstring(L, 1, "", &prefixlen);
const char *prefix = luaL_optlstring(L, 1, "", &prefixlen);
lua_newtable(L);
i = 0;
n = GetZipCdirRecords(zcdir);
@ -4977,13 +4959,13 @@ static int LuaProgramTokenBucket(lua_State *L) {
}
static const char *GetContentTypeExt(const char *path, size_t n) {
char *r, *e;
const char *r, *e;
int top;
lua_State *L = GL;
if ((r = FindContentType(path, n))) return r;
// extract the last .; use the entire path if none is present
if (e = strrchr(path, '.')) path = e + 1;
if ((e = strrchr(path, '.'))) path = e + 1;
top = lua_gettop(L);
lua_pushlightuserdata(L, (void *)&ctIdx); // push address as unique key
CHECK_EQ(lua_gettable(L, LUA_REGISTRYINDEX), LUA_TTABLE);
@ -5055,7 +5037,7 @@ static bool LuaRunAsset(const char *path, bool mandatory) {
if ((a = GetAsset(path, pathlen))) {
if ((code = FreeLater(LoadAsset(a, &codelen)))) {
lua_State *L = GL;
effectivepath.p = path;
effectivepath.p = (void *)path;
effectivepath.n = pathlen;
DEBUGF("(lua) LuaRunAsset(%`'s)", path);
status = luaL_loadbuffer(
@ -5420,7 +5402,6 @@ static void HandleCompletions(const char *p, linenoiseCompletions *c) {
static void LuaPrint(lua_State *L) {
int i, n;
char *b = 0;
const char *s;
n = lua_gettop(L);
if (n > 0) {
for (i = 1; i <= n; i++) {
@ -5529,6 +5510,7 @@ static void MemDestroy(void) {
Free(&cpm.outbuf);
FreeStrings(&stagedirs);
FreeStrings(&hidepaths);
Free(&cachedirective);
Free(&launchbrowser);
Free(&serverheader);
Free(&trustedips.p);
@ -5608,7 +5590,7 @@ static ssize_t SendString(const char *s) {
ssize_t rc;
struct iovec iov;
n = strlen(s);
iov.iov_base = s;
iov.iov_base = (void *)s;
iov.iov_len = n;
if (logmessages) {
LogMessage("sending", s, n);
@ -5776,7 +5758,6 @@ static void HandleReload(void) {
static void HandleHeartbeat(void) {
size_t i;
sigset_t mask;
UpdateCurrentDate(timespec_real());
Reindex();
getrusage(RUSAGE_SELF, &shared->server);
@ -6062,7 +6043,6 @@ static char *Route(const char *host, size_t hostlen, const char *path,
static char *RoutePath(const char *path, size_t pathlen) {
int m;
long r;
char *p;
struct Asset *a;
DEBUGF("(srvr) RoutePath(%`'.*s)", pathlen, path);
if ((a = GetAsset(path, pathlen))) {
@ -6166,7 +6146,6 @@ static bool IsNotModified(struct Asset *a) {
static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) {
char *p;
uint32_t crc;
const char *ct;
ct = GetContentType(a, path, pathlen);
if (IsNotModified(a)) {
@ -6274,7 +6253,7 @@ static bool TransmitResponse(char *p) {
iovlen = 1;
if (!MustNotIncludeMessageBody()) {
if (cpm.gzipped) {
iov[iovlen].iov_base = kGzipHeader;
iov[iovlen].iov_base = (void *)kGzipHeader;
iov[iovlen].iov_len = sizeof(kGzipHeader);
++iovlen;
}
@ -6438,10 +6417,10 @@ static bool IsSsl(unsigned char c) {
}
static void HandleMessages(void) {
char *p;
bool once;
ssize_t rc;
size_t got;
(void)once;
for (once = false;;) {
InitRequest();
startread = timespec_real();
@ -6607,14 +6586,14 @@ static int MemoryMonitor(void *arg, int tid) {
static struct termios oldterm;
static int tty;
sigset_t ss;
bool done, ok;
bool ok;
size_t intervals;
struct winsize ws;
unsigned char rez;
struct termios term;
char *b, *addr, title[128];
char *b, *addr;
struct MemoryInterval *mi, *mi2;
long i, j, k, n, x, y, pi, gen, pages;
long i, j, gen, pages;
int rc, id, color, color2, workers;
id = atomic_load_explicit(&shared->workers, memory_order_relaxed);
DEBUGF("(memv) started for pid %d on tid %d", getpid(), gettid());
@ -6689,7 +6668,7 @@ static int MemoryMonitor(void *arg, int tid) {
appendr(&b, 0);
appends(&b, "\e[H\e[1m");
for (pi = k = x = y = i = 0; i < intervals; ++i) {
for (i = 0; i < intervals; ++i) {
addr = (char *)((int64_t)((uint64_t)mi[i].x << 32) >> 16);
color = 0;
appendf(&b, "\e[0m%lx", addr);
@ -6934,8 +6913,6 @@ static int HandleConnection(size_t i) {
static void MakeExecutableModifiable(void) {
#ifdef __x86_64__
int ft;
size_t n;
extern char ape_rom_vaddr[] __attribute__((__weak__));
if (!(SUPPORT_VECTOR & (_HOSTMETAL | _HOSTWINDOWS | _HOSTXNU))) return;
if (IsWindows()) return; // TODO
if (IsOpenbsd()) return; // TODO
@ -7253,8 +7230,8 @@ static void TlsInit(void) {
}
mbedtls_ssl_set_bio(&ssl, &g_bio, TlsSend, 0, TlsRecv);
conf.disable_compression = confcli.disable_compression = true;
DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&conf, kAlpn));
DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&confcli, kAlpn));
DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&conf, (void *)kAlpn));
DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&confcli, (void *)kAlpn));
DCHECK_EQ(0, mbedtls_ssl_setup(&ssl, &conf));
DCHECK_EQ(0, mbedtls_ssl_setup(&sslcli, &confcli));
#endif

View file

@ -170,17 +170,13 @@ static wontreturn void PrintUsage(FILE *f, int rc) {
}
int fetch(void) {
char *p;
int status;
ssize_t rc;
const char *body;
int t, ret, sock;
struct TlsBio *bio;
long messagesremaining;
struct HttpMessage msg;
struct HttpUnchunker u;
size_t urlarglen, requestlen;
size_t g, i, n, hdrsize, paylen;
size_t g, n, hdrsize, paylen;
messagesremaining = messagesperconnection;
@ -188,7 +184,7 @@ int fetch(void) {
* Setup crypto.
*/
if (usessl) {
-mbedtls_ssl_session_reset(&ssl);
mbedtls_ssl_session_reset(&ssl);
CHECK_EQ(0, mbedtls_ssl_set_hostname(&ssl, host));
}

View file

@ -20,7 +20,7 @@
#include "tool/plinko/lib/plinko.h"
struct Binding Bind(int x, int y, int a, int u, dword p1, dword p2) {
int k, v, w;
int k, v;
dword a1 = 0;
while (x) {
if (x < 0) {

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/char.h"
#include "tool/plinko/lib/cons.h"
#include "tool/plinko/lib/char.h"
int List(int x, int y) {
return Cons(x, Cons(y, -0));
@ -47,8 +47,7 @@ int GetCommonCons(int x, int y) {
}
int ShareCons(int x, int y) {
dword t;
int i, n;
int i;
if ((i = GetCommonCons(x, y))) return i;
#if 0
t = MAKE(x, y);

View file

@ -46,7 +46,7 @@ struct T DispatchRecur2(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchYcombine(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int ycomb, z, u, t, p, b, name, lambda, closure;
int ycomb, p, name, lambda, closure;
SetFrame(r, LO(ea));
r |= NEED_GC;
ycomb = recurse(MAKE(Car(LO(ea)), HI(ea)), p1, p2);

View file

@ -69,8 +69,6 @@ static void CheckClosure(int e, int a) {
}
int Enclose(int e, int a) {
int x;
dword w;
CheckClosure(e, a);
return Cons(kClosure, Cons(e, a));
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/gc.h"
#include "libc/assert.h"
#include "libc/intrin/bsf.h"
#include "libc/intrin/popcnt.h"
@ -27,7 +28,6 @@
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/plinko/lib/cons.h"
#include "tool/plinko/lib/gc.h"
#include "tool/plinko/lib/histo.h"
#include "tool/plinko/lib/plinko.h"
#include "tool/plinko/lib/print.h"
@ -66,7 +66,7 @@ void Marker(const dword M[], int A, int x) {
do {
i = ~(x - A);
if (HasBit(M, i)) return;
SetBit(M, i);
SetBit((void *)M, i);
if (HI(GetShadow(x)) < A) {
Marker(M, A, HI(GetShadow(x)));
}

View file

@ -44,7 +44,6 @@ int IsDelegate(int x_) {
if (ddx_ >= 0) return 0;
w_ = Get(ddx_); // ((F . V) . Q)
int addx_ = LO(w_);
int dddx_ = HI(w_);
if (addx_ >= 0) return 0;
w_ = Get(addx_); // (F . V)
int aaddx_ = LO(w_);

View file

@ -42,7 +42,6 @@ bool IsYcombinator(int x_) {
if (dx_ >= 0) return false;
w_ = Get(dx_); // ((λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) . Q)
int adx_ = LO(w_);
int ddx_ = HI(w_);
if (adx_ >= 0) return false;
w_ = Get(adx_); // (λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))))
int aadx_ = LO(w_);

View file

@ -96,7 +96,7 @@ static dword PlanLambda(int e, int a, int s) {
}
static dword PlanCond(int e, int a, int s) {
int x, b;
int x;
if (!Cdr(e)) return DF(DispatchNil); // (ζ) ⟺ ⊥
for (x = e; (x = Cdr(x));) {
if (x > 0) React(e, e, kCond); // (ζ . 𝑣) not allowed
@ -107,7 +107,6 @@ static dword PlanCond(int e, int a, int s) {
}
static dword PlanProgn(int e, int a, int s) {
int x;
if (!Cdr(e)) return DF(DispatchNil); // (progn) ⟺ ⊥
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kProgn);
return MAKE(DF(DispatchProgn), Cdr(e));
@ -216,7 +215,7 @@ static dword PlanClosure(int e, int a, int s) {
}
static dword PlanLet(int e, int a, int s) {
int p, n;
int n;
if ((n = CountSimpleArguments(Cdr(e))) == -1) return DF(DispatchFuncall);
if (CountSimpleArguments(Car(e)) < 3) React(e, e, kLambda); // need (λ 𝑥 𝑦)
switch (CountSimpleParameters(Cadr(Car(e)))) {
@ -234,7 +233,6 @@ static dword PlanLet(int e, int a, int s) {
}
static dontinline dword PlanPrecious(int e, int a, int s, int f) {
int x;
DCHECK_GT(f, 0);
if (f == kCar) return PlanCar(e, a, s);
if (f == kCdr) return PlanCdr(e, a, s);

View file

@ -168,7 +168,7 @@ static int QuoteList(int x) {
}
static int GetAtom(const char *s) {
int x, y, t, u;
int x, y;
ax = y = TERM;
x = *s++ & 255;
if (*s) y = GetAtom(s);
@ -532,7 +532,7 @@ struct T DispatchIf(dword ea, dword tm, dword r, dword p1, dword p2, dword d) {
struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
bool b;
int x, e, A;
int e;
e = LO(ea);
SetFrame(r, e);
b = literally;
@ -545,7 +545,6 @@ struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchFlush(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int x, A;
SetFrame(r, LO(ea));
Flush(1);
return Ret(MAKE(kIgnore0, 0), tm, r);
@ -794,15 +793,11 @@ Delegate:
struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int a, b, e, f, t, u, y, p, z;
int b, e, u, y, p;
e = LO(ea);
a = HI(ea);
DCHECK_LT(e, 0);
SetFrame(r, e);
f = Car(e);
z = Cdr(e);
y = HI(d);
t = Car(y);
// (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏)
y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏)
u = Cdr(y); // 𝑏
@ -816,15 +811,11 @@ struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchCall2(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int a, b, e, f, t, u, y, p, z;
int b, e, u, y, p;
e = LO(ea);
a = HI(ea);
DCHECK_LT(e, 0);
SetFrame(r, e);
f = Car(e);
z = Cdr(e);
y = HI(d);
t = Car(y);
// (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏)
y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏)
u = Cdr(y); // 𝑏
@ -878,7 +869,7 @@ static void PrintStats(long usec) {
-cHeap - -cFrost, usec, cGets, cSets, cAtoms, -cFrost);
}
static wontreturn Exit(void) {
static wontreturn int Exit(void) {
exit(0 <= fails && fails <= 255 ? fails : 255);
}
@ -903,9 +894,8 @@ static wontreturn void PrintUsage(void) {
}
int Plinko(int argc, char *argv[]) {
long *p;
int S, x;
bool trace;
int S, x, u, j;
uint64_t t1, t2;
tick = kStartTsc;
#ifndef NDEBUG

View file

@ -23,7 +23,7 @@
#include "tool/plinko/lib/tree.h"
static void PrettyPrintList(int fd, int x, int n) {
int i, y, once, func, mode, argwidth, funcwidth, forcedot;
int y, once, func, mode, argwidth, funcwidth, forcedot;
DCHECK_GE(n, 0);
DCHECK_LE(x, 0);
if (x < cx) {

View file

@ -32,7 +32,7 @@ static inline long GetVarInt(va_list va, signed char t) {
}
static int PrintStr(int fd, const char *s, int cols) {
int n, j, k = 0, i = 0;
int n, k = 0, i = 0;
n = strlen(s);
k += PrintIndent(fd, +cols - n);
while (i < n) k += PrintChar(fd, s[i++]);
@ -77,7 +77,7 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
const char *s;
signed char type;
char quot, ansi, gotr, pdot, zero;
int b, c, i, x, y, si, prec, cols, sign;
int b, c, x, y, si, prec, cols, sign;
gotr = false;
t = rdtsc();
ftrace_enabled(-1);

View file

@ -98,8 +98,7 @@ dontinstrument int ReadChar(int fd) {
}
static int ReadListItem(int fd, int closer, int f(int)) {
int i, n, x, y;
dword t;
int x, y;
if ((x = f(fd)) > 0) {
if (Get(x) == MAKE(closer, TERM)) return -0;
if (Get(x) == MAKE(L'.', TERM)) {
@ -123,7 +122,7 @@ static int ReadList(int fd, int closer) {
static int TokenizeInteger(int fd, int b) {
dword a;
int c, i, x, y;
int c, i;
for (i = a = 0;; ++i) {
if ((c = GetDiglet(ToUpper(dx))) != -1 && c < b) {
a = (a * b) + c;
@ -146,7 +145,7 @@ static void ConsumeComment(int fd) {
}
static int ReadAtomRest(int fd, int x) {
int y, t, u;
int y;
ax = y = TERM;
if (x == L'\\') x = ReadChar(fd);
if (!IsSpace(dx) && !IsParen(dx) && !IsMathAlnum(x) && !IsMathAlnum(dx)) {
@ -194,7 +193,7 @@ static int TokenizeComplicated(int fd) {
}
static int Read2(int fd) {
int r, f, t, l;
int r, l;
while (IsSpace((l = dx))) ReadChar(fd);
switch (dx) {
case L'#':

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/trace.h"
#include "tool/plinko/lib/plinko.h"
#include "tool/plinko/lib/printf.h"
#include "tool/plinko/lib/trace.h"
void EnableTracing(void) {
eval = EvalTrace;
@ -112,7 +112,7 @@ static relegated int Trace(int e, int a, EvalFn *f, bool p(int), const char *s,
}
relegated int RecurseTrace(dword ea, dword p1, dword p2) {
int r, d, S = sp;
int r;
const char *s = "Recurse";
const unsigned short c[5] = u"╔═║╚═";
if (depth < ARRAYLEN(g_depths)) {
@ -143,7 +143,7 @@ relegated int RecurseTrace(dword ea, dword p1, dword p2) {
}
relegated int EvlisTrace(int e, int a, dword p1, dword p2) {
int r, d, S = sp;
int r, d;
const char *s = "Evlis";
const unsigned short c[5] = u"╒─┆╘─";
DCHECK_GE(depth, -1);
@ -177,7 +177,7 @@ relegated int EvlisTrace(int e, int a, dword p1, dword p2) {
relegated int Trace3(int x, int y, int a, PairFn *f, const char *s,
const unsigned short c[5]) {
int r, d, S = sp;
int r;
if (depth < ARRAYLEN(g_depths)) {
if (loga) {
Fprintf(2, "%I%c%c%s[x=%S; y=%S; a=%S] δ %'Rns%n", c[0], c[1], s,
@ -198,7 +198,6 @@ relegated int Trace3(int x, int y, int a, PairFn *f, const char *s,
relegated struct Binding BindTrace(int x, int y, int a, int u, dword p1,
dword p2) {
int d, S = sp;
struct Binding r;
if (depth < ARRAYLEN(g_depths)) {
if (loga) {

View file

@ -10,7 +10,6 @@ COSMOPOLITAN_C_START_
BindFn *bf; \
EvlisFn *ef; \
RecurseFn *rf; \
unsigned char mo; \
TailFn *tails[8]; \
EvalFn *ev, *ex; \
memcpy(tails, kTail, sizeof(kTail)); \

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/tree.h"
#include "libc/log/check.h"
#include "tool/plinko/lib/index.h"
#include "tool/plinko/lib/tree.h"
int Nod(int E, int L, int R, int C) {
#ifndef NDEBUG
@ -30,7 +30,7 @@ int Nod(int E, int L, int R, int C) {
}
static void CheckTreeImpl(int N) {
int p, e, L, R;
int p, L, R;
if (N >= 0) Error("N is atom: %S", N);
if (Car(N) >= 0) Error("Car(N) is an atom: %S", N);
if (Cdr(N) & ~1) Error("Cdr(N) is non-bool: %S", N);
@ -229,7 +229,7 @@ int PutTree(int E, int N, int KEEP) {
* @return ((𝑒 𝑙 . 𝑟) . 𝑐) if found, otherwise 0
*/
int GetTree(int k, int N) {
int p, e;
int p;
while (N) {
p = Cmp(k, Key(Ent(N)));
if (p < 0) {
@ -244,7 +244,7 @@ int GetTree(int k, int N) {
}
int GetTreeCount(int k, int N, int *c) {
int p, e;
int p;
while (N) {
++*c;
p = Cmp(k, Key(Ent(N)));

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) {