diff --git a/ape/ape-m1.c b/ape/ape-m1.c index 1afd1edb0..d31ca0b27 100644 --- a/ape/ape-m1.c +++ b/ape/ape-m1.c @@ -221,13 +221,15 @@ struct ApeLoader { static unsigned long StrLen(const char *s) { unsigned long n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; } static int StrCmp(const char *l, const char *r) { unsigned long i = 0; - while (l[i] == r[i] && r[i]) ++i; + while (l[i] == r[i] && r[i]) + ++i; return (l[i] & 255) - (r[i] & 255); } @@ -276,7 +278,8 @@ static char *Utoa(char p[21], unsigned long x) { } static char *Itoa(char p[21], long x) { - if (x < 0) *p++ = '-', x = -(unsigned long)x; + if (x < 0) + *p++ = '-', x = -(unsigned long)x; return Utoa(p, x); } @@ -312,7 +315,8 @@ static int GetIndirectOffset(const char *arg0) { static void Perror(const char *thing, long rc, const char *reason) { char ibuf[21]; ibuf[0] = 0; - if (rc) Itoa(ibuf, -rc); + if (rc) + Itoa(ibuf, -rc); Print(2, "ape error: ", thing, ": ", reason, rc ? " failed w/ errno " : "", ibuf, "\n", 0l); } @@ -327,7 +331,8 @@ static char AccessCommand(struct PathSearcher *ps, unsigned long pathlen) { if (pathlen + 1 + ps->namelen + 1 > sizeof(ps->path)) { return 0; } - if (pathlen && ps->path[pathlen - 1] != '/') ps->path[pathlen++] = '/'; + if (pathlen && ps->path[pathlen - 1] != '/') + ps->path[pathlen++] = '/'; memmove(ps->path + pathlen, ps->name, ps->namelen); ps->path[pathlen + ps->namelen] = 0; return !access(ps->path, X_OK); @@ -377,8 +382,10 @@ static char *Commandv(struct PathSearcher *ps, const char *name, const char *syspath) { ps->syspath = syspath ? syspath : "/bin:/usr/local/bin:/usr/bin"; ps->name = name; - if (!(ps->namelen = ps->indirect ? ps->indirect : StrLen(ps->name))) return 0; - if (ps->namelen + 1 > sizeof(ps->path)) return 0; + if (!(ps->namelen = ps->indirect ? ps->indirect : StrLen(ps->name))) + return 0; + if (ps->namelen + 1 > sizeof(ps->path)) + return 0; if (FindCommand(ps)) { return ps->path; } else { @@ -585,7 +592,8 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, a = p[i].p_vaddr & -pagesz; b = (p[i].p_vaddr + p[i].p_memsz + (pagesz - 1)) & -pagesz; for (j = i + 1; j < e->e_phnum; ++j) { - if (p[j].p_type != PT_LOAD) continue; + if (p[j].p_type != PT_LOAD) + continue; c = p[j].p_vaddr & -pagesz; d = (p[j].p_vaddr + p[j].p_memsz + (pagesz - 1)) & -pagesz; if (MAX(a, c) < MIN(b, d)) { @@ -614,7 +622,8 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, if (e->e_type == ET_DYN) { rc = sys_mmap(0, virtmax - virtmin, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (rc < 0) Pexit(exe, rc, "pie mmap"); + if (rc < 0) + Pexit(exe, rc, "pie mmap"); dynbase = rc; if (dynbase & (pagesz - 1)) { Pexit(exe, 0, "OS mmap incongruent w/ AT_PAGESZ"); @@ -630,14 +639,18 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, for (i = 0; i < e->e_phnum; ++i) { void *addr; unsigned long size; - if (p[i].p_type != PT_LOAD) continue; + if (p[i].p_type != PT_LOAD) + continue; /* configure mapping */ prot = 0; flags = MAP_FIXED | MAP_PRIVATE; - if (p[i].p_flags & PF_R) prot |= PROT_READ; - if (p[i].p_flags & PF_W) prot |= PROT_WRITE; - if (p[i].p_flags & PF_X) prot |= PROT_EXEC; + if (p[i].p_flags & PF_R) + prot |= PROT_READ; + if (p[i].p_flags & PF_W) + prot |= PROT_WRITE; + if (p[i].p_flags & PF_X) + prot |= PROT_EXEC; /* load from file */ if (p[i].p_filesz) { @@ -687,24 +700,30 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, as the default strategy which is slow but it works for both */ rc = sys_mmap(addr, size, (prot1 = PROT_READ | PROT_WRITE), MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); - if (rc < 0) Pexit(exe, rc, "prog mmap anon"); + if (rc < 0) + Pexit(exe, rc, "prog mmap anon"); rc = pread(fd, addr, p[i].p_filesz, p[i].p_offset & -pagesz); - if (rc != p[i].p_filesz) Pexit(exe, -errno, "prog pread"); + if (rc != p[i].p_filesz) + Pexit(exe, -errno, "prog pread"); #endif } else { rc = sys_mmap(addr, size, prot1, flags, fd, p[i].p_offset & -pagesz); - if (rc < 0) Pexit(exe, rc, "prog mmap"); + if (rc < 0) + Pexit(exe, rc, "prog mmap"); } - if (wipe) memset((void *)(dynbase + a), 0, wipe); + if (wipe) + memset((void *)(dynbase + a), 0, wipe); if (prot2 != prot1) { rc = sys_mprotect(addr, size, prot2); - if (rc < 0) Pexit(exe, rc, "prog mprotect"); + if (rc < 0) + Pexit(exe, rc, "prog mprotect"); } /* allocate extra bss */ if (c > b) { flags |= MAP_ANONYMOUS; rc = sys_mmap((void *)(dynbase + b), c - b, prot, flags, -1, 0); - if (rc < 0) Pexit(exe, rc, "extra bss mmap"); + if (rc < 0) + Pexit(exe, rc, "extra bss mmap"); } } else { /* allocate pure bss */ @@ -712,7 +731,8 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, size = (p[i].p_vaddr & (pagesz - 1)) + p[i].p_memsz; flags |= MAP_ANONYMOUS; rc = sys_mmap(addr, size, prot, flags, -1, 0); - if (rc < 0) Pexit(exe, rc, "bss mmap"); + if (rc < 0) + Pexit(exe, rc, "bss mmap"); } } @@ -790,8 +810,10 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf, /* read program headers */ rc = pread(fd, M->phdr.buf, size, ebuf->ehdr.e_phoff); - if (rc < 0) return "failed to read ELF program headers"; - if (rc != size) return "truncated read of ELF program headers"; + if (rc < 0) + return "failed to read ELF program headers"; + if (rc != size) + return "truncated read of ELF program headers"; /* bail on recoverable program header errors */ p = &M->phdr.phdr; @@ -970,7 +992,8 @@ int main(int argc, char **argv, char **envp) { grows down the alloc by poking the guard pages */ n = (auxv - sp + AUXV_WORDS + 1) * sizeof(long); sp2 = (long *)__builtin_alloca(n); - if ((long)sp2 & 15) ++sp2; + if ((long)sp2 & 15) + ++sp2; for (; n > 0; n -= pagesz) { ((char *)sp2)[n - 1] = 0; } diff --git a/ape/loader.c b/ape/loader.c index 752d5ef6e..8b35e3a30 100644 --- a/ape/loader.c +++ b/ape/loader.c @@ -228,13 +228,15 @@ extern char _end[]; static unsigned long StrLen(const char *s) { unsigned long n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; } static int StrCmp(const char *l, const char *r) { unsigned long i = 0; - while (l[i] == r[i] && r[i]) ++i; + while (l[i] == r[i] && r[i]) + ++i; return (l[i] & 255) - (r[i] & 255); } @@ -353,7 +355,8 @@ static char *Utoa(char p[20], unsigned long x) { } static char *Itoa(char p[21], long x) { - if (x < 0) *p++ = '-', x = -(unsigned long)x; + if (x < 0) + *p++ = '-', x = -(unsigned long)x; return Utoa(p, x); } @@ -362,7 +365,8 @@ __attribute__((__noinline__)) static long CallSystem(long arg1, long arg2, long arg5, long arg6, long arg7, int numba, char os) { - if (IsXnu()) numba |= 0x2000000; + if (IsXnu()) + numba |= 0x2000000; return SystemCall(arg1, arg2, arg3, arg4, arg5, arg6, arg7, numba); } @@ -529,7 +533,8 @@ static long Printf(int os, int fd, const char *fmt, ...) { switch ((c = *fmt++)) { case 's': for (s = __builtin_va_arg(va, const char *); s && *s; ++s) { - if (k < 512) b[k++] = *s; + if (k < 512) + b[k++] = *s; } break; case 'd': @@ -542,16 +547,19 @@ static long Printf(int os, int fd, const char *fmt, ...) { u -= 10; c = 'a' + u; } - if (k < 512) b[k++] = c; + if (k < 512) + b[k++] = c; } break; default: - if (k < 512) b[k++] = c; + if (k < 512) + b[k++] = c; break; } break; default: - if (k < 512) b[k++] = c; + if (k < 512) + b[k++] = c; break; } } @@ -560,7 +568,8 @@ static long Printf(int os, int fd, const char *fmt, ...) { static void Perror(int os, const char *thing, long rc, const char *reason) { char ibuf[21]; ibuf[0] = 0; - if (rc) Itoa(ibuf, -rc); + if (rc) + Itoa(ibuf, -rc); Print(os, 2, "ape error: ", thing, ": ", reason, rc ? " failed w/ errno " : "", ibuf, "\n", 0l); } @@ -572,8 +581,10 @@ __attribute__((__noreturn__)) static void Pexit(int os, const char *c, int rc, } static char AccessCommand(struct PathSearcher *ps, unsigned long pathlen) { - if (pathlen + 1 + ps->namelen + 1 > sizeof(ps->path)) return 0; - if (pathlen && ps->path[pathlen - 1] != '/') ps->path[pathlen++] = '/'; + if (pathlen + 1 + ps->namelen + 1 > sizeof(ps->path)) + return 0; + if (pathlen && ps->path[pathlen - 1] != '/') + ps->path[pathlen++] = '/'; MemMove(ps->path + pathlen, ps->name, ps->namelen); ps->path[pathlen + ps->namelen] = 0; return !Access(ps->path, X_OK, ps->os); @@ -600,11 +611,14 @@ static char SearchPath(struct PathSearcher *ps) { static char *Commandv(struct PathSearcher *ps, int os, char *name, const char *syspath) { - if (!(ps->namelen = StrLen((ps->name = name)))) return 0; - if (ps->literally || MemChr(ps->name, '/', ps->namelen)) return name; + if (!(ps->namelen = StrLen((ps->name = name)))) + return 0; + if (ps->literally || MemChr(ps->name, '/', ps->namelen)) + return name; ps->os = os; ps->syspath = syspath ? syspath : "/bin:/usr/local/bin:/usr/bin"; - if (ps->namelen + 1 > sizeof(ps->path)) return 0; + if (ps->namelen + 1 > sizeof(ps->path)) + return 0; ps->path[0] = 0; if (SearchPath(ps)) { return ps->path; @@ -661,7 +675,8 @@ __attribute__((__noreturn__)) static void Spawn(int os, char *exe, int fd, Pexit(os, exe, 0, "ELF segments overlap your APE loader"); } for (j = i + 1; j < e->e_phnum; ++j) { - if (p[j].p_type != PT_LOAD) continue; + if (p[j].p_type != PT_LOAD) + continue; c = p[j].p_vaddr & -pagesz; d = (p[j].p_vaddr + p[j].p_memsz + (pagesz - 1)) & -pagesz; if (MAX(a, c) < MIN(b, d)) { @@ -694,7 +709,8 @@ __attribute__((__noreturn__)) static void Spawn(int os, char *exe, int fd, if (e->e_type == ET_DYN) { rc = Mmap(0, virtmax - virtmin, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0, os); - if (rc < 0) Pexit(os, exe, rc, "pie mmap"); + if (rc < 0) + Pexit(os, exe, rc, "pie mmap"); dynbase = rc; if (dynbase & (pagesz - 1)) { Pexit(os, exe, 0, "OS mmap incongruent w/ AT_PAGESZ"); @@ -710,14 +726,18 @@ __attribute__((__noreturn__)) static void Spawn(int os, char *exe, int fd, for (i = 0; i < e->e_phnum; ++i) { void *addr; unsigned long size; - if (p[i].p_type != PT_LOAD) continue; + if (p[i].p_type != PT_LOAD) + continue; /* configure mapping */ prot = 0; flags = MAP_FIXED | MAP_PRIVATE; - if (p[i].p_flags & PF_R) prot |= PROT_READ; - if (p[i].p_flags & PF_W) prot |= PROT_WRITE; - if (p[i].p_flags & PF_X) prot |= PROT_EXEC; + if (p[i].p_flags & PF_R) + prot |= PROT_READ; + if (p[i].p_flags & PF_W) + prot |= PROT_WRITE; + if (p[i].p_flags & PF_X) + prot |= PROT_EXEC; if (p[i].p_filesz) { /* load from file */ @@ -744,17 +764,21 @@ __attribute__((__noreturn__)) static void Spawn(int os, char *exe, int fd, addr = (void *)(dynbase + (p[i].p_vaddr & -pagesz)); size = (p[i].p_vaddr & (pagesz - 1)) + p[i].p_filesz; rc = Mmap(addr, size, prot1, flags, fd, p[i].p_offset & -pagesz, os); - if (rc < 0) Pexit(os, exe, rc, "prog mmap"); - if (wipe) Bzero((void *)(dynbase + a), wipe); + if (rc < 0) + Pexit(os, exe, rc, "prog mmap"); + if (wipe) + Bzero((void *)(dynbase + a), wipe); if (prot2 != prot1) { rc = Mprotect(addr, size, prot2, os); - if (rc < 0) Pexit(os, exe, rc, "prog mprotect"); + if (rc < 0) + Pexit(os, exe, rc, "prog mprotect"); } /* allocate extra bss */ if (c > b) { flags |= MAP_ANONYMOUS; rc = Mmap((void *)(dynbase + b), c - b, prot, flags, -1, 0, os); - if (rc < 0) Pexit(os, exe, rc, "extra bss mmap"); + if (rc < 0) + Pexit(os, exe, rc, "extra bss mmap"); } } else { /* allocate pure bss */ @@ -762,7 +786,8 @@ __attribute__((__noreturn__)) static void Spawn(int os, char *exe, int fd, size = (p[i].p_vaddr & (pagesz - 1)) + p[i].p_memsz; flags |= MAP_ANONYMOUS; rc = Mmap(addr, size, prot, flags, -1, 0, os); - if (rc < 0) Pexit(os, exe, rc, "bss mmap"); + if (rc < 0) + Pexit(os, exe, rc, "bss mmap"); } } @@ -783,7 +808,8 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf, struct ElfPhdr *p; /* validate page size */ - if (!pagesz) pagesz = 4096; + if (!pagesz) + pagesz = 4096; if (pagesz & (pagesz - 1)) { Pexit(os, exe, 0, "AT_PAGESZ isn't two power"); } @@ -818,8 +844,10 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf, /* read program headers */ rc = Pread(fd, M->phdr.buf, size, e->e_phoff, os); - if (rc < 0) return "failed to read ELF program headers"; - if (rc != size) return "truncated read of ELF program headers"; + if (rc < 0) + return "failed to read ELF program headers"; + if (rc != size) + return "truncated read of ELF program headers"; /* bail on recoverable program header errors */ p = &M->phdr.phdr; @@ -949,7 +977,8 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp, /* determine ape loader program name */ ape = argv[0]; - if (!ape) ape = "ape"; + if (!ape) + ape = "ape"; /* detect openbsd */ if (SupportsOpenbsd() && !os && !auxv[0]) { @@ -1021,7 +1050,8 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp, grows down the alloc by poking the guard pages */ n = (endp - sp + 1) * sizeof(long); sp2 = (long *)__builtin_alloca(n); - if ((long)sp2 & 15) ++sp2; + if ((long)sp2 & 15) + ++sp2; for (; n > 0; n -= pagesz) { ((char *)sp2)[n - 1] = 0; } diff --git a/build/sha256sum.c b/build/sha256sum.c index 15aa45cf0..10d61850f 100644 --- a/build/sha256sum.c +++ b/build/sha256sum.c @@ -197,7 +197,8 @@ static char *FormatUint32(char *p, uint32_t x) { } static char *FormatInt32(char *p, int32_t x) { - if (x < 0) *p++ = '-', x = -(uint32_t)x; + if (x < 0) + *p++ = '-', x = -(uint32_t)x; return FormatUint32(p, x); } @@ -205,7 +206,8 @@ static size_t StrCat(char *dst, const char *src, size_t dsize) { size_t m, n = dsize; const char *p = dst; const char *q = src; - while (n-- != 0 && *dst != '\0') dst++; + while (n-- != 0 && *dst != '\0') + dst++; m = dst - p; n = dsize - m; if (n-- == 0) { @@ -277,7 +279,8 @@ static bool IsSupportedPath(const char *path) { for (i = 0;; ++i) { switch (path[i]) { case 0: - if (i) return true; + if (i) + return true; // fallthrough case '\r': case '\n': @@ -320,8 +323,10 @@ static bool ProduceDigest(const char *path, FILE *f) { char hexdigest[65]; char mode[2] = {g_mode}; unsigned char digest[32]; - if (!IsSupportedPath(path)) return false; - if (!GetDigest(path, f, digest)) return false; + if (!IsSupportedPath(path)) + return false; + if (!GetDigest(path, f, digest)) + return false; CopyHex(hexdigest, digest, 32); Write(1, hexdigest, " ", mode, path, "\n", NULL); return true; @@ -361,17 +366,24 @@ static bool CheckDigests(const char *path, FILE *f) { uint8_t wantdigest[32], gotdigest[32]; char buf[64 + 2 + PATH_MAX + 1 + 1], *p; for (line = 0; fgets(buf, sizeof(buf), f); ++line) { - if (!*Chomp(buf)) continue; + if (!*Chomp(buf)) + continue; for (p = buf, i = 0; i < 32; ++i) { - if ((a = HexToInt(*p++ & 255)) == -1) goto InvalidLine; - if ((b = HexToInt(*p++ & 255)) == -1) goto InvalidLine; + if ((a = HexToInt(*p++ & 255)) == -1) + goto InvalidLine; + if ((b = HexToInt(*p++ & 255)) == -1) + goto InvalidLine; wantdigest[i] = a << 4 | b; } - if (*p++ != ' ') goto InvalidLine; - if (!IsModeCharacter(*p++)) goto InvalidLine; + if (*p++ != ' ') + goto InvalidLine; + if (!IsModeCharacter(*p++)) + goto InvalidLine; path2 = p; - if (!*path2) goto InvalidLine; - if (!IsSupportedPath(path2)) continue; + if (!*path2) + goto InvalidLine; + if (!IsSupportedPath(path2)) + continue; if ((f2 = fopen(path2, "rb"))) { if (GetDigest(path2, f2, gotdigest)) { if (!memcmp(wantdigest, gotdigest, 32)) { diff --git a/dsp/core/alaw.c b/dsp/core/alaw.c index 3c236cdfd..584530b2d 100644 --- a/dsp/core/alaw.c +++ b/dsp/core/alaw.c @@ -27,7 +27,8 @@ */ int alaw(int x) { int a, b, i; - if ((a = x) < 0) a = ~a; + if ((a = x) < 0) + a = ~a; a >>= 4; if (a > 15) { if ((i = a >> 5)) { @@ -40,6 +41,7 @@ int alaw(int x) { a += 16; } } - if (x >= 0) a |= 128; + if (x >= 0) + a |= 128; return a ^ 85; } diff --git a/dsp/core/mulaw.c b/dsp/core/mulaw.c index 510ac29f1..e9aef8dfa 100644 --- a/dsp/core/mulaw.c +++ b/dsp/core/mulaw.c @@ -28,13 +28,15 @@ int mulaw(int x) { int b, i, a, s, l, h; a = x < 0 ? (~x >> 2) + 33 : (x >> 2) + 33; - if (a > 8191) a = 8191; + if (a > 8191) + a = 8191; i = a >> 6; s = i ? (__builtin_clz(i) ^ 31) + 2 : 1; h = 8 - s; l = (a >> s) & 15; l = 15 - l; b = (h << 4) | l; - if (x >= 0) b |= 128; + if (x >= 0) + b |= 128; return b; } diff --git a/dsp/core/scalevolume.c b/dsp/core/scalevolume.c index 3b89b2f6d..4586aeb22 100644 --- a/dsp/core/scalevolume.c +++ b/dsp/core/scalevolume.c @@ -29,7 +29,8 @@ void scalevolume(size_t n, int16_t pcm[n][8], int p) { /* TODO(jart): This isn't acceptable. */ size_t i, j; if (p > 0) { - if (p > 15) p = 15; + if (p > 15) + p = 15; for (i = 0; i < n; ++i) { for (j = 0; j < 8; ++j) { pcm[i][j] = @@ -38,7 +39,8 @@ void scalevolume(size_t n, int16_t pcm[n][8], int p) { } } else if (p < 0) { p = -p; - if (p > 15) p = 15; + if (p > 15) + p = 15; for (i = 0; i < n; ++i) { for (j = 0; j < 8; ++j) { pcm[i][j] = pcm[i][j] >> p; diff --git a/dsp/core/unalaw.c b/dsp/core/unalaw.c index bb0929bcf..dcb854a62 100644 --- a/dsp/core/unalaw.c +++ b/dsp/core/unalaw.c @@ -31,8 +31,10 @@ int unalaw(int x) { i = (x ^ 85) & 127; e = i >> 4; m = i & 15; - if (e > 0) m += 16; + if (e > 0) + m += 16; m = (m << 4) + 8; - if (e > 1) m = m << (e - 1); + if (e > 1) + m = m << (e - 1); return x & 128 ? m : -m; } diff --git a/dsp/mpeg/macroblock.c b/dsp/mpeg/macroblock.c index 10dee49ee..3639011c3 100644 --- a/dsp/mpeg/macroblock.c +++ b/dsp/mpeg/macroblock.c @@ -46,7 +46,8 @@ forceinline void plm_video_process_macroblock(plm_video_t *self, si = ((self->mb_row * BW) + vp) * dw + (self->mb_col * BW) + hp; di = (self->mb_row * dw + self->mb_col) * BW; max_address = (dw * (self->mb_height * BW - BW + 1) - BW); - if (si > max_address || di > max_address) return; + if (si > max_address || di > max_address) + return; d += di; s += si; switch (((interpolate << 2) | (odd_h << 1) | (odd_v)) & 7) { diff --git a/dsp/scale/gyarados.c b/dsp/scale/gyarados.c index b28abde83..4487b3d79 100644 --- a/dsp/scale/gyarados.c +++ b/dsp/scale/gyarados.c @@ -77,7 +77,8 @@ static struct SamplingSolution *NewSamplingSolution(long n, long s) { static bool IsNormalized(int n, double A[n]) { int i; double x; - for (x = i = 0; i < n; ++i) x += A[i]; + for (x = i = 0; i < n; ++i) + x += A[i]; return fabs(x - 1) < 1e-4; } @@ -96,8 +97,10 @@ struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar, short *weights, *indices; struct SamplingSolution *res; long j, i, k, n, min, max, s, N[6]; - if (!dar) dar = sn, dar /= dn; - if (!off) off = (dar - 1) / 2; + if (!dar) + dar = sn, dar /= dn; + if (!off) + off = (dar - 1) / 2; f = dar < 1 ? 1 / dar : dar; s = 3 * f + 4; fweights = gc(xcalloc(s + /*xxx*/ 2, sizeof(double))); @@ -114,8 +117,10 @@ struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar, for (k = 0, j = min; j <= max; ++j) { fweights[k++] = ComputeWeight((j - x) / (f / par)); } - for (sum = k = 0; k < n; ++k) sum += fweights[k]; - for (j = 0; j < n; ++j) fweights[j] *= 1 / sum; + for (sum = k = 0; k < n; ++k) + sum += fweights[k]; + for (j = 0; j < n; ++j) + fweights[j] *= 1 / sum; DCHECK(IsNormalized(n, fweights)); for (j = 0; j < n; ++j) { indices[i * s + j] = MIN(sn - 1, MAX(0, min + j)); diff --git a/dsp/tty/hidecursor.c b/dsp/tty/hidecursor.c index 3a2e7d572..9747165ae 100644 --- a/dsp/tty/hidecursor.c +++ b/dsp/tty/hidecursor.c @@ -30,8 +30,10 @@ static int ttysetcursor(int fd, bool visible) { struct NtConsoleCursorInfo ntcursor; char code[8] = "\e[?25l"; - if (__nocolor) return 0; - if (visible) code[5] = 'h'; + if (__nocolor) + return 0; + if (visible) + code[5] = 'h'; if (IsWindows()) { GetConsoleCursorInfo(GetStdHandle(kNtStdOutputHandle), &ntcursor); ntcursor.bVisible = visible; diff --git a/dsp/tty/setbgfg16.c b/dsp/tty/setbgfg16.c index 32834130c..c0ef4e34f 100644 --- a/dsp/tty/setbgfg16.c +++ b/dsp/tty/setbgfg16.c @@ -21,16 +21,20 @@ #include "libc/limits.h" static char *ansitoa(char *p, unsigned xt, unsigned base) { - if (xt >= 8) xt -= 8, base += 60; + if (xt >= 8) + xt -= 8, base += 60; return itoa8(p, xt + base); } static char *setansibgfg(char *p, unsigned bg, unsigned fg) { *p++ = '\e'; *p++ = '['; - if (bg != -1u) p = ansitoa(p, bg, 40); - if (bg != -1u && fg != -1u) *p++ = ';'; - if (fg != -1u) p = ansitoa(p, fg, 30); + if (bg != -1u) + p = ansitoa(p, bg, 40); + if (bg != -1u && fg != -1u) + *p++ = ';'; + if (fg != -1u) + p = ansitoa(p, fg, 30); *p++ = 'm'; return p; } diff --git a/dsp/tty/ttyraster.c b/dsp/tty/ttyraster.c index c439ee44c..1ced9e374 100644 --- a/dsp/tty/ttyraster.c +++ b/dsp/tty/ttyraster.c @@ -666,7 +666,8 @@ static char *CopyBlock(char *v, const struct TtyRgb chunk[hasatleast 4], struct Glyph *glyph) { unsigned i; CHECK_LT(pick.bg, 4); - if (pick.fg != 0xff) CHECK_LT(pick.fg, 4); + if (pick.fg != 0xff) + CHECK_LT(pick.fg, 4); i = 0; if (pick.fg == 0xff) { if (!ttyeq(*bg, chunk[pick.bg])) { @@ -744,7 +745,8 @@ static dontinline char *CopyRun(char *v, size_t n, v = CopyGlyph(v, *glyph); *x += 2; *c += 2; - if (*x >= n) break; + if (*x >= n) + break; CopyChunk(chunk, *c, n); } while (ChunkEq(chunk, lastchunk)); *x -= 2; diff --git a/dsp/tty/ttyraw.c b/dsp/tty/ttyraw.c index 60ebeea8d..b2b8812ef 100644 --- a/dsp/tty/ttyraw.c +++ b/dsp/tty/ttyraw.c @@ -69,13 +69,16 @@ static textstartup int ttyraw_enable(void) { } static textstartup void ttyraw_hidecursor(void) { - if (!g_ttyraw.setup) return; - if (g_ttyraw.flags & kTtyCursor) return; + if (!g_ttyraw.setup) + return; + if (g_ttyraw.flags & kTtyCursor) + return; ttyhidecursor(FD); } static textexit int ttyraw_disable(void) { - if (!g_ttyraw.setup) return 0; + if (!g_ttyraw.setup) + return 0; ttyshowcursor(FD); return ttyrestore(FD, &g_ttyraw.old); } @@ -87,7 +90,8 @@ static textexit void ttyraw_onexit(void) { static relegated void ttyraw_onsig(int sig, struct siginfo *info, struct ucontext *ctx) { size_t i; - if (g_ttyraw.noreentry) _Exit(128 + sig); + if (g_ttyraw.noreentry) + _Exit(128 + sig); g_ttyraw.noreentry = true; if (g_ttyraw.flags != -1) { if (sig == SIGCONT) { diff --git a/examples/greenbean.c b/examples/greenbean.c index 166b6e532..7d8174d90 100644 --- a/examples/greenbean.c +++ b/examples/greenbean.c @@ -104,8 +104,10 @@ void *Worker(void *id) { if (client == -1) { // accept() errors are generally ephemeral or recoverable // it'd potentially be a good idea to exponential backoff here - if (errno == ECANCELED) continue; // pthread_cancel() was called - if (errno == EMFILE) ExplainPrlimit(); + if (errno == ECANCELED) + continue; // pthread_cancel() was called + if (errno == EMFILE) + ExplainPrlimit(); LOG("accept() returned %m"); SomethingHappened(); continue; @@ -346,8 +348,10 @@ int main(int argc, char *argv[]) { if ((rc = pthread_create(th + i, &attr, Worker, (void *)(intptr_t)i))) { --a_workers; kprintf("pthread_create failed: %s\n", strerror(rc)); - if (rc == EAGAIN) ExplainPrlimit(); - if (!i) exit(1); + if (rc == EAGAIN) + ExplainPrlimit(); + if (!i) + exit(1); threads = i; break; } @@ -364,7 +368,8 @@ int main(int argc, char *argv[]) { PrintEphemeralStatusLine(); unassert(!pthread_cond_wait(&statuscond, &statuslock)); // limit status line updates to sixty frames per second - do tick = timespec_add(tick, (struct timespec){0, 1e9 / 60}); + do + tick = timespec_add(tick, (struct timespec){0, 1e9 / 60}); while (timespec_cmp(tick, timespec_real()) < 0); clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &tick, 0); } @@ -378,7 +383,8 @@ int main(int argc, char *argv[]) { } // on windows this is the only way accept() can be canceled - if (IsWindows()) close(server); + if (IsWindows()) + close(server); // print status in terminal as the shutdown progresses unassert(!pthread_mutex_lock(&statuslock)); @@ -394,7 +400,8 @@ int main(int argc, char *argv[]) { } // close the server socket - if (!IsWindows()) close(server); + if (!IsWindows()) + close(server); // clean up terminal line LOG("thank you for choosing \e[32mgreenbean\e[0m"); diff --git a/examples/kilo.c b/examples/kilo.c index 9645634e1..dfc5aeb46 100644 --- a/examples/kilo.c +++ b/examples/kilo.c @@ -212,10 +212,13 @@ void editorAtExit(void) { int enableRawMode(int64_t fd) { struct termios raw; - if (E.rawmode) return 0; /* Already enabled. */ - if (!isatty(STDIN_FILENO)) goto fatal; + if (E.rawmode) + return 0; /* Already enabled. */ + if (!isatty(STDIN_FILENO)) + goto fatal; atexit(editorAtExit); - if (tcgetattr(fd, &orig_termios) == -1) goto fatal; + if (tcgetattr(fd, &orig_termios) == -1) + goto fatal; raw = orig_termios; /* modify the original mode */ /* input modes: no break, no CR to NL, no parity check, no strip char, @@ -233,7 +236,8 @@ int enableRawMode(int64_t fd) { raw.c_cc[VTIME] = 1; /* 100 ms timeout (unit is tens of second). */ /* put terminal in raw mode after flushing */ - if (tcsetattr(fd, TCSAFLUSH, &raw) < 0) goto fatal; + if (tcsetattr(fd, TCSAFLUSH, &raw) < 0) + goto fatal; E.rawmode = 1; return 0; @@ -249,7 +253,8 @@ int editorReadKey(int64_t fd) { char c, seq[3]; do { nread = read(fd, &c, 1); - if (nread == -1) exit(1); + if (nread == -1) + exit(1); } while (!nread); while (1) { @@ -260,12 +265,15 @@ int editorReadKey(int64_t fd) { return PAGE_DOWN; case '\e': /* escape sequence */ /* If this is just an ESC, we'll timeout here. */ - if (read(fd, seq, 1) == 0) return CTRL('['); + if (read(fd, seq, 1) == 0) + return CTRL('['); if (seq[0] == '[') { - if (read(fd, seq + 1, 1) == 0) return CTRL('['); + if (read(fd, seq + 1, 1) == 0) + return CTRL('['); if (seq[1] >= '0' && seq[1] <= '9') { /* Extended escape, read additional byte. */ - if (read(fd, seq + 2, 1) == 0) return CTRL('['); + if (read(fd, seq + 2, 1) == 0) + return CTRL('['); if (seq[2] == '~') { switch (seq[1]) { case '1': @@ -308,7 +316,8 @@ int editorReadKey(int64_t fd) { } else if (seq[0] == 'v') { return PAGE_UP; } else if (seq[0] == 'O') { - if (read(fd, seq + 1, 1) == 0) return CTRL('['); + if (read(fd, seq + 1, 1) == 0) + return CTRL('['); /* ESC O sequences. */ switch (seq[1]) { case 'H': @@ -332,19 +341,24 @@ int getCursorPosition(int64_t ifd, int64_t ofd, int *rows, int *cols) { unsigned i = 0; /* Report cursor location */ - if (write(ofd, "\e[6n", 4) != 4) return -1; + if (write(ofd, "\e[6n", 4) != 4) + return -1; /* Read the response: ESC [ rows ; cols R */ while (i < sizeof(buf) - 1) { - if (read(ifd, buf + i, 1) != 1) break; - if (buf[i] == 'R') break; + if (read(ifd, buf + i, 1) != 1) + break; + if (buf[i] == 'R') + break; i++; } buf[i] = '\0'; /* Parse it. */ - if (buf[0] != CTRL('[') || buf[1] != '[') return -1; - if (sscanf(buf + 2, "%d;%d", rows, cols) != 2) return -1; + if (buf[0] != CTRL('[') || buf[1] != '[') + return -1; + if (sscanf(buf + 2, "%d;%d", rows, cols) != 2) + return -1; return 0; } @@ -359,12 +373,15 @@ int getWindowSize(int64_t ifd, int64_t ofd, int *rows, int *cols) { /* Get the initial position so we can restore it later. */ retval = getCursorPosition(ifd, ofd, &orig_row, &orig_col); - if (retval == -1) goto failed; + if (retval == -1) + goto failed; /* Go to right/bottom margin and get position. */ - if (write(ofd, "\e[999C\e[999B", 12) != 12) goto failed; + if (write(ofd, "\e[999C\e[999B", 12) != 12) + goto failed; retval = getCursorPosition(ifd, ofd, rows, cols); - if (retval == -1) goto failed; + if (retval == -1) + goto failed; /* Restore position. */ char seq[32]; @@ -406,7 +423,8 @@ void editorUpdateSyntax(erow *row) { row->hl = realloc(row->hl, row->rsize); memset(row->hl, HL_NORMAL, row->rsize); - if (E.syntax == NULL) return; /* No syntax, everything is HL_NORMAL. */ + if (E.syntax == NULL) + return; /* No syntax, everything is HL_NORMAL. */ int i, prev_sep, in_string, in_comment; char *p; @@ -475,7 +493,8 @@ void editorUpdateSyntax(erow *row) { prev_sep = 0; continue; } - if (*p == in_string) in_string = 0; + if (*p == in_string) + in_string = 0; p++; i++; continue; @@ -515,7 +534,8 @@ void editorUpdateSyntax(erow *row) { for (j = 0; keywords[j]; j++) { int klen = strlen(keywords[j]); int kw2 = keywords[j][klen - 1] == '|'; - if (kw2) klen--; + if (kw2) + klen--; if (!memcmp(p, keywords[j], klen) && is_separator(*(p + klen))) { /* Keyword */ @@ -599,7 +619,8 @@ void editorUpdateRow(erow *row) { * respecting tabs, substituting non printable characters with '?'. */ free(row->render); for (j = 0; j < row->size; j++) { - if (row->chars[j] == '\t') tabs++; + if (row->chars[j] == '\t') + tabs++; } row->render = malloc(row->size + tabs * 8 + nonprint * 9 + 1); @@ -626,11 +647,13 @@ void editorUpdateRow(erow *row) { /* Insert a row at the specified position, shifting the other rows on the bottom * if required. */ void editorInsertRow(int at, char *s, size_t len) { - if (at > E.numrows) return; + if (at > E.numrows) + return; E.row = realloc(E.row, sizeof(erow) * (E.numrows + 1)); if (at != E.numrows) { memmove(E.row + at + 1, E.row + at, sizeof(E.row[0]) * (E.numrows - at)); - for (int j = at + 1; j <= E.numrows; j++) E.row[j].idx++; + for (int j = at + 1; j <= E.numrows; j++) + E.row[j].idx++; } E.row[at].size = len; E.row[at].chars = malloc(len + 1); @@ -657,11 +680,13 @@ void editorFreeRow(erow *row) { void editorDelRow(int at) { erow *row; - if (at >= E.numrows) return; + if (at >= E.numrows) + return; row = E.row + at; editorFreeRow(row); memmove(E.row + at, E.row + at + 1, sizeof(E.row[0]) * (E.numrows - at - 1)); - for (int j = at; j < E.numrows - 1; j++) E.row[j].idx++; + for (int j = at; j < E.numrows - 1; j++) + E.row[j].idx++; E.numrows--; E.dirty++; } @@ -729,7 +754,8 @@ void editorRowAppendString(erow *row, char *s, size_t len) { /* Delete the character at offset 'at' from the specified row. */ void editorRowDelChar(erow *row, int at) { - if (row->size <= at) return; + if (row->size <= at) + return; memmove(row->chars + at, row->chars + at + 1, row->size - at); editorUpdateRow(row); row->size--; @@ -745,7 +771,8 @@ void editorInsertChar(int c) { /* If the row where the cursor is currently located does not exist in our * logical representation of the file, add enough empty rows as needed. */ if (!row) { - while (E.numrows <= filerow) editorInsertRow(E.numrows, "", 0); + while (E.numrows <= filerow) + editorInsertRow(E.numrows, "", 0); } row = &E.row[filerow]; editorRowInsertChar(row, filecol, c); @@ -773,7 +800,8 @@ void editorInsertNewline(void) { } /* If the cursor is over the current line size, we want to conceptually * think it's just over the last character. */ - if (filecol >= row->size) filecol = row->size; + if (filecol >= row->size) + filecol = row->size; if (filecol == 0) { editorInsertRow(filerow, "", 0); } else { @@ -800,7 +828,8 @@ void editorDelChar(void) { int filecol = E.coloff + E.cx; erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow]; - if (!row || (filecol == 0 && filerow == 0)) return; + if (!row || (filecol == 0 && filerow == 0)) + return; if (filecol == 0) { /* Handle the case of column 0, we need to move the current line * on the right of the previous one. */ @@ -825,7 +854,8 @@ void editorDelChar(void) { else E.cx--; } - if (row) editorUpdateRow(row); + if (row) + editorUpdateRow(row); E.dirty++; } @@ -868,12 +898,15 @@ int editorSave(void) { int len; char *buf = editorRowsToString(&len); int64_t fd = open(E.filename, O_RDWR | O_CREAT, 0644); - if (fd == -1) goto writeerr; + if (fd == -1) + goto writeerr; /* Use truncate + a single write(2) call in order to make saving * a bit safer, under the limits of what we can do in a small editor. */ - if (ftruncate(fd, len) == -1) goto writeerr; - if (write(fd, buf, len) != len) goto writeerr; + if (ftruncate(fd, len) == -1) + goto writeerr; + if (write(fd, buf, len) != len) + goto writeerr; close(fd); free(buf); @@ -883,7 +916,8 @@ int editorSave(void) { writeerr: free(buf); - if (fd != -1) close(fd); + if (fd != -1) + close(fd); editorSetStatusMessage("Can't save! I/O error: %s", strerror(errno)); return 1; } @@ -924,7 +958,8 @@ void editorRefreshScreen(void) { abAppend(&ab, "~", 1); padding--; } - while (padding--) abAppend(&ab, " ", 1); + while (padding--) + abAppend(&ab, " ", 1); abAppend(&ab, welcome, welcomelen); } else { abAppend(&ab, "~\e[0K\r\n", 7); @@ -939,7 +974,8 @@ void editorRefreshScreen(void) { int current_color = -1; #endif if (len > 0) { - if (len > E.screencols) len = E.screencols; + if (len > E.screencols) + len = E.screencols; char *c = r->render + E.coloff; #if SYNTAX unsigned char *hl = r->hl + E.coloff; @@ -990,7 +1026,8 @@ void editorRefreshScreen(void) { E.numrows, E.dirty ? "(modified)" : ""); int rlen = snprintf(rstatus, sizeof(rstatus), "%d/%d", E.rowoff + E.cy + 1, E.numrows); - if (len > E.screencols) len = E.screencols; + if (len > E.screencols) + len = E.screencols; abAppend(&ab, status, len); while (len < E.screencols) { if (E.screencols - len == rlen) { @@ -1018,7 +1055,8 @@ void editorRefreshScreen(void) { erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow]; if (row) { for (j = E.coloff; j < (E.cx + E.coloff); j++) { - if (j < row->size && row->chars[j] == CTRL('I')) cx += 7 - ((cx) % 8); + if (j < row->size && row->chars[j] == CTRL('I')) + cx += 7 - ((cx) % 8); cx++; } } @@ -1069,7 +1107,8 @@ void editorFind(int64_t fd) { int c = editorReadKey(fd); if (c == DEL_KEY || c == CTRL('H') || c == CTRL('?')) { - if (qlen != 0) query[--qlen] = '\0'; + if (qlen != 0) + query[--qlen] = '\0'; last_match = -1; } else if (c == CTRL('G')) { break; @@ -1096,7 +1135,8 @@ void editorFind(int64_t fd) { } /* Search occurrence. */ - if (last_match == -1) find_next = 1; + if (last_match == -1) + find_next = 1; if (find_next) { char *match = NULL; int match_offset = 0; @@ -1190,7 +1230,8 @@ void editorMoveCursor(int key) { break; case ARROW_UP: if (E.cy == 0) { - if (E.rowoff) E.rowoff--; + if (E.rowoff) + E.rowoff--; } else { E.cy -= 1; } @@ -1299,9 +1340,11 @@ void editorProcessKeypress(int64_t fd) { case CTRL('L'): times = E.screenrows / 2; - while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN); + while (times--) + editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN); times = E.screenrows / 2; - while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_DOWN : ARROW_UP); + while (times--) + editorMoveCursor(c == PAGE_UP ? ARROW_DOWN : ARROW_UP); break; case PAGE_UP: @@ -1312,14 +1355,17 @@ void editorProcessKeypress(int64_t fd) { E.cy = E.screenrows - 1; } times = E.screenrows; - while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN); + while (times--) + editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN); times = E.screenrows / 2; - while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_DOWN : ARROW_UP); + while (times--) + editorMoveCursor(c == PAGE_UP ? ARROW_DOWN : ARROW_UP); break; case HOME_KEY: case CTRL('A'): - while (E.cx || E.coloff) editorMoveCursor(ARROW_LEFT); + while (E.cx || E.coloff) + editorMoveCursor(ARROW_LEFT); break; case END_KEY: case CTRL('E'): diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index 0f5db41cd..296980186 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -492,7 +492,8 @@ void TransmitVideo(void) { ssize_t rc; struct Frame* f; f = &vf_[frame_]; - if (!HasVideo(f)) f = FlipFrameBuffer(); + if (!HasVideo(f)) + f = FlipFrameBuffer(); if ((rc = Write(STDOUT_FILENO, f->w, f->p - f->w)) != -1) { f->w += rc; } else if (errno == EAGAIN) { @@ -504,9 +505,12 @@ void TransmitVideo(void) { void TransmitAudio(void) { ssize_t rc; - if (!playpid_) return; - if (!audio_.i) return; - if (playfd_ == -1) return; + if (!playpid_) + return; + if (!audio_.i) + return; + if (playfd_ == -1) + return; if ((rc = Write(playfd_, audio_.p, audio_.i * sizeof(short))) != -1) { rc /= sizeof(short); memmove(audio_.p, audio_.p + rc, (audio_.i - rc) * sizeof(short)); @@ -561,9 +565,12 @@ void KeyCountdown(struct Action* a) { void PollAndSynchronize(void) { do { if (ReadKeyboard() == -1) { - if (errno != EINTR) Exit(1); - if (exited_) Exit(0); - if (resized_) GetTermSize(); + if (errno != EINTR) + Exit(1); + if (exited_) + Exit(0); + if (resized_) + GetTermSize(); } } while (!timeout_); TransmitVideo(); @@ -734,7 +741,8 @@ u8 Access(unsigned addr, u8 value, bool write) { } } } - if ((addr >> 13) == 3) return PRAM[addr & 0x1FFF]; + if ((addr >> 13) == 3) + return PRAM[addr & 0x1FFF]; return banks[(addr / RomGranularity) % RomPages][addr % RomGranularity]; } @@ -828,7 +836,8 @@ bool offset_toggle = false; u8& NesMmap(int i) { i &= 0x3FFF; if (i >= 0x3F00) { - if (i % 4 == 0) i &= 0x0F; + if (i % 4 == 0) + i &= 0x0F; return palette[i & 0x1F]; } if (i < 0x2000) { @@ -844,7 +853,8 @@ u8 PpuAccess(u16 index, u8 v, bool write) { return open_bus_decay_timer = 77777, open_bus = v; }; u8 res = open_bus; - if (write) RefreshOpenBus(v); + if (write) + RefreshOpenBus(v); switch (index) { // Which port from $200x? case 0: if (write) { @@ -858,7 +868,8 @@ u8 PpuAccess(u16 index, u8 v, bool write) { } break; case 2: - if (write) break; + if (write) + break; res = reg.status | (open_bus & 0x1F); reg.InVBlank = false; // Reading $2002 clears the vblank flag. offset_toggle = false; // Also resets the toggle for address updates. @@ -867,7 +878,8 @@ u8 PpuAccess(u16 index, u8 v, bool write) { } break; case 3: - if (write) reg.OAMaddr = v; + if (write) + reg.OAMaddr = v; break; // Index into Object Attribute Memory case 4: if (write) { @@ -878,7 +890,8 @@ u8 PpuAccess(u16 index, u8 v, bool write) { } break; case 5: - if (!write) break; // Set background scrolling offset + if (!write) + break; // Set background scrolling offset if (offset_toggle) { scroll.yfine = v & 7; scroll.ycoarse = v >> 3; @@ -888,7 +901,8 @@ u8 PpuAccess(u16 index, u8 v, bool write) { offset_toggle = !offset_toggle; break; case 6: - if (!write) break; // Set video memory position for reads/writes + if (!write) + break; // Set video memory position for reads/writes if (offset_toggle) { scroll.vaddrlo = v; vaddr.raw = (unsigned)scroll.raw; @@ -926,17 +940,21 @@ void RenderingTick() { case 2: // Point to attribute table ioaddr = 0x23C0 + 0x400 * vaddr.basenta + 8 * (vaddr.ycoarse / 4) + (vaddr.xcoarse / 4); - if (tile_decode_mode) break; // Or nametable, with sprites. - case 0: // Point to nametable + if (tile_decode_mode) + break; // Or nametable, with sprites. + case 0: // Point to nametable ioaddr = 0x2000 + (vaddr.raw & 0xFFF); // Reset sprite data if (x_ == 0) { sprinpos = sproutpos = 0; - if (reg.ShowSP) reg.OAMaddr = 0; + if (reg.ShowSP) + reg.OAMaddr = 0; } - if (!reg.ShowBG) break; + if (!reg.ShowBG) + break; // Reset scrolling (vertical once, horizontal each scanline) - if (x_ == 304 && scanline == -1) vaddr.raw = (unsigned)scroll.raw; + if (x_ == 304 && scanline == -1) + vaddr.raw = (unsigned)scroll.raw; if (x_ == 256) { vaddr.xcoarse = (unsigned)scroll.xcoarse; vaddr.basenta_h = (unsigned)scroll.basenta_h; @@ -949,7 +967,8 @@ void RenderingTick() { } // Name table access pat_addr = 0x1000 * reg.BGaddr + 16 * NesMmap(ioaddr) + vaddr.yfine; - if (!tile_decode_mode) break; + if (!tile_decode_mode) + break; // Push the current tile into shift registers. // The bitmap pattern is 16 bits, while the attribute is 2 bits, repeated // 8 times. @@ -976,7 +995,8 @@ void RenderingTick() { auto& o = OAM3[sprrenpos]; // Sprite to render on next scanline memcpy(&o, &OAM2[sprrenpos], sizeof(o)); unsigned y = (scanline)-o.y; - if (o.attr & 0x80) y ^= (reg.SPsize ? 15 : 7); + if (o.attr & 0x80) + y ^= (reg.SPsize ? 15 : 7); pat_addr = 0x1000 * (reg.SPsize ? (o.index & 0x01) : reg.SPaddr); pat_addr += 0x10 * (reg.SPsize ? (o.index & 0xFE) : (o.index & 0xFF)); pat_addr += (y & 7) + (y & 8) * 2; @@ -1011,8 +1031,10 @@ void RenderingTick() { break; } ++sprinpos; // next sprite - if (sproutpos < 8) OAM2[sproutpos].y = sprtmp; - if (sproutpos < 8) OAM2[sproutpos].sprindex = reg.OAMindex; + if (sproutpos < 8) + OAM2[sproutpos].y = sprtmp; + if (sproutpos < 8) + OAM2[sproutpos].sprindex = reg.OAMindex; y1 = sprtmp; y2 = sprtmp + (reg.SPsize ? 16 : 8); if (!(scanline >= y1 && scanline < y2)) { @@ -1020,19 +1042,23 @@ void RenderingTick() { } break; case 1: - if (sproutpos < 8) OAM2[sproutpos].index = sprtmp; + if (sproutpos < 8) + OAM2[sproutpos].index = sprtmp; break; case 2: - if (sproutpos < 8) OAM2[sproutpos].attr = sprtmp; + if (sproutpos < 8) + OAM2[sproutpos].attr = sprtmp; break; case 3: - if (sproutpos < 8) OAM2[sproutpos].x_ = sprtmp; + if (sproutpos < 8) + OAM2[sproutpos].x_ = sprtmp; if (sproutpos < 8) { ++sproutpos; } else { reg.SPoverflow = true; } - if (sprinpos == 2) reg.OAMaddr = 8; + if (sprinpos == 2) + reg.OAMaddr = 8; break; } } @@ -1060,13 +1086,17 @@ void RenderPixel() { auto& s = OAM3[sno]; // Check if this sprite is horizontally in range unsigned xdiff = x_ - s.x_; - if (xdiff >= 8) continue; // Also matches negative values + if (xdiff >= 8) + continue; // Also matches negative values // Determine which pixel to display; skip transparent pixels - if (!(s.attr & 0x40)) xdiff = 7 - xdiff; + if (!(s.attr & 0x40)) + xdiff = 7 - xdiff; u8 spritepixel = (s.pattern >> (xdiff * 2)) & 3; - if (!spritepixel) continue; + if (!spritepixel) + continue; // Register sprite-0 hit if applicable - if (x_ < 255 && pixel && s.sprindex == 0) reg.SP0hit = true; + if (x_ < 255 && pixel && s.sprindex == 0) + reg.SP0hit = true; // Render the pixel unless behind-background placement wanted if (!(s.attr & 0x20) || !pixel) { attr = (s.attr & 3) + 4; @@ -1095,11 +1125,13 @@ void ReadToolAssistedSpeedrunRobotKeys() { } if (ctrlmask & 0x80) { joy_next_[0] = fgetc(fp); - if (feof(fp)) joy_next_[0] = 0; + if (feof(fp)) + joy_next_[0] = 0; } if (ctrlmask & 0x40) { joy_next_[1] = fgetc(fp); - if (feof(fp)) joy_next_[1] = 0; + if (feof(fp)) + joy_next_[1] = 0; } } } @@ -1144,18 +1176,23 @@ void Tick() { CPU::nmi = reg.InVBlank && reg.NMIenabled; break; } - if (VBlankState != 0) VBlankState += (VBlankState < 0 ? 1 : -1); - if (open_bus_decay_timer && !--open_bus_decay_timer) open_bus = 0; + if (VBlankState != 0) + VBlankState += (VBlankState < 0 ? 1 : -1); + if (open_bus_decay_timer && !--open_bus_decay_timer) + open_bus = 0; // Graphics processing scanline? if (scanline < DYN) { /* Process graphics for this cycle */ - if (reg.ShowBGSP) RenderingTick(); - if (scanline >= 0 && x_ < 256) RenderPixel(); + if (reg.ShowBGSP) + RenderingTick(); + if (scanline >= 0 && x_ < 256) + RenderPixel(); } // Done with the cycle. Check for end of scanline. - if (++cycle_counter == 3) cycle_counter = 0; // For NTSC pixel shifting + if (++cycle_counter == 3) + cycle_counter = 0; // For NTSC pixel shifting if (++x_ >= scanline_end) { // Begin new scanline FlushScanline(scanline); @@ -1242,30 +1279,36 @@ struct channel { template int Tick() { channel& ch = *this; - if (!ChannelsEnabled[c]) return c == 4 ? 64 : 8; + if (!ChannelsEnabled[c]) + return c == 4 ? 64 : 8; int wl = (ch.reg.WaveLength + 1) * (c >= 2 ? 1 : 2); - if (c == 3) wl = NoisePeriods[ch.reg.NoiseFreq]; + if (c == 3) + wl = NoisePeriods[ch.reg.NoiseFreq]; int volume = ch.length_counter ? ch.reg.EnvDecayDisable ? ch.reg.FixedVolume : ch.envelope : 0; // Sample may change at wavelen intervals. auto& S = ch.level; - if (!count(ch.wave_counter, wl)) return S; + if (!count(ch.wave_counter, wl)) + return S; switch (c) { default: // Square wave. With four different 8-step binary waveforms (32 // bits of data total). - if (wl < 8) return S = 8; + if (wl < 8) + return S = 8; return S = (0xF33C0C04u & (1u << (++ch.phase % 8 + ch.reg.DutyCycle * 8))) ? volume : 0; case 2: // Triangle wave - if (ch.length_counter && ch.linear_counter && wl >= 3) ++ch.phase; + if (ch.length_counter && ch.linear_counter && wl >= 3) + ++ch.phase; return S = (ch.phase & 15) ^ ((ch.phase & 16) ? 15 : 0); case 3: // Noise: Linear feedback shift register - if (!ch.hold) ch.hold = 1; + if (!ch.hold) + ch.hold = 1; ch.hold = (ch.hold >> 1) | (((ch.hold ^ (ch.hold >> (ch.reg.NoiseType ? 6 : 1))) & 1) << 14); @@ -1302,7 +1345,8 @@ struct channel { } else { v -= 2; } - if (v >= 0 && v <= 0x7F) ch.linear_counter = v; + if (v >= 0 && v <= 0x7F) + ch.linear_counter = v; } return S = ch.linear_counter; } @@ -1338,7 +1382,8 @@ void Write(u8 index, u8 value) { ch.linear_counter = ch.reg.LinearCounterInit; ch.env_delay = ch.reg.EnvDecayRate; ch.envelope = 15; - if (index < 8) ch.phase = 0; + if (index < 8) + ch.phase = 0; break; case 0x10: ch.reg.reg3 = value; @@ -1384,9 +1429,11 @@ u8 Read() { for (c = 0; c < 5; ++c) { res |= channels[c].length_counter ? 1 << c : 0; } - if (PeriodicIRQ) res |= 0x40; + if (PeriodicIRQ) + res |= 0x40; PeriodicIRQ = false; - if (DMC_IRQ) res |= 0x80; + if (DMC_IRQ) + res |= 0x80; DMC_IRQ = false; CPU::intr = false; return res; @@ -1396,7 +1443,8 @@ void Tick() { // Invoked at CPU's rate. // Divide CPU clock by 7457.5 to get a 240 Hz, which controls certain events. if ((hz240counter.lo += 2) >= 14915) { hz240counter.lo -= 14915; - if (++hz240counter.hi >= 4 + FiveCycleDivider) hz240counter.hi = 0; + if (++hz240counter.hi >= 4 + FiveCycleDivider) + hz240counter.hi = 0; // 60 Hz interval: IRQ. IRQ is not invoked in five-cycle mode (48 Hz). if (!IRQdisable && !FiveCycleDivider && hz240counter.hi == 0) { @@ -1422,7 +1470,8 @@ void Tick() { // Invoked at CPU's rate. if (wl >= 8 && ch.reg.SweepEnable && ch.reg.SweepShift) { int s = wl >> ch.reg.SweepShift, d[4] = {s, s, ~s, -s}; wl += d[ch.reg.SweepDecrease * 2 + c]; - if (wl < 0x800) ch.reg.WaveLength = wl; + if (wl < 0x800) + ch.reg.WaveLength = wl; } // Linear tick (triangle wave only) @@ -1464,20 +1513,24 @@ namespace CPU { void Tick() { // PPU clock: 3 times the CPU rate - for (unsigned n = 0; n < 3; ++n) PPU::Tick(); + for (unsigned n = 0; n < 3; ++n) + PPU::Tick(); // APU clock: 1 times the CPU rate - for (unsigned n = 0; n < 1; ++n) APU::Tick(); + for (unsigned n = 0; n < 1; ++n) + APU::Tick(); } template u8 MemAccess(u16 addr, u8 v) { // Memory writes are turned into reads while reset is being signalled - if (reset && write) return MemAccess<0>(addr); + if (reset && write) + return MemAccess<0>(addr); Tick(); // Map the memory from CPU's viewpoint. /**/ if (addr < 0x2000) { u8& r = RAM[addr & 0x7FF]; - if (!write) return r; + if (!write) + return r; r = v; } else if (addr < 0x4000) { return PPU::PpuAccess(addr & 7, v, write); @@ -1489,17 +1542,21 @@ u8 MemAccess(u16 addr, u8 v) { WB(0x2004, RB((v & 7) * 0x0100 + b)); return 0; case 0x15: - if (!write) return APU::Read(); + if (!write) + return APU::Read(); APU::Write(0x15, v); break; case 0x16: - if (!write) return JoyRead(0); + if (!write) + return JoyRead(0); JoyStrobe(v); break; case 0x17: - if (!write) return JoyRead(1); // write:passthru + if (!write) + return JoyRead(1); // write:passthru default: - if (!write) break; + if (!write) + break; APU::Write(addr & 0x1F, v); } } else { @@ -1527,7 +1584,8 @@ u16 wrap(u16 oldaddr, u16 newaddr) { } void Misfire(u16 old, u16 addr) { u16 q = wrap(old, addr); - if (q != addr) RB(q); + if (q != addr) + RB(q); } u8 Pop() { return RB(0x100 | u8(++S)); @@ -1655,7 +1713,8 @@ void Op() { } else if (intr && !P.I) { op = 0x102; } - if (!nmi_now) nmi_edge_detected = false; + if (!nmi_now) + nmi_edge_detected = false; // Define function pointers for each opcode (00..FF) and each interrupt // (100,101,102) @@ -1757,12 +1816,15 @@ Press enter to continue without sound: ", fgetc(fp); fgetc(fp); - if (mappernum >= 0x40) mappernum &= 15; + if (mappernum >= 0x40) + mappernum &= 15; GamePak::mappernum = mappernum; // Read the ROM data - if (rom16count) GamePak::ROM.resize(rom16count * 0x4000); - if (vrom8count) GamePak::VRAM.resize(vrom8count * 0x2000); + if (rom16count) + GamePak::ROM.resize(rom16count * 0x4000); + if (vrom8count) + GamePak::VRAM.resize(vrom8count * 0x2000); fread(&GamePak::ROM[0], rom16count, 0x4000, fp); fread(&GamePak::VRAM[0], vrom8count, 0x2000, fp); @@ -1776,10 +1838,12 @@ Press enter to continue without sound: ", PPU::reg.value = 0; // Pre-initialize RAM the same way as FCEUX does, to improve TAS sync. - for (unsigned a = 0; a < 0x800; ++a) CPU::RAM[a] = (a & 4) ? 0xFF : 0x00; + for (unsigned a = 0; a < 0x800; ++a) + CPU::RAM[a] = (a & 4) ? 0xFF : 0x00; // Run the CPU until the program is killed. - for (;;) CPU::Op(); + for (;;) + CPU::Op(); } wontreturn void PrintUsage(int rc, FILE* f) { diff --git a/examples/picol.c b/examples/picol.c index fe32ba9fd..fd54cca53 100644 --- a/examples/picol.c +++ b/examples/picol.c @@ -123,14 +123,16 @@ int picolParseCommand(struct picolParser *p) { } else if (*p->p == '[' && blevel == 0) { level++; } else if (*p->p == ']' && blevel == 0) { - if (!--level) break; + if (!--level) + break; } else if (*p->p == '\\') { p->p++; p->len--; } else if (*p->p == '{') { blevel++; } else if (*p->p == '}') { - if (blevel != 0) blevel--; + if (blevel != 0) + blevel--; } p->p++; p->len--; @@ -270,11 +272,13 @@ int picolGetToken(struct picolParser *p) { case ' ': case '\t': case '\r': - if (p->insidequote) return picolParseString(p); + if (p->insidequote) + return picolParseString(p); return picolParseSep(p); case '\n': case ';': - if (p->insidequote) return picolParseString(p); + if (p->insidequote) + return picolParseString(p); return picolParseEol(p); case '[': return picolParseCommand(p); @@ -310,7 +314,8 @@ void picolSetResult(struct picolInterp *i, char *s) { struct picolVar *picolGetVar(struct picolInterp *i, char *name) { struct picolVar *v = i->callframe->vars; while (v) { - if (strcmp(v->name, name) == 0) return v; + if (strcmp(v->name, name) == 0) + return v; v = v->next; } return NULL; @@ -334,7 +339,8 @@ int picolSetVar(struct picolInterp *i, char *name, char *val) { struct picolCmd *picolGetCommand(struct picolInterp *i, char *name) { struct picolCmd *c = i->commands; while (c) { - if (strcmp(c->name, name) == 0) return c; + if (strcmp(c->name, name) == 0) + return c; c = c->next; } return NULL; @@ -372,9 +378,11 @@ int picolEval(struct picolInterp *i, char *t) { int tlen; int prevtype = p.type; picolGetToken(&p); - if (p.type == PT_EOF) break; + if (p.type == PT_EOF) + break; tlen = p.end - p.start + 1; - if (tlen < 0) tlen = 0; + if (tlen < 0) + tlen = 0; t = malloc(tlen + 1); memcpy(t, p.start, tlen); t[tlen] = '\0'; @@ -392,7 +400,8 @@ int picolEval(struct picolInterp *i, char *t) { } else if (p.type == PT_CMD) { retcode = picolEval(i, t); free(t); - if (retcode != PICOL_OK) goto err; + if (retcode != PICOL_OK) + goto err; t = strdup(i->result); } else if (p.type == PT_ESC) { /* XXX: escape handling missing! */ @@ -414,10 +423,12 @@ int picolEval(struct picolInterp *i, char *t) { goto err; } retcode = c->func(i, argc, argv, c->privdata); - if (retcode != PICOL_OK) goto err; + if (retcode != PICOL_OK) + goto err; } /* Prepare for the next command */ - for (j = 0; j < argc; j++) free(argv[j]); + for (j = 0; j < argc; j++) + free(argv[j]); free(argv); argv = NULL; argc = 0; @@ -438,7 +449,8 @@ int picolEval(struct picolInterp *i, char *t) { prevtype = p.type; } err: - for (j = 0; j < argc; j++) free(argv[j]); + for (j = 0; j < argc; j++) + free(argv[j]); free(argv); return retcode; } @@ -454,7 +466,8 @@ int picolArityErr(struct picolInterp *i, char *name) { int picolCommandMath(struct picolInterp *i, int argc, char **argv, void *pd) { char buf[64]; int a, b, c; - if (argc != 3) return picolArityErr(i, argv[0]); + if (argc != 3) + return picolArityErr(i, argv[0]); a = atoi(argv[1]); b = atoi(argv[2]); if (argv[0][0] == '+') @@ -485,22 +498,26 @@ int picolCommandMath(struct picolInterp *i, int argc, char **argv, void *pd) { } int picolCommandSet(struct picolInterp *i, int argc, char **argv, void *pd) { - if (argc != 3) return picolArityErr(i, argv[0]); + if (argc != 3) + return picolArityErr(i, argv[0]); picolSetVar(i, argv[1], argv[2]); picolSetResult(i, argv[2]); return PICOL_OK; } int picolCommandPuts(struct picolInterp *i, int argc, char **argv, void *pd) { - if (argc != 2) return picolArityErr(i, argv[0]); + if (argc != 2) + return picolArityErr(i, argv[0]); printf("%s\n", argv[1]); return PICOL_OK; } int picolCommandIf(struct picolInterp *i, int argc, char **argv, void *pd) { int retcode; - if (argc != 3 && argc != 5) return picolArityErr(i, argv[0]); - if ((retcode = picolEval(i, argv[1])) != PICOL_OK) return retcode; + if (argc != 3 && argc != 5) + return picolArityErr(i, argv[0]); + if ((retcode = picolEval(i, argv[1])) != PICOL_OK) + return retcode; if (atoi(i->result)) return picolEval(i, argv[2]); else if (argc == 5) @@ -509,10 +526,12 @@ int picolCommandIf(struct picolInterp *i, int argc, char **argv, void *pd) { } int picolCommandWhile(struct picolInterp *i, int argc, char **argv, void *pd) { - if (argc != 3) return picolArityErr(i, argv[0]); + if (argc != 3) + return picolArityErr(i, argv[0]); while (1) { int retcode = picolEval(i, argv[1]); - if (retcode != PICOL_OK) return retcode; + if (retcode != PICOL_OK) + return retcode; if (atoi(i->result)) { if ((retcode = picolEval(i, argv[2])) == PICOL_CONTINUE) continue; @@ -530,7 +549,8 @@ int picolCommandWhile(struct picolInterp *i, int argc, char **argv, void *pd) { int picolCommandRetCodes(struct picolInterp *i, int argc, char **argv, void *pd) { - if (argc != 1) return picolArityErr(i, argv[0]); + if (argc != 1) + return picolArityErr(i, argv[0]); if (strcmp(argv[0], "break") == 0) return PICOL_BREAK; else if (strcmp(argv[0], "continue") == 0) @@ -564,25 +584,31 @@ int picolCommandCallProc(struct picolInterp *i, int argc, char **argv, tofree = p; while (1) { char *start = p; - while (*p != ' ' && *p != '\0') p++; + while (*p != ' ' && *p != '\0') + p++; if (*p != '\0' && p == start) { p++; continue; } - if (p == start) break; + if (p == start) + break; if (*p == '\0') done = 1; else *p = '\0'; - if (++arity > argc - 1) goto arityerr; + if (++arity > argc - 1) + goto arityerr; picolSetVar(i, start, argv[arity]); p++; - if (done) break; + if (done) + break; } free(tofree); - if (arity != argc - 1) goto arityerr; + if (arity != argc - 1) + goto arityerr; errcode = picolEval(i, body); - if (errcode == PICOL_RETURN) errcode = PICOL_OK; + if (errcode == PICOL_RETURN) + errcode = PICOL_OK; picolDropCallFrame(i); /* remove the called proc callframe */ return errcode; arityerr: @@ -594,14 +620,16 @@ arityerr: int picolCommandProc(struct picolInterp *i, int argc, char **argv, void *pd) { char **procdata = malloc(sizeof(char *) * 2); - if (argc != 4) return picolArityErr(i, argv[0]); + if (argc != 4) + return picolArityErr(i, argv[0]); procdata[0] = strdup(argv[2]); /* arguments list */ procdata[1] = strdup(argv[3]); /* procedure body */ return picolRegisterCommand(i, argv[1], picolCommandCallProc, procdata); } int picolCommandReturn(struct picolInterp *i, int argc, char **argv, void *pd) { - if (argc != 1 && argc != 2) return picolArityErr(i, argv[0]); + if (argc != 1 && argc != 2) + return picolArityErr(i, argv[0]); picolSetResult(i, (argc == 2) ? argv[1] : ""); return PICOL_RETURN; } @@ -631,9 +659,11 @@ int main(int argc, char **argv) { int retcode; printf("picol> "); fflush(stdout); - if (fgets(clibuf, 1024, stdin) == NULL) return 0; + if (fgets(clibuf, 1024, stdin) == NULL) + return 0; retcode = picolEval(&interp, clibuf); - if (interp.result[0] != '\0') printf("[%d] %s\n", retcode, interp.result); + if (interp.result[0] != '\0') + printf("[%d] %s\n", retcode, interp.result); } } else if (argc == 2) { char buf[1024 * 16]; @@ -644,7 +674,8 @@ int main(int argc, char **argv) { } buf[fread(buf, 1, 1024 * 16, fp)] = '\0'; fclose(fp); - if (picolEval(&interp, buf) != PICOL_OK) printf("%s\n", interp.result); + if (picolEval(&interp, buf) != PICOL_OK) + printf("%s\n", interp.result); } return 0; } diff --git a/examples/rusage.c b/examples/rusage.c index 7a965a162..d86160987 100644 --- a/examples/rusage.c +++ b/examples/rusage.c @@ -23,7 +23,8 @@ int main(int argc, char *argv[]) { const char *prog = argv[0]; - if (!prog) prog = "rusage"; + if (!prog) + prog = "rusage"; if (argc < 2) { tinyprint(2, prog, ": missing command\n", NULL); diff --git a/examples/spawn_bench.c b/examples/spawn_bench.c index b04f1bc2f..38423389d 100644 --- a/examples/spawn_bench.c +++ b/examples/spawn_bench.c @@ -50,8 +50,10 @@ static char *Ithoa(char p[27], unsigned long x) { } while (x); for (;;) { *p++ = m[--i]; - if (!i) break; - if (!(i % 3)) *p++ = ','; + if (!i) + break; + if (!(i % 3)) + *p++ = ','; } *p = '\0'; return p; diff --git a/examples/stackexplorer.c b/examples/stackexplorer.c index 13f60f134..5b5d9add9 100644 --- a/examples/stackexplorer.c +++ b/examples/stackexplorer.c @@ -36,8 +36,10 @@ void Append(intptr_t i, char *s) { int Compare(const void *a, const void *b) { struct Thing *x = (struct Thing *)a; struct Thing *y = (struct Thing *)b; - if (x->i < y->i) return +1; - if (x->i > y->i) return -1; + if (x->i < y->i) + return +1; + if (x->i > y->i) + return -1; return 0; } @@ -46,19 +48,22 @@ int main(int argc, char *argv[]) { Append((uintptr_t)__oldstack, "__oldstack"); for (int i = 0;; ++i) { Append((uintptr_t)&argv[i], xasprintf("&argv[%d] = %`'s", i, argv[i])); - if (!argv[i]) break; + if (!argv[i]) + break; Append((uintptr_t)argv[i], xasprintf("argv[%d] = %`'s", i, argv[i])); } for (int i = 0;; ++i) { Append((uintptr_t)&environ[i], xasprintf("&environ[%d] = %`'s", i, environ[i])); - if (!environ[i]) break; + if (!environ[i]) + break; Append((uintptr_t)environ[i], xasprintf("environ[%d] = %`'s", i, environ[i])); } for (int i = 0;; i += 2) { Append((uintptr_t)&__auxv[i], xasprintf("&auxv[%d] = %ld", i, __auxv[i])); - if (!__auxv[i]) break; + if (!__auxv[i]) + break; Append((uintptr_t)&__auxv[i + 1], xasprintf("&auxv[%d] = %#lx", i + 1, __auxv[i + 1])); } diff --git a/examples/ttyinfo.c b/examples/ttyinfo.c index 2febd7a1f..6f111acbe 100644 --- a/examples/ttyinfo.c +++ b/examples/ttyinfo.c @@ -198,7 +198,8 @@ int main(int argc, char *argv[]) { dprintf(outfd, "%`'.*s (got %d) ", n, code, n); if (iscntrl(code[0]) && !code[1]) { dprintf(outfd, "is CTRL-%c a.k.a. ^%c\r\n", CTRL(code[0]), CTRL(code[0])); - if (code[0] == CTRL('C') || code[0] == CTRL('D')) break; + if (code[0] == CTRL('C') || code[0] == CTRL('D')) + break; } else if (startswith(code, "\e[") && endswith(code, "R")) { yn = 1, xn = 1; sscanf(code, "\e[%d;%dR", &yn, &xn); diff --git a/examples/uname.c b/examples/uname.c index bdaa6cf6b..81ef6749a 100644 --- a/examples/uname.c +++ b/examples/uname.c @@ -13,7 +13,8 @@ int main(int argc, char *argv[]) { struct utsname names; - if (uname(&names)) return 1; + if (uname(&names)) + return 1; printf("%-10s %`'s\n", "sysname", names.sysname); printf("%-10s %`'s\n", "release", names.release); printf("%-10s %`'s\n", "version", names.version); diff --git a/examples/unbourne.c b/examples/unbourne.c index 536af38b5..034ad8aff 100644 --- a/examples/unbourne.c +++ b/examples/unbourne.c @@ -371,25 +371,28 @@ barrier(); \ 0; \ }) -#define INTON \ - ({ \ - barrier(); \ - if (--suppressint == 0 && intpending) onint(); \ - 0; \ +#define INTON \ + ({ \ + barrier(); \ + if (--suppressint == 0 && intpending) \ + onint(); \ + 0; \ }) -#define FORCEINTON \ - ({ \ - barrier(); \ - suppressint = 0; \ - if (intpending) onint(); \ - 0; \ +#define FORCEINTON \ + ({ \ + barrier(); \ + suppressint = 0; \ + if (intpending) \ + onint(); \ + 0; \ }) #define SAVEINT(v) ((v) = suppressint) -#define RESTOREINT(v) \ - ({ \ - barrier(); \ - if ((suppressint = (v)) == 0 && intpending) onint(); \ - 0; \ +#define RESTOREINT(v) \ + ({ \ + barrier(); \ + if ((suppressint = (v)) == 0 && intpending) \ + onint(); \ + 0; \ }) #define CLEAR_PENDING_INT intpending = 0 #define int_pending() intpending @@ -1577,7 +1580,8 @@ static inline int max_int_length(int bytes) { /* prefix -- see if pfx is a prefix of string. */ static char *prefix(const char *string, const char *pfx) { while (*pfx) { - if (*pfx++ != *string++) return 0; + if (*pfx++ != *string++) + return 0; } return (char *)string; } @@ -1606,7 +1610,8 @@ enum ShErrorAction { E_OPEN, E_CREAT, E_EXEC }; * Action describes the operation that got the error. */ static const char *errmsg(int e, enum ShErrorAction action) { - if (e != ENOENT && e != ENOTDIR) return strerror(e); + if (e != ENOENT && e != ENOTDIR) + return strerror(e); switch (action) { case E_OPEN: return "No such file"; @@ -1629,7 +1634,8 @@ static inline void sigclearmask(void) { * stored in the global variable "exception". */ wontreturn static void exraise(int e) { - if (vforked) _exit(exitstatus); + if (vforked) + _exit(exitstatus); INTOFF; exception = e; longjmp(handler->loc, 1); @@ -1655,12 +1661,14 @@ wontreturn static void onint(void) { static pointer ckmalloc(unsigned nbytes) { pointer p; - if (!(p = malloc(nbytes))) abort(); + if (!(p = malloc(nbytes))) + abort(); return p; } static pointer ckrealloc(pointer p, unsigned nbytes) { - if (!(p = realloc(p, nbytes))) abort(); + if (!(p = realloc(p, nbytes))) + abort(); return p; } @@ -1668,13 +1676,14 @@ static pointer ckrealloc(pointer p, unsigned nbytes) { #define stackblocksize() stacknleft #define STARTSTACKSTR(p) ((p) = stackblock()) #define STPUTC(c, p) ((p) = _STPUTC((c), (p))) -#define CHECKSTRSPACE(n, p) \ - ({ \ - char *q = (p); \ - unsigned l = (n); \ - unsigned m = sstrend - q; \ - if (l > m) (p) = makestrspace(l, q); \ - 0; \ +#define CHECKSTRSPACE(n, p) \ + ({ \ + char *q = (p); \ + unsigned l = (n); \ + unsigned m = sstrend - q; \ + if (l > m) \ + (p) = makestrspace(l, q); \ + 0; \ }) #define USTPUTC(c, p) (*p++ = (c)) #define STACKSTRNUL(p) \ @@ -1696,9 +1705,11 @@ static pointer stalloc(unsigned nbytes) { unsigned blocksize; struct stack_block *sp; blocksize = aligned; - if (blocksize < MINSIZE) blocksize = MINSIZE; + if (blocksize < MINSIZE) + blocksize = MINSIZE; len = sizeof(struct stack_block) - MINSIZE + blocksize; - if (len < blocksize) abort(); + if (len < blocksize) + abort(); INTOFF; sp = ckmalloc(len); sp->prev = stackp; @@ -1759,9 +1770,11 @@ int __xwrite(int, const void *, uint64_t); static void flushout(struct output *dest) { unsigned len; len = dest->nextc - dest->buf; - if (!len || dest->fd < 0) return; + if (!len || dest->fd < 0) + return; dest->nextc = dest->buf; - if ((__xwrite(dest->fd, dest->buf, len))) dest->flags |= OUTPUT_ERR; + if ((__xwrite(dest->fd, dest->buf, len))) + dest->flags |= OUTPUT_ERR; } static void flushall(void) { @@ -1794,8 +1807,10 @@ static int Xvasprintf(char **sp, unsigned size, const char *f, va_list ap) { va_copy(ap2, ap); len = xvsnprintf(*sp, size, f, ap2); va_end(ap2); - if (len < 0) abort(); - if (len < size) return len; + if (len < 0) + abort(); + if (len < size) + return len; s = stalloc((len >= stackblocksize() ? len : stackblocksize()) + 1); *sp = s; len = xvsnprintf(s, len + 1, f, ap); @@ -1827,7 +1842,8 @@ static void outmem(const char *p, unsigned len, struct output *dest) { flushout(dest); } nleft = dest->end - dest->nextc; - if (nleft > len) goto buffered; + if (nleft > len) + goto buffered; if ((__xwrite(dest->fd, p, len))) { dest->flags |= OUTPUT_ERR; } @@ -1982,7 +1998,8 @@ wontreturn static void varunset(const char *end, const char *var_, msg = "parameter not set"; if (umsg) { if (*end == (char)CTLENDVAR) { - if (varflags & VSNUL) tail = " or null"; + if (varflags & VSNUL) + tail = " or null"; } else msg = umsg; } @@ -1997,14 +2014,18 @@ static int64_t atomax(const char *s, int base) { int64_t r; errno = 0; r = strtoimax(s, &p, base); - if (errno == ERANGE) badnum(s); + if (errno == ERANGE) + badnum(s); /* * Disallow completely blank strings in non-arithmetic (base != 0) * contexts. */ - if (p == s && base) badnum(s); - while (isspace((unsigned char)*p)) p++; - if (*p) badnum(s); + if (p == s && base) + badnum(s); + while (isspace((unsigned char)*p)) + p++; + if (*p) + badnum(s); return r; } @@ -2018,7 +2039,8 @@ static int64_t atomax10(const char *s) { */ static int number(const char *s) { int64_t n = atomax10(s); - if (n < 0 || n > INT_MAX) badnum(s); + if (n < 0 || n > INT_MAX) + badnum(s); return n; } @@ -2038,9 +2060,11 @@ static inline int64_t getn(const char *s) { static void growstackblock(unsigned min) { unsigned newlen; newlen = stacknleft * 2; - if (newlen < stacknleft) sh_error("Out of space"); + if (newlen < stacknleft) + sh_error("Out of space"); min = SHELL_ALIGN(min | 128); - if (newlen < min) newlen += min; + if (newlen < min) + newlen += min; if (stacknxt == stackp->space && stackp != &stackbase) { struct stack_block *sp; struct stack_block *prevstackp; @@ -2090,7 +2114,8 @@ static void *growstackstr(void) { } static char *growstackto(unsigned len) { - if (stackblocksize() < len) growstackblock(len); + if (stackblocksize() < len) + growstackblock(len); return stackblock(); } @@ -2099,7 +2124,8 @@ static char *growstackto(unsigned len) { */ static char *savestr(const char *s) { char *p = strdup(s); - if (!p) sh_error("Out of space"); + if (!p) + sh_error("Out of space"); return p; } @@ -2293,13 +2319,15 @@ static unsigned cvtnum(int64_t num, int flags); static int getchr(void) { int val = 0; - if (*gargv) val = **gargv++; + if (*gargv) + val = **gargv++; return val; } static char *getstr(void) { char *val = nullstr; - if (*gargv) val = *gargv++; + if (*gargv) + val = *gargv++; return val; } @@ -2308,7 +2336,8 @@ static char *getstr(void) { */ static int is_number(const char *p) { do { - if (!is_digit(*p)) return 0; + if (!is_digit(*p)) + return 0; } while (*++p != '\0'); return 1; } @@ -2328,14 +2357,16 @@ static inline void outc(int ch, struct output *file) { } static inline char *_STPUTC(int c, char *p) { - if (p == sstrend) p = growstackstr(); + if (p == sstrend) + p = growstackstr(); *p++ = c; return p; } static void ifsfree(void) { struct ifsregion *p = ifsfirst.next; - if (!p) goto out; + if (!p) + goto out; INTOFF; do { struct ifsregion *ifsp; @@ -2402,7 +2433,8 @@ static void rmaliases(void) { struct alias *lookupalias(const char *name, int check) { struct alias *ap = *__lookupalias(name); - if (check && ap && (ap->flag & ALIASINUSE)) return (NULL); + if (check && ap && (ap->flag & ALIASINUSE)) + return (NULL); return (ap); } @@ -2579,7 +2611,8 @@ static int shlex() { checkeq: buf++; checkeqcur: - if (*buf != '=') goto out; + if (*buf != '=') + goto out; value += 11; break; case '>': @@ -2681,12 +2714,15 @@ out: static int varcmp(const char *p, const char *q) { int c, d; while ((c = *p) == (d = *q)) { - if (!c || c == '=') goto out; + if (!c || c == '=') + goto out; p++; q++; } - if (c == '=') c = 0; - if (d == '=') d = 0; + if (c == '=') + c = 0; + if (d == '=') + d = 0; out: return c - d; } @@ -2715,7 +2751,8 @@ static int64_t do_binop(int op, int64_t a, int64_t b) { default: case ARITH_REM: case ARITH_DIV: - if (!b) yyerror("division by zero"); + if (!b) + yyerror("division by zero"); return op == ARITH_REM ? a % b : a / b; case ARITH_MUL: return a * b; @@ -2754,7 +2791,8 @@ again: switch (token) { case ARITH_LPAREN: result = assignment(op, noeval); - if (last_token != ARITH_RPAREN) yyerror("expecting ')'"); + if (last_token != ARITH_RPAREN) + yyerror("expecting ')'"); last_token = shlex(); return result; case ARITH_NUM: @@ -2809,7 +2847,8 @@ static int64_t binop2(int64_t a, int op, int prec, int noeval) { static int64_t binop(int token, union yystype *val, int op, int noeval) { int64_t a = primary(token, val, op, noeval); op = last_token; - if (op < ARITH_BINOP_MIN || op >= ARITH_BINOP_MAX) return a; + if (op < ARITH_BINOP_MIN || op >= ARITH_BINOP_MAX) + return a; return binop2(a, op, ARITH_MAX_PREC, noeval); } @@ -2817,7 +2856,8 @@ static int64_t and (int token, union yystype *val, int op, int noeval) { int64_t a = binop(token, val, op, noeval); int64_t b; op = last_token; - if (op != ARITH_AND) return a; + if (op != ARITH_AND) + return a; token = shlex(); *val = yylval; b = and(token, val, shlex(), noeval | !a); @@ -2828,7 +2868,8 @@ static int64_t or (int token, union yystype *val, int op, int noeval) { int64_t a = and(token, val, op, noeval); int64_t b; op = last_token; - if (op != ARITH_OR) return a; + if (op != ARITH_OR) + return a; token = shlex(); *val = yylval; b = or (token, val, shlex(), noeval | !!a); @@ -2839,9 +2880,11 @@ static int64_t cond(int token, union yystype *val, int op, int noeval) { int64_t a = or (token, val, op, noeval); int64_t b; int64_t c; - if (last_token != ARITH_QMARK) return a; + if (last_token != ARITH_QMARK) + return a; b = assignment(shlex(), noeval | !a); - if (last_token != ARITH_COLON) yyerror("expecting ':'"); + if (last_token != ARITH_COLON) + yyerror("expecting ':'"); token = shlex(); *val = yylval; c = cond(token, val, shlex(), noeval | !!a); @@ -2852,12 +2895,14 @@ static int64_t assignment(int var_, int noeval) { union yystype val = yylval; int op = shlex(); int64_t result; - if (var_ != ARITH_VAR) return cond(var_, &val, op, noeval); + if (var_ != ARITH_VAR) + return cond(var_, &val, op, noeval); if (op != ARITH_ASS && (op < ARITH_ASS_MIN || op >= ARITH_ASS_MAX)) { return cond(var_, &val, op, noeval); } result = assignment(shlex(), noeval); - if (noeval) return result; + if (noeval) + return result; return setvarint( val.name, (op == ARITH_ASS ? result @@ -2869,7 +2914,8 @@ static int64_t arith(const char *s) { int64_t result; arith_buf = arith_startbuf = s; result = assignment(shlex(), 0); - if (last_token) yyerror("expecting EOF"); + if (last_token) + yyerror("expecting EOF"); return result; } @@ -2915,8 +2961,10 @@ static int cdcmd(int argc, char **argv) { dest = bltinlookup("OLDPWD"); flags |= CD_PRINT; } - if (!dest) dest = nullstr; - if (*dest == '/') goto step6; + if (!dest) + dest = nullstr; + if (*dest == '/') + goto step6; if (*dest == '.') { c = dest[1]; dotdot: @@ -2926,18 +2974,22 @@ static int cdcmd(int argc, char **argv) { goto step6; case '.': c = dest[2]; - if (c != '.') goto dotdot; + if (c != '.') + goto dotdot; } } - if (!*dest) dest = "."; + if (!*dest) + dest = "."; path = bltinlookup("CDPATH"); while (p = path, (len = padvance_magic(&path, dest, 0)) >= 0) { c = *p; p = stalloc(len); if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) { - if (c && c != ':') flags |= CD_PRINT; + if (c && c != ':') + flags |= CD_PRINT; docd: - if (!docd(p, flags)) goto out; + if (!docd(p, flags)) + goto out; goto err; } } @@ -2948,7 +3000,8 @@ err: sh_error("can't cd to %s", dest); __builtin_unreachable(); out: - if (flags & CD_PRINT) out1fmt(snlfmt, curdir); + if (flags & CD_PRINT) + out1fmt(snlfmt, curdir); return 0; } @@ -2963,10 +3016,12 @@ static int docd(const char *dest, int flags) { INTOFF; if (!(flags & CD_PHYSICAL)) { dir = updatepwd(dest); - if (dir) dest = dir; + if (dir) + dest = dir; } err = chdir(dest); - if (err) goto out; + if (err) + goto out; setpwd(dir, 1); hashcd(); out: @@ -2986,14 +3041,17 @@ static const char *updatepwd(const char *dir) { cdcomppath = sstrdup(dir); STARTSTACKSTR(new); if (*dir != '/') { - if (curdir == nullstr) return 0; + if (curdir == nullstr) + return 0; new = stputs(curdir, new); } new = makestrspace(strlen(dir) + 2, new); lim = (char *)stackblock() + 1; if (*dir != '/') { - if (new[-1] != '/') USTPUTC('/', new); - if (new > lim && *lim == '/') lim++; + if (new[-1] != '/') + USTPUTC('/', new); + if (new > lim &&*lim == '/') + lim++; } else { USTPUTC('/', new); cdcomppath++; @@ -3010,7 +3068,8 @@ static const char *updatepwd(const char *dir) { if (p[1] == '.' && p[2] == '\0') { while (new > lim) { STUNPUTC(new); - if (new[-1] == '/') break; + if (new[-1] == '/') + break; } break; } else if (p[1] == '\0') @@ -3022,7 +3081,8 @@ static const char *updatepwd(const char *dir) { } p = strtok(0, "/"); } - if (new > lim) STUNPUTC(new); + if (new > lim) + STUNPUTC(new); *new = 0; return stackblock(); } @@ -3033,7 +3093,8 @@ static const char *updatepwd(const char *dir) { */ static inline char *getpwd() { char buf[PATH_MAX]; - if (getcwd(buf, sizeof(buf))) return savestr(buf); + if (getcwd(buf, sizeof(buf))) + return savestr(buf); sh_warnx("getcwd() failed: %s", strerror(errno)); return nullstr; } @@ -3043,7 +3104,8 @@ static int pwdcmd(int argc, char **argv) { const char *dir = curdir; flags = cdopt(); if (flags) { - if (physdir == nullstr) setpwd(dir, 0); + if (physdir == nullstr) + setpwd(dir, 0); dir = physdir; } out1fmt(snlfmt, dir); @@ -3058,13 +3120,15 @@ static void setpwd(const char *val, int setold) { } INTOFF; if (physdir != nullstr) { - if (physdir != oldcur) free(physdir); + if (physdir != oldcur) + free(physdir); physdir = nullstr; } if (oldcur == val || !val) { char *s = getpwd(); physdir = s; - if (!val) dir = s; + if (!val) + dir = s; } else dir = savestr(val); if (oldcur != dir && oldcur != nullstr) { @@ -3093,9 +3157,11 @@ static void setpwd(const char *val, int setold) { static char *endofname(const char *name) { char *p; p = (char *)name; - if (!is_name(*p)) return p; + if (!is_name(*p)) + return p; while (*++p) { - if (!is_in_name(*p)) break; + if (!is_in_name(*p)) + break; } return p; } @@ -3127,7 +3193,8 @@ static int evaltree(union node *n, int flags) { unsigned isor; int status = 0; setstackmark(&smark); - if (nflag) goto out; + if (nflag) + goto out; if (n == NULL) { TRACE(("evaltree(NULL) called\n")); goto out; @@ -3141,12 +3208,14 @@ static int evaltree(union node *n, int flags) { goto setstatus; case NREDIR: errlinno = lineno = n->nredir.linno; - if (funcline) lineno -= funcline - 1; + if (funcline) + lineno -= funcline - 1; expredir(n->nredir.redirect); pushredir(n->nredir.redirect); status = (redirectsafe(n->nredir.redirect, REDIR_PUSH) ?: evaltree(n->nredir.n, flags & EV_TESTED)); - if (n->nredir.redirect) popredir(0); + if (n->nredir.redirect) + popredir(0); goto setstatus; case NCMD: evalfn = evalcommand; @@ -3176,7 +3245,8 @@ static int evaltree(union node *n, int flags) { isor = n->type - NAND; status = evaltree(n->nbinary.ch1, (flags | ((isor >> 1) - 1)) & EV_TESTED); - if ((!status) == isor || evalskip) break; + if ((!status) == isor || evalskip) + break; n = n->nbinary.ch2; evaln: evalfn = evaltree; @@ -3185,7 +3255,8 @@ static int evaltree(union node *n, int flags) { goto setstatus; case NIF: status = evaltree(n->nif.test, EV_TESTED); - if (evalskip) break; + if (evalskip) + break; if (!status) { n = n->nif.ifpart; goto evaln; @@ -3203,7 +3274,8 @@ static int evaltree(union node *n, int flags) { } out: dotrap(); - if (eflag && checkexit & status) goto exexit; + if (eflag && checkexit & status) + goto exexit; if (flags & EV_EXIT) { exexit: exraise(EXEND); @@ -3231,8 +3303,10 @@ static int evalstring(char *s, int flags) { for (; (n = parsecmd(0)) != NEOF; popstackmark(&smark)) { int i; i = evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); - if (n) status = i; - if (evalskip) break; + if (n) + status = i; + if (evalskip) + break; } popstackmark(&smark); popfile(); @@ -3251,7 +3325,8 @@ static int evalcmd(int argc, char **argv, int flags) { ap = argv + 2; for (;;) { concat = stputs(p, concat); - if ((p = *ap++) == NULL) break; + if ((p = *ap++) == NULL) + break; STPUTC(' ', concat); } STPUTC('\0', concat); @@ -3289,10 +3364,14 @@ static int evalloop(union node *n, int flags) { int i; i = evaltree(n->nbinary.ch1, EV_TESTED); skip = skiploop(); - if (skip == SKIPFUNC) status = i; - if (skip) continue; - if (n->type != NWHILE) i = !i; - if (i != 0) break; + if (skip == SKIPFUNC) + status = i; + if (skip) + continue; + if (n->type != NWHILE) + i = !i; + if (i != 0) + break; status = evaltree(n->nbinary.ch2, flags); skip = skiploop(); } while (!(skip & ~SKIPCONT)); @@ -3306,7 +3385,8 @@ static int evalfor(union node *n, int flags) { struct strlist *sp; int status; errlinno = lineno = n->nfor.linno; - if (funcline) lineno -= funcline - 1; + if (funcline) + lineno -= funcline - 1; arglist.lastp = &arglist.list; for (argp = n->nfor.args; argp; argp = argp->narg.next) { expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); @@ -3318,7 +3398,8 @@ static int evalfor(union node *n, int flags) { for (sp = arglist.list; sp; sp = sp->next) { setvar(n->nfor.var_, sp->text, 0); status = evaltree(n->nfor.body, flags); - if (skiploop() & ~SKIPCONT) break; + if (skiploop() & ~SKIPCONT) + break; } loopnest--; return status; @@ -3346,7 +3427,8 @@ static int evalcase(union node *n, int flags) { struct arglist arglist; int status = 0; errlinno = lineno = n->ncase.linno; - if (funcline) lineno -= funcline - 1; + if (funcline) + lineno -= funcline - 1; arglist.lastp = &arglist.list; expandarg(n->ncase.expr, &arglist, EXP_TILDE); for (cp = n->ncase.cases; cp && evalskip == 0; cp = cp->nclist.next) { @@ -3375,7 +3457,8 @@ static int evalsubshell(union node *n, int flags) { int backgnd = (n->type == NBACKGND); int status; errlinno = lineno = n->nredir.linno; - if (funcline) lineno -= funcline - 1; + if (funcline) + lineno -= funcline - 1; expredir(n->nredir.redirect); INTOFF; if (!backgnd && flags & EV_EXIT && !have_traps()) { @@ -3385,7 +3468,8 @@ static int evalsubshell(union node *n, int flags) { jp = makejob(n, 1); if (forkshell(jp, n, backgnd) == 0) { flags |= EV_EXIT; - if (backgnd) flags &= ~EV_TESTED; + if (backgnd) + flags &= ~EV_TESTED; nofork: INTON; redirect(n->nredir.redirect, 0); @@ -3393,7 +3477,8 @@ static int evalsubshell(union node *n, int flags) { /* never returns */ } status = 0; - if (!backgnd) status = waitforjob(jp); + if (!backgnd) + status = waitforjob(jp); INTON; return status; } @@ -3441,7 +3526,8 @@ static int evalpipe(union node *n, int flags) { int status = 0; TRACE(("evalpipe(0x%lx) called\n", (long)n)); pipelen = 0; - for (lp = n->npipe.cmdlist; lp; lp = lp->next) pipelen++; + for (lp = n->npipe.cmdlist; lp; lp = lp->next) + pipelen++; flags |= EV_EXIT; INTOFF; jp = makejob(n, pipelen); @@ -3471,7 +3557,8 @@ static int evalpipe(union node *n, int flags) { evaltreenr(lp->n, flags); /* never returns */ } - if (prevfd >= 0) close(prevfd); + if (prevfd >= 0) + close(prevfd); prevfd = pip[0]; close(pip[1]); } @@ -3499,7 +3586,8 @@ static void evalbackcmd(union node *n, struct backcmd *result) { if (n == NULL) { goto out; } - if (pipe(pip) < 0) sh_error("Pipe call failed"); + if (pipe(pip) < 0) + sh_error("Pipe call failed"); jp = makejob(n, 1); if (forkshell(jp, n, FORK_NOJOB) == 0) { FORCEINTON; @@ -3527,7 +3615,8 @@ static struct strlist *fill_arglist(struct arglist *arglist, while ((argp = *argpp)) { expandarg(argp, arglist, EXP_FULL | EXP_TILDE); *argpp = argp->narg.next; - if (*lastp) break; + if (*lastp) + break; } return *lastp; } @@ -3538,12 +3627,16 @@ static int parse_command_args(struct arglist *arglist, union node **argpp, char *cp, c; for (;;) { sp = unlikely(sp->next != NULL) ? sp->next : fill_arglist(arglist, argpp); - if (!sp) return 0; + if (!sp) + return 0; cp = sp->text; - if (*cp++ != '-') break; - if (!(c = *cp++)) break; + if (*cp++ != '-') + break; + if (!(c = *cp++)) + break; if (c == '-' && !*cp) { - if (likely(!sp->next) && !fill_arglist(arglist, argpp)) return 0; + if (likely(!sp->next) && !fill_arglist(arglist, argpp)) + return 0; sp = sp->next; break; } @@ -3588,7 +3681,8 @@ static int evalcommand(union node *cmd, int flags) { int vflags; int vlocal; errlinno = lineno = cmd->ncmd.linno; - if (funcline) lineno -= funcline - 1; + if (funcline) + lineno -= funcline - 1; /* First expand the arguments. */ TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); file_stop = parsefile; @@ -3614,16 +3708,19 @@ static int evalcommand(union node *cmd, int flags) { pathval()); vlocal++; /* implement bltin and command here */ - if (cmdentry.cmdtype != CMDBUILTIN) break; + if (cmdentry.cmdtype != CMDBUILTIN) + break; pseudovarflag = cmdentry.u.cmd->flags & BUILTIN_ASSIGN; if (likely(spclbltin < 0)) { spclbltin = cmdentry.u.cmd->flags & BUILTIN_SPECIAL; vlocal = spclbltin ^ BUILTIN_SPECIAL; } execcmd = cmdentry.u.cmd == EXECCMD; - if (likely(cmdentry.u.cmd != COMMANDCMD)) break; + if (likely(cmdentry.u.cmd != COMMANDCMD)) + break; cmd_flag = parse_command_args(&arglist, &argp, &path); - if (!cmd_flag) break; + if (!cmd_flag) + break; } for (; argp; argp = argp->narg.next) { expandarg(argp, &arglist, @@ -3631,8 +3728,10 @@ static int evalcommand(union node *cmd, int flags) { ? EXP_VARTILDE : EXP_FULL | EXP_TILDE); } - for (sp = arglist.list; sp; sp = sp->next) argc++; - if (execcmd && argc > 1) vflags = VEXPORT; + for (sp = arglist.list; sp; sp = sp->next) + argc++; + if (execcmd && argc > 1) + vflags = VEXPORT; } localvar_stop = pushlocalvars(vlocal); /* Reserve one extra spot at the front for shellexec. */ @@ -3644,7 +3743,8 @@ static int evalcommand(union node *cmd, int flags) { } *nargv = NULL; lastarg = NULL; - if (iflag && funcline == 0 && argc > 0) lastarg = nargv[-1]; + if (iflag && funcline == 0 && argc > 0) + lastarg = nargv[-1]; preverrout.fd = 2; expredir(cmd->ncmd.redirect); redir_stop = pushredir(cmd->ncmd.redirect); @@ -3653,7 +3753,8 @@ static int evalcommand(union node *cmd, int flags) { bail: exitstatus = status; /* We have a redirection error. */ - if (spclbltin > 0) exraise(EXERROR); + if (spclbltin > 0) + exraise(EXERROR); goto out; } for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { @@ -3707,13 +3808,15 @@ static int evalcommand(union node *cmd, int flags) { } break; case CMDFUNCTION: - if (evalfun(cmdentry.u.func, argc, argv, flags)) goto raise; + if (evalfun(cmdentry.u.func, argc, argv, flags)) + goto raise; break; } status = waitforjob(jp); FORCEINTON; out: - if (cmd->ncmd.redirect) popredir(execcmd); + if (cmd->ncmd.redirect) + popredir(execcmd); unwindredir(redir_stop); unwindfiles(file_stop); unwindlocalvars(localvar_stop); @@ -3737,7 +3840,8 @@ static int evalbltin(const struct builtincmd *cmd, int argc, char **argv, savecmdname = commandname; savehandler = handler; - if ((i = setjmp(jmploc.loc))) goto cmddone; + if ((i = setjmp(jmploc.loc))) + goto cmddone; handler = &jmploc; commandname = argv[0]; argptr = argv + 1; @@ -3747,7 +3851,8 @@ static int evalbltin(const struct builtincmd *cmd, int argc, char **argv, else status = (*cmd->builtin)(argc, argv); flushall(); - if (out1->flags) sh_warnx("%s: I/O error", commandname); + if (out1->flags) + sh_warnx("%s: I/O error", commandname); status |= out1->flags; exitstatus = status; cmddone: @@ -3762,7 +3867,8 @@ cmddone: * Free a parse tree. */ static void freefunc(struct funcnode *f) { - if (f && --f->count < 0) ckfree(f); + if (f && --f->count < 0) + ckfree(f); } static int evalfun(struct funcnode *func, int argc, char **argv, int flags) { @@ -3854,8 +3960,10 @@ static int bltincmd(int argc, char **argv) { */ static int breakcmd(int argc, char **argv) { int n = argc > 1 ? number(argv[1]) : 1; - if (n <= 0) badnum(argv[1]); - if (n > loopnest) n = loopnest; + if (n <= 0) + badnum(argv[1]); + if (n > loopnest) + n = loopnest; if (n > 0) { evalskip = (**argv == 'c') ? SKIPCONT : SKIPBREAK; skipcount = n; @@ -3931,7 +4039,8 @@ wontreturn static void shellexec(char **argv, const char *path, int idx) { cmdname = stackblock(); if (--idx < 0 && pathopt == NULL) { tryexec(cmdname, argv, envp); - if (errno != ENOENT && errno != ENOTDIR) e = errno; + if (errno != ENOENT && errno != ENOTDIR) + e = errno; } } } @@ -3968,7 +4077,8 @@ static const char *legal_pathopt(const char *opt, const char *term, int magic) { opt += strcspn(opt, term); break; } - if (opt && *opt == '%') opt++; + if (opt && *opt == '%') + opt++; return opt; } @@ -3993,7 +4103,8 @@ static int padvance_magic(const char **path, const char *name, int magic) { const char *start; unsigned qlen; unsigned len; - if (*path == NULL) return -1; + if (*path == NULL) + return -1; lpathopt = NULL; start = *path; if (*start == '%' && (p = legal_pathopt(start + 1, term, magic))) { @@ -4054,7 +4165,8 @@ static int hashcmd(int argc, char **argv) { delete_cmd_entry(); } find_command(name, &entry, DO_ERR, pathval()); - if (entry.cmdtype == CMDUNKNOWN) c = 1; + if (entry.cmdtype == CMDUNKNOWN) + c = 1; argptr++; } return c; @@ -4118,7 +4230,8 @@ static void find_command(char *name, struct cmdentry *entry, int act, return; } updatetbl = (path == pathval()); - if (!updatetbl) act |= DO_ALTPATH; + if (!updatetbl) + act |= DO_ALTPATH; /* If name is in the table, check answer will be ok */ if ((cmdp = cmdlookup(name, 0)) != NULL) { switch (cmdp->cmdtype) { @@ -4134,7 +4247,8 @@ static void find_command(char *name, struct cmdentry *entry, int act, break; } if (act & bit) { - if (act & bit & DO_REGBLTIN) goto fail; + if (act & bit & DO_REGBLTIN) + goto fail; updatetbl = 0; cmdp = NULL; } else if (cmdp->rehash == 0) { @@ -4148,7 +4262,8 @@ static void find_command(char *name, struct cmdentry *entry, int act, (builtinloc <= 0))) { goto builtin_success; } - if (act & DO_REGBLTIN) goto fail; + if (act & DO_REGBLTIN) + goto fail; /* We have to search path. */ prev = -1; /* where to start */ if (cmdp && cmdp->rehash) { /* doing a rehash */ @@ -4166,7 +4281,8 @@ loop: idx++; if (lpathopt) { if (*lpathopt == 'b') { - if (bcmd) goto builtin_success; + if (bcmd) + goto builtin_success; continue; } else if (!(act & DO_NOFUNC)) { /* handled below */ @@ -4177,16 +4293,19 @@ loop: } /* if rehash, don't redo absolute path names */ if (fullname[0] == '/' && idx <= prev) { - if (idx < prev) continue; + if (idx < prev) + continue; TRACE(("searchexec \"%s\": no change\n", name)); goto success; } while (stat(fullname, &statb) < 0) { - if (errno != ENOENT && errno != ENOTDIR) e = errno; + if (errno != ENOENT && errno != ENOTDIR) + e = errno; goto loop; } e = EACCES; /* if we fail, this will be the error */ - if (!S_ISREG(statb.st_mode)) continue; + if (!S_ISREG(statb.st_mode)) + continue; if (lpathopt) { /* this is a %func directory */ stalloc(len); readcmdfile(fullname); @@ -4210,8 +4329,10 @@ loop: goto success; } /* We failed. If there was an entry for this command, delete it */ - if (cmdp && updatetbl) delete_cmd_entry(); - if (act & DO_ERR) sh_warnx("%s: %s", name, errmsg(e, E_EXEC)); + if (cmdp && updatetbl) + delete_cmd_entry(); + if (act & DO_ERR) + sh_warnx("%s: %s", name, errmsg(e, E_EXEC)); fail: entry->cmdtype = CMDUNKNOWN; return; @@ -4269,7 +4390,8 @@ static void changepath(const char *newval) { break; } neu = strchr(neu, ':'); - if (!neu) break; + if (!neu) + break; idx++; neu++; } @@ -4318,11 +4440,13 @@ static struct tblentry *cmdlookup(const char *name, int add) { struct tblentry **pp; p = name; hashval = (unsigned char)*p << 4; - while (*p) hashval += (unsigned char)*p++; + while (*p) + hashval += (unsigned char)*p++; hashval &= 0x7FFF; pp = &cmdtable[hashval % CMDTABLESIZE]; for (cmdp = *pp; cmdp; cmdp = cmdp->next) { - if (equal(cmdp->cmdname, name)) break; + if (equal(cmdp->cmdname, name)) + break; pp = &cmdp->next; } if (add && cmdp == NULL) { @@ -4343,7 +4467,8 @@ static void delete_cmd_entry(void) { INTOFF; cmdp = *lastcmdentry; *lastcmdentry = cmdp->next; - if (cmdp->cmdtype == CMDFUNCTION) freefunc(cmdp->param.func); + if (cmdp->cmdtype == CMDFUNCTION) + freefunc(cmdp->param.func); ckfree(cmdp); INTON; } @@ -4591,7 +4716,8 @@ static char *argstr(char *p, int flag) { if (flag & EXP_TILDE) { flag &= ~EXP_TILDE; tilde: - if (*p == '~') p = exptilde(p, flag); + if (*p == '~') + p = exptilde(p, flag); } start: startloc = expdest - (char *)stackblock(); @@ -4623,7 +4749,8 @@ start: } p += length + 1; length = 0; - if (end) break; + if (end) + break; switch (c) { case '=': flag |= EXP_VARTILDE2; @@ -4684,7 +4811,8 @@ static char *exptilde(char *startp, int flag) { case CTLQUOTEMARK: return (startp); case ':': - if (flag & EXP_VARTILDE) goto done; + if (flag & EXP_VARTILDE) + goto done; break; case '/': case CTLENDVAR: @@ -4692,7 +4820,8 @@ static char *exptilde(char *startp, int flag) { } } done: - if (flag & EXP_DISCARD) goto out; + if (flag & EXP_DISCARD) + goto out; *p = '\0'; if (*name == '\0') { home = lookupvar(homestr); @@ -4700,7 +4829,8 @@ done: home = getpwhome(name); } *p = c; - if (!home) goto lose; + if (!home) + goto lose; strtodest(home, flag | EXP_QUOTED); out: return (p); @@ -4709,7 +4839,8 @@ lose: } static void removerecordregions(int endoff) { - if (ifslastp == NULL) return; + if (ifslastp == NULL) + return; if (ifsfirst.endoff > endoff) { while (ifsfirst.next != NULL) { struct ifsregion *ifsp; @@ -4739,7 +4870,8 @@ static void removerecordregions(int endoff) { ifslastp->next = ifsp; INTON; } - if (ifslastp->endoff > endoff) ifslastp->endoff = endoff; + if (ifslastp->endoff > endoff) + ifslastp->endoff = endoff; } /* @@ -4756,18 +4888,21 @@ static char *expari(char *start, int flag) { p = stackblock(); begoff = expdest - p; p = argstr(start, flag & EXP_DISCARD); - if (flag & EXP_DISCARD) goto out; + if (flag & EXP_DISCARD) + goto out; start = stackblock(); endoff = expdest - start; start += begoff; STADJUST(start - expdest, expdest); removerecordregions(begoff); - if (likely(flag & QUOTES_ESC)) rmescapes(start, 0); + if (likely(flag & QUOTES_ESC)) + rmescapes(start, 0); pushstackmark(&sm, endoff); result = arith(start); popstackmark(&sm); len = cvtnum(result, flag); - if (likely(!(flag & EXP_QUOTED))) recordregion(begoff, begoff + len, 0); + if (likely(!(flag & EXP_QUOTED))) + recordregion(begoff, begoff + len, 0); out: return p; } @@ -4783,7 +4918,8 @@ static void expbackq(union node *cmd, int flag) { char *dest; int startloc; struct stackmark smark; - if (flag & EXP_DISCARD) goto out; + if (flag & EXP_DISCARD) + goto out; INTOFF; startloc = expdest - (char *)stackblock(); pushstackmark(&smark, startloc); @@ -4791,19 +4927,23 @@ static void expbackq(union node *cmd, int flag) { popstackmark(&smark); p = in.buf; i = in.nleft; - if (i == 0) goto read; + if (i == 0) + goto read; for (;;) { memtodest(p, i, flag); read: - if (in.fd < 0) break; + if (in.fd < 0) + break; do { i = read(in.fd, buf, sizeof buf); } while (i < 0 && errno == EINTR); TRACE(("expbackq: read returns %d\n", i)); - if (i <= 0) break; + if (i <= 0) + break; p = buf; } - if (in.buf) ckfree(in.buf); + if (in.buf) + ckfree(in.buf); if (in.fd >= 0) { close(in.fd); back_exitstatus = waitforjob(in.jp); @@ -4843,8 +4983,10 @@ static char *scanleft(char *startp, char *rmesc, char *rmescend, char *str, } match = pmatch(str, s); *loc2 = c; - if (match) return loc; - if (quotes && *loc == (char)CTLESC) loc++; + if (match) + return loc; + if (quotes && *loc == (char)CTLESC) + loc++; loc++; loc2++; } while (c); @@ -4866,7 +5008,8 @@ static char *scanright(char *startp, char *rmesc, char *rmescend, char *str, } match = pmatch(str, s); *loc2 = c; - if (match) return loc; + if (match) + return loc; loc--; if (quotes) { if (--esc < 0) { @@ -4893,7 +5036,8 @@ static char *subevalvar(char *start, char *str, int strloc, int startloc, char *(*scan)(char *, char *, char *, char *, int, int); char *p; p = argstr(start, (flag & EXP_DISCARD) | EXP_TILDE | (str ? 0 : EXP_CASE)); - if (flag & EXP_DISCARD) return p; + if (flag & EXP_DISCARD) + return p; startp = (char *)stackblock() + startloc; switch (subtype) { case VSASSIGN: @@ -4959,7 +5103,8 @@ static char *evalvar(char *p, int flag) { p = strchr(p, '=') + 1; again: varlen = varvalue(var_, varflags, flag, quoted); - if (varflags & VSNUL) varlen--; + if (varflags & VSNUL) + varlen--; discard = varlen < 0 ? EXP_DISCARD : 0; switch (subtype) { case VSPLUS: @@ -4973,19 +5118,23 @@ again: case VSQUESTION: p = subevalvar(p, var_, 0, startloc, varflags, (flag & ~QUOTES_ESC) | (discard ^ EXP_DISCARD)); - if ((flag | ~discard) & EXP_DISCARD) goto record; + if ((flag | ~discard) & EXP_DISCARD) + goto record; varflags &= ~VSNUL; subtype = VSNORMAL; goto again; } - if ((discard & ~flag) && uflag) varunset(p, var_, 0, 0); + if ((discard & ~flag) && uflag) + varunset(p, var_, 0, 0); if (subtype == VSLENGTH) { p++; - if (flag & EXP_DISCARD) return p; + if (flag & EXP_DISCARD) + return p; cvtnum(varlen > 0 ? varlen : 0, flag); goto really_record; } - if (subtype == VSNORMAL) goto record; + if (subtype == VSNORMAL) + goto record; flag |= discard; if (!(flag & EXP_DISCARD)) { /* @@ -4997,11 +5146,13 @@ again: patloc = expdest - (char *)stackblock(); p = subevalvar(p, NULL, patloc, startloc, varflags, flag); record: - if ((flag | discard) & EXP_DISCARD) return p; + if ((flag | discard) & EXP_DISCARD) + return p; really_record: if (quoted) { quoted = *var_ == '@' && shellparam.nparam; - if (!quoted) return p; + if (!quoted) + return p; } recordregion(startloc, expdest - (char *)stackblock(), quoted); return p; @@ -5014,7 +5165,8 @@ static unsigned memtodest(const char *p, unsigned len, int flags) { const char *syntax = flags & EXP_QUOTED ? DQSYNTAX : BASESYNTAX; char *q; char *s; - if (unlikely(!len)) return 0; + if (unlikely(!len)) + return 0; q = makestrspace(len * 2, expdest); s = q; do { @@ -5054,7 +5206,8 @@ static long varvalue(char *name, int varflags, int flags, int quoted) { long len = 0; char c; if (!subtype) { - if (discard) return -1; + if (discard) + return -1; sh_error("Bad substitution"); } flags |= EXP_KEEPNUL; @@ -5072,7 +5225,8 @@ static long varvalue(char *name, int varflags, int flags, int quoted) { goto numvar; case '!': num = backgndpid; - if (num == 0) return -1; + if (num == 0) + return -1; numvar: len = cvtnum(num, flags); break; @@ -5087,7 +5241,8 @@ static long varvalue(char *name, int varflags, int flags, int quoted) { expdest = p; break; case '@': - if (quoted && sep) goto param; + if (quoted && sep) + goto param; /* fall through */ case '*': /* We will set c to 0 or ~0 depending on whether @@ -5110,7 +5265,8 @@ static long varvalue(char *name, int varflags, int flags, int quoted) { sep |= ifsset() ? (unsigned char)(c & ifsval()[0]) : ' '; param: sepc = sep; - if (!(ap = shellparam.p)) return -1; + if (!(ap = shellparam.p)) + return -1; while ((p = *ap++)) { len += strtodest(p, flags); if (*ap && sep) { @@ -5130,17 +5286,20 @@ static long varvalue(char *name, int varflags, int flags, int quoted) { case '8': case '9': num = atoi(name); - if (num < 0 || num > shellparam.nparam) return -1; + if (num < 0 || num > shellparam.nparam) + return -1; p = num ? shellparam.p[num - 1] : arg0; goto value; default: p = lookupvar(name); value: - if (!p) return -1; + if (!p) + return -1; len = strtodest(p, flags); break; } - if (discard) STADJUST(-len, expdest); + if (discard) + STADJUST(-len, expdest); return len; } @@ -5201,10 +5360,12 @@ static void ifsbreakup(char *string, int maxargs, struct arglist *arglist) { bool isdefifs; q = p; c = *p++; - if (c == (char)CTLESC) c = *p++; + if (c == (char)CTLESC) + c = *p++; isifs = !!strchr(ifs, c); isdefifs = false; - if (isifs) isdefifs = !!strchr(defifs, c); + if (isifs) + isdefifs = !!strchr(defifs, c); /* If only reading one more argument: * If we have exactly one field, * read that field without its terminator. @@ -5226,21 +5387,26 @@ static void ifsbreakup(char *string, int maxargs, struct arglist *arglist) { */ if (!maxargs) { if (isdefifs) { - if (!r) r = q; + if (!r) + r = q; continue; } - if (!(isifs && ifsspc)) r = NULL; + if (!(isifs && ifsspc)) + r = NULL; ifsspc = 0; continue; } if (ifsspc) { - if (isifs) q = p; + if (isifs) + q = p; start = q; - if (isdefifs) continue; + if (isdefifs) + continue; isifs = false; } if (isifs) { - if (!(afternul || nulonly)) ifsspc = isdefifs; + if (!(afternul || nulonly)) + ifsspc = isdefifs; /* Ignore IFS whitespace at start */ if (q == start && ifsspc) { start = p; @@ -5262,10 +5428,13 @@ static void ifsbreakup(char *string, int maxargs, struct arglist *arglist) { ifsspc = 0; } } while ((ifsp = ifsp->next) != NULL); - if (nulonly) goto add; + if (nulonly) + goto add; } - if (r) *r = '\0'; - if (!*start) return; + if (r) + *r = '\0'; + if (!*start) + return; add: sp = (struct strlist *)stalloc(sizeof *sp); sp->text = start; @@ -5285,8 +5454,10 @@ static void expandmeta(struct strlist *str) { struct strlist *sp; char *p; unsigned len; - if (fflag) goto nometa; - if (!strpbrk(str->text, metachars)) goto nometa; + if (fflag) + goto nometa; + if (!strpbrk(str->text, metachars)) + goto nometa; savelastp = exparg.lastp; INTOFF; p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP); @@ -5295,7 +5466,8 @@ static void expandmeta(struct strlist *str) { expdir = ckmalloc(expdir_max); expmeta(p, len, 0); ckfree(expdir); - if (p != str->text) ckfree(p); + if (p != str->text) + ckfree(p); INTON; if (exparg.lastp == savelastp) { /* @@ -5308,7 +5480,8 @@ static void expandmeta(struct strlist *str) { } else { *exparg.lastp = NULL; *savelastp = sp = expsort(*savelastp); - while (sp->next != NULL) sp = sp->next; + while (sp->next != NULL) + sp = sp->next; exparg.lastp = &sp->next; } str = str->next; @@ -5338,46 +5511,57 @@ static void expmeta(char *name, unsigned name_len, unsigned expdir_len) { metaflag = 1; else if (*p == '[') { char *q = p + 1; - if (*q == '!') q++; + if (*q == '!') + q++; for (;;) { - if (*q == '\\') q++; - if (*q == '/' || *q == '\0') break; + if (*q == '\\') + q++; + if (*q == '/' || *q == '\0') + break; if (*++q == ']') { metaflag = 1; break; } } } else { - if (*p == '\\' && p[1]) esc++; + if (*p == '\\' && p[1]) + esc++; if (p[esc] == '/') { - if (metaflag) break; + if (metaflag) + break; start = p + esc + 1; } } } if (metaflag == 0) { /* we've reached the end of the file name */ - if (!expdir_len) return; + if (!expdir_len) + return; p = name; do { - if (*p == '\\' && p[1]) p++; + if (*p == '\\' && p[1]) + p++; *enddir++ = *p; } while (*p++); - if (lstat(expdir, &statb) >= 0) addfname(expdir); + if (lstat(expdir, &statb) >= 0) + addfname(expdir); return; } endname = p; if (name < start) { p = name; do { - if (*p == '\\' && p[1]) p++; + if (*p == '\\' && p[1]) + p++; *enddir++ = *p++; } while (p < start); } *enddir = 0; cp = expdir; expdir_len = enddir - cp; - if (!expdir_len) cp = "."; - if ((dirp = opendir(cp)) == NULL) return; + if (!expdir_len) + cp = "."; + if ((dirp = opendir(cp)) == NULL) + return; if (*endname == 0) { atend = 1; } else { @@ -5388,10 +5572,13 @@ static void expmeta(char *name, unsigned name_len, unsigned expdir_len) { name_len -= endname - name; matchdot = 0; p = start; - if (*p == '\\') p++; - if (*p == '.') matchdot++; + if (*p == '\\') + p++; + if (*p == '.') + matchdot++; while (!int_pending() && (dp = readdir(dirp)) != NULL) { - if (dp->d_name[0] == '.' && !matchdot) continue; + if (dp->d_name[0] == '.' && !matchdot) + continue; if (pmatch(start, dp->d_name)) { if (atend) { scopy(dp->d_name, enddir); @@ -5414,7 +5601,8 @@ static void expmeta(char *name, unsigned name_len, unsigned expdir_len) { } } closedir(dirp); - if (!atend) endname[-esc - 1] = esc ? '\\' : '/'; + if (!atend) + endname[-esc - 1] = esc ? '\\' : '/'; } /* @@ -5437,7 +5625,8 @@ static struct strlist *expsort(struct strlist *str) { int len; struct strlist *sp; len = 0; - for (sp = str; sp; sp = sp->next) len++; + for (sp = str; sp; sp = sp->next) + len++; return msort(str, len); } @@ -5446,7 +5635,8 @@ static struct strlist *msort(struct strlist *list, int len) { struct strlist **lpp; int half; int n; - if (len <= 1) return list; + if (len <= 1) + return list; half = len >> 1; p = list; for (n = half; --n >= 0;) { @@ -5505,7 +5695,8 @@ static int ccmatch(const char *p, int chr, const char **r) { for (class = classes; class < end; class ++) { const char *q; q = prefix(p, class->name); - if (!q) continue; + if (!q) + continue; *r = q; return class->fn(chr); } @@ -5528,19 +5719,23 @@ static int pmatch(const char *pattern, const char *string) { } goto dft; case '?': - if (*q++ == '\0') return 0; + if (*q++ == '\0') + return 0; break; case '*': c = *p; - while (c == '*') c = *++p; + while (c == '*') + c = *++p; if (c != '\\' && c != '?' && c != '*' && c != '[') { while (*q != c) { - if (*q == '\0') return 0; + if (*q == '\0') + return 0; q++; } } do { - if (pmatch(p, q)) return 1; + if (pmatch(p, q)) + return 1; } while (*q++ != '\0'); return 0; case '[': { @@ -5555,7 +5750,8 @@ static int pmatch(const char *pattern, const char *string) { } found = 0; chr = *q; - if (chr == '\0') return 0; + if (chr == '\0') + return 0; c = *p++; do { if (!c) { @@ -5574,25 +5770,31 @@ static int pmatch(const char *pattern, const char *string) { c = *p++; if (*p == '-' && p[1] != ']') { p++; - if (*p == '\\') p++; - if (chr >= c && chr <= *p) found = 1; + if (*p == '\\') + p++; + if (chr >= c && chr <= *p) + found = 1; p++; } else { - if (chr == c) found = 1; + if (chr == c) + found = 1; } } while ((c = *p++) != ']'); - if (found == invert) return 0; + if (found == invert) + return 0; q++; break; } dft: default: - if (*q++ != c) return 0; + if (*q++ != c) + return 0; break; } } breakloop: - if (*q != '\0') return 0; + if (*q != '\0') + return 0; return 1; } @@ -5642,7 +5844,8 @@ static char *rmescapes(char *str, int flag) { } if (*p == (char)CTLESC) { p++; - if (notescaped) *q++ = '\\'; + if (notescaped) + *q++ = '\\'; } notescaped = globbing; copy: @@ -5672,11 +5875,13 @@ static void freestrings(struct strpush *sp) { struct strpush *psp; if (sp->ap) { sp->ap->flag &= ~ALIASINUSE; - if (sp->ap->flag & ALIASDEAD) unalias(sp->ap->name); + if (sp->ap->flag & ALIASDEAD) + unalias(sp->ap->name); } psp = sp; sp = sp->spfree; - if (psp != &(parsefile->basestrpush)) ckfree(psp); + if (psp != &(parsefile->basestrpush)) + ckfree(psp); } while (sp); parsefile->spfree = NULL; INTON; @@ -5684,7 +5889,8 @@ static void freestrings(struct strpush *sp) { static int pgetc_nofree(void) { int c; - if (parsefile->unget) return parsefile->lastc[--parsefile->unget]; + if (parsefile->unget) + return parsefile->lastc[--parsefile->unget]; if (--parsefile->nleft >= 0) c = (signed char)*parsefile->nextc++; else @@ -5700,13 +5906,15 @@ static int pgetc_nofree(void) { */ int pgetc(void) { struct strpush *sp = parsefile->spfree; - if (unlikely(sp)) freestrings(sp); + if (unlikely(sp)) + freestrings(sp); return pgetc_nofree(); } static void AddUniqueCompletion(linenoiseCompletions *c, char *s) { size_t i; - if (!s) return; + if (!s) + return; for (i = 0; i < c->len; ++i) { if (!strcmp(s, c->cvec[i])) { return; @@ -5765,8 +5973,10 @@ static void CompleteFilename(const char *p, const char *q, const char *b, } if ((d = opendir(buf))) { while ((e = readdir(d))) { - if (!strcmp(e->d_name, ".")) continue; - if (!strcmp(e->d_name, "..")) continue; + if (!strcmp(e->d_name, ".")) + continue; + if (!strcmp(e->d_name, "..")) + continue; if (!strncmp(e->d_name, p, q - p)) { snprintf(buf, 512, "%.*s%s%s", p - b, b, e->d_name, e->d_type == DT_DIR ? "/" : ""); @@ -5783,7 +5993,8 @@ static void ShellCompletion(const char *p, linenoiseCompletions *c) { bool slashed; const char *q, *b; for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) { - if (p[-1] == '/' && p[-1] == '\\') slashed = true; + if (p[-1] == '/' && p[-1] == '\\') + slashed = true; if (!isalnum(p[-1]) && (p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' && p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) { @@ -5835,7 +6046,8 @@ retry: nr = read(parsefile->fd, buf, IBUFSIZ - 1); } if (nr < 0) { - if (errno == EINTR) goto retry; + if (errno == EINTR) + goto retry; if (parsefile->fd == 0 && errno == EAGAIN) { int flags = fcntl(0, F_GETFL, 0); if (flags >= 0 && flags & O_NONBLOCK) { @@ -5895,7 +6107,8 @@ static int preadbuffer(void) { } if (more <= 0) { parsefile->nleft = q - parsefile->nextc - 1; - if (parsefile->nleft < 0) goto again; + if (parsefile->nleft < 0) + goto again; break; } } @@ -5979,8 +6192,10 @@ static int setinputfile(const char *fname, int flags) { int fd; INTOFF; fd = sh_open(fname, O_RDONLY, flags & INPUT_NOFILE_OK); - if (fd < 0) goto out; - if (fd < 10) fd = savefd(fd, fd); + if (fd < 0) + goto out; + if (fd < 10) + fd = savefd(fd, fd); setinputfd(fd, flags & INPUT_PUSH_FILE); out: INTON; @@ -5997,7 +6212,8 @@ static void setinputfd(int fd, int push) { parsefile->buf = 0; } parsefile->fd = fd; - if (parsefile->buf == NULL) parsefile->buf = ckmalloc(IBUFSIZ); + if (parsefile->buf == NULL) + parsefile->buf = ckmalloc(IBUFSIZ); parsefile->lleft = parsefile->nleft = 0; plinno = 1; } @@ -6034,9 +6250,12 @@ static void pushfile(void) { static void popfile(void) { struct parsefile *pf = parsefile; INTOFF; - if (pf->fd >= 0) close(pf->fd); - if (pf->buf) ckfree(pf->buf); - if (parsefile->spfree) freestrings(parsefile->spfree); + if (pf->fd >= 0) + close(pf->fd); + if (pf->buf) + ckfree(pf->buf); + if (parsefile->spfree) + freestrings(parsefile->spfree); while (pf->strpush) { popstring(); freestrings(parsefile->spfree); @@ -6047,7 +6266,8 @@ static void popfile(void) { } static void unwindfiles(struct parsefile *stop) { - while (parsefile != stop) popfile(); + while (parsefile != stop) + popfile(); } /* @@ -6083,7 +6303,8 @@ static void set_curjob(struct job *jp, unsigned mode) { jpp = curp = &curjob; do { jp1 = *jpp; - if (jp1 == jp) break; + if (jp1 == jp) + break; jpp = &jp1->prev_job; } while (1); *jpp = jp1->prev_job; @@ -6099,7 +6320,8 @@ static void set_curjob(struct job *jp, unsigned mode) { put after all stopped jobs. */ do { jp1 = *jpp; - if (!JOBS || !jp1 || jp1->state != JOBSTOPPED) break; + if (!JOBS || !jp1 || jp1->state != JOBSTOPPED) + break; jpp = &jp1->prev_job; } while (1); /* FALLTHROUGH */ @@ -6123,15 +6345,18 @@ static void set_curjob(struct job *jp, unsigned mode) { static void setjobctl(int on) { int fd; int pgrp; - if (IsWindows()) return; /* TODO(jart) */ - if (on == jobctl || rootshell == 0) return; + if (IsWindows()) + return; /* TODO(jart) */ + if (on == jobctl || rootshell == 0) + return; if (on) { int ofd; ofd = fd = sh_open(_PATH_TTY, O_RDWR, 1); if (fd < 0) { fd += 3; while (!isatty(fd)) - if (--fd < 0) goto out; + if (--fd < 0) + goto out; } fd = savefd(fd, ofd); do { /* while we are in the background */ @@ -6141,7 +6366,8 @@ static void setjobctl(int on) { mflag = on = 0; goto close; } - if (pgrp == getpgrp()) break; + if (pgrp == getpgrp()) + break; killpg(0, SIGTTIN); } while (1); initialpgrp = pgrp; @@ -6172,7 +6398,8 @@ static int decode_signum(const char *string) { int signo = -1; if (is_number(string)) { signo = atoi(string); - if (signo >= NSIG) signo = -1; + if (signo >= NSIG) + signo = -1; } return signo; } @@ -6195,7 +6422,8 @@ char **argv; signo = decode_signal(*argv + 1, 1); if (signo < 0) { int c; - while ((c = nextopt("ls:")) != '\0') switch (c) { + while ((c = nextopt("ls:")) != '\0') + switch (c) { default: case 'l': list = 1; @@ -6211,7 +6439,8 @@ char **argv; } else argv++; } - if (!list && signo < 0) signo = SIGTERM; + if (!list && signo < 0) + signo = SIGTERM; if ((signo < 0 || !*argv) ^ list) { goto usage; } @@ -6226,7 +6455,8 @@ char **argv; return 0; } signo = number(*argv); - if (signo > 128) signo -= 128; + if (signo > 128) + signo -= 128; if (0 < signo && signo < NSIG) outfmt(out, snlfmt, strsignal(signo)); else @@ -6282,10 +6512,12 @@ static int restartjob(struct job *jp, int mode) { int status; int pgid; INTOFF; - if (jp->state == JOBDONE) goto out; + if (jp->state == JOBDONE) + goto out; jp->state = JOBRUNNING; pgid = jp->ps->pid; - if (mode == FORK_FG) xtcsetpgrp(ttyfd, pgid); + if (mode == FORK_FG) + xtcsetpgrp(ttyfd, pgid); killpg(pgid, SIGCONT); ps = jp->ps; i = jp->nprocs; @@ -6306,10 +6538,13 @@ static int sprint_status(char *os, int status, int sigonly) { st = WEXITSTATUS(status); if (!WIFEXITED(status)) { st = WSTOPSIG(status); - if (!WIFSTOPPED(status)) st = WTERMSIG(status); + if (!WIFSTOPPED(status)) + st = WTERMSIG(status); if (sigonly) { - if (st == SIGINT || st == SIGPIPE) goto out; - if (WIFSTOPPED(status)) goto out; + if (st == SIGINT || st == SIGPIPE) + goto out; + if (WIFSTOPPED(status)) + goto out; } s = stpncpy(s, strsignal(st), 32); } else if (!sigonly) { @@ -6340,14 +6575,16 @@ static void showjob(struct output *out, struct job *jp, int mode) { s[col - 2] = '+'; else if (curjob && jp == curjob->prev_job) s[col - 2] = '-'; - if (mode & SHOW_PID) col += fmtstr(s + col, 16, "%d ", ps->pid); + if (mode & SHOW_PID) + col += fmtstr(s + col, 16, "%d ", ps->pid); psend = ps + jp->nprocs; if (jp->state == JOBRUNNING) { scopy("Running", s + col); col += strlen("Running"); } else { int status = psend[-1].status; - if (jp->state == JOBSTOPPED) status = jp->stopstatus; + if (jp->state == JOBSTOPPED) + status = jp->stopstatus; col += sprint_status(s + col, status, 0); } goto start; @@ -6383,7 +6620,8 @@ static int jobscmd(int argc, char **argv) { mode = SHOW_PGID; out = out1; argv = argptr; - if (*argv) do + if (*argv) + do showjob(out, getjob(*argv, 0), mode); while (*++argv); else @@ -6401,7 +6639,8 @@ static void showjobs(struct output *out, int mode) { /* If not even one job changed, there is nothing to do */ dowait(DOWAIT_NONBLOCK, NULL); for (jp = curjob; jp; jp = jp->prev_job) { - if (!(mode & SHOW_CHANGED) || jp->changed) showjob(out, jp, mode); + if (!(mode & SHOW_CHANGED) || jp->changed) + showjob(out, jp, mode); } } @@ -6413,9 +6652,11 @@ static void freejob(struct job *jp) { int i; INTOFF; for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) { - if (ps->cmd != nullstr) ckfree(ps->cmd); + if (ps->cmd != nullstr) + ckfree(ps->cmd); } - if (jp->ps != &jp->ps0) ckfree(jp->ps); + if (jp->ps != &jp->ps0) + ckfree(jp->ps); jp->used = 0; set_curjob(jp, CUR_DELETE); INTON; @@ -6437,11 +6678,13 @@ static int waitcmd(int argc, char **argv) { /* no running procs */ goto out; } - if (jp->state == JOBRUNNING) break; + if (jp->state == JOBRUNNING) + break; jp->waited = 1; jp = jp->prev_job; } - if (!dowait(DOWAIT_WAITCMD_ALL, 0)) goto sigout; + if (!dowait(DOWAIT_WAITCMD_ALL, 0)) + goto sigout; } } retval = 127; @@ -6451,15 +6694,18 @@ static int waitcmd(int argc, char **argv) { job = curjob; goto start; do { - if (job->ps[job->nprocs - 1].pid == pid) break; + if (job->ps[job->nprocs - 1].pid == pid) + break; job = job->prev_job; start: - if (!job) goto repeat; + if (!job) + goto repeat; } while (1); } else job = getjob(*argv, 0); /* loop until process terminated or stopped */ - if (!dowait(DOWAIT_WAITCMD, job)) goto sigout; + if (!dowait(DOWAIT_WAITCMD, job)) + goto sigout; job->waited = 1; retval = getstatus(job); repeat:; @@ -6484,20 +6730,25 @@ static struct job *getjob(const char *name, int getctl) { char *(*match)(const char *, const char *); jp = curjob; p = name; - if (!p) goto currentjob; - if (*p != '%') goto err; + if (!p) + goto currentjob; + if (*p != '%') + goto err; c = *++p; - if (!c) goto currentjob; + if (!c) + goto currentjob; if (!p[1]) { if (c == '+' || c == '%') { currentjob: err_msg = "No current job"; goto check; } else if (c == '-') { - if (jp) jp = jp->prev_job; + if (jp) + jp = jp->prev_job; err_msg = "No previous job"; check: - if (!jp) goto err; + if (!jp) + goto err; goto gotit; } } @@ -6505,7 +6756,8 @@ static struct job *getjob(const char *name, int getctl) { num = atoi(p); if (num > 0 && num <= njobs) { jp = jobtab + num - 1; - if (jp->used) goto gotit; + if (jp->used) + goto gotit; goto err; } } @@ -6517,17 +6769,20 @@ static struct job *getjob(const char *name, int getctl) { found = 0; while (jp) { if (match(jp->ps[0].cmd, p)) { - if (found) goto err; + if (found) + goto err; found = jp; err_msg = "%s: ambiguous"; } jp = jp->prev_job; } - if (!found) goto err; + if (!found) + goto err; jp = found; gotit: err_msg = "job %s not created under job control"; - if (getctl && jp->jobctl == 0) goto err; + if (getctl && jp->jobctl == 0) + goto err; return jp; err: sh_error(err_msg, name); @@ -6545,14 +6800,18 @@ struct job *makejob(union node *node, int nprocs) { jp = growjobtab(); break; } - if (jp->used == 0) break; - if (jp->state != JOBDONE || !jp->waited) continue; - if (jobctl) continue; + if (jp->used == 0) + break; + if (jp->state != JOBDONE || !jp->waited) + continue; + if (jobctl) + continue; freejob(jp); break; } memset(jp, 0, sizeof(*jp)); - if (jobctl) jp->jobctl = 1; + if (jobctl) + jp->jobctl = 1; jp->prev_job = curjob; curjob = jp; jp->used = 1; @@ -6585,10 +6844,13 @@ static struct job *growjobtab(void) { jq--; #define joff(p) ((struct job *)((char *)(p) + l)) #define jmove(p) (p) = (void *)((char *)(p) + offset) - if (likely(joff(jp)->ps == &jq->ps0)) jmove(joff(jp)->ps); - if (joff(jp)->prev_job) jmove(joff(jp)->prev_job); + if (likely(joff(jp)->ps == &jq->ps0)) + jmove(joff(jp)->ps); + if (joff(jp)->prev_job) + jmove(joff(jp)->prev_job); } - if (curjob) jmove(curjob); + if (curjob) + jmove(curjob); #undef joff #undef jmove } @@ -6638,7 +6900,8 @@ static void forkchild(struct job *jp, union node *n, int mode) { pgrp = jp->ps[0].pid; /* This can fail because we are doing it in the parent also */ (void)setpgid(0, pgrp); - if (mode == FORK_FG) xtcsetpgrp(ttyfd, pgrp); + if (mode == FORK_FG) + xtcsetpgrp(ttyfd, pgrp); setsignal(SIGTSTP); setsignal(SIGTTOU); } else if (mode == FORK_BG) { @@ -6654,19 +6917,23 @@ static void forkchild(struct job *jp, union node *n, int mode) { setsignal(SIGQUIT); setsignal(SIGTERM); } - if (lvforked) return; - for (jp = curjob; jp; jp = jp->prev_job) freejob(jp); + if (lvforked) + return; + for (jp = curjob; jp; jp = jp->prev_job) + freejob(jp); } static void forkparent(struct job *jp, union node *n, int mode, int pid) { if (pid < 0) { TRACE(("Fork failed, errno=%d", errno)); - if (jp) freejob(jp); + if (jp) + freejob(jp); sh_error("Cannot fork"); __builtin_unreachable(); } TRACE(("In parent shell: child = %d\n", pid)); - if (!jp) return; + if (!jp) + return; if (mode != FORK_NOJOB && jp->jobctl) { int pgrp; if (jp->nprocs == 0) @@ -6685,7 +6952,8 @@ static void forkparent(struct job *jp, union node *n, int mode, int pid) { ps->pid = pid; ps->status = -1; ps->cmd = nullstr; - if (jobctl && n) ps->cmd = commandtext(n); + if (jobctl && n) + ps->cmd = commandtext(n); } } @@ -6745,7 +7013,8 @@ static int waitforjob(struct job *jp) { int st; TRACE(("waitforjob(%%%d) called\n", jp ? jobno(jp) : 0)); dowait(jp ? DOWAIT_BLOCK : DOWAIT_NONBLOCK, jp); - if (!jp) return exitstatus; + if (!jp) + return exitstatus; st = getstatus(jp); if (jp->jobctl) { xtcsetpgrp(ttyfd, rootpid); @@ -6757,9 +7026,11 @@ static int waitforjob(struct job *jp) { * intuit from the subprocess exit status whether a SIGINT * occurred, and if so interrupt ourselves. Yuck. - mycroft */ - if (jp->sigint) raise(SIGINT); + if (jp->sigint) + raise(SIGINT); } - if (!JOBS || jp->state == JOBDONE) freejob(jp); + if (!JOBS || jp->state == JOBDONE) + freejob(jp); return st; } @@ -6776,11 +7047,13 @@ static int waitone(int block, struct job *job) { TRACE(("dowait(%d) called\n", block)); pid = waitproc(block, &status); TRACE(("wait returns pid %d, status=%d\n", pid, status)); - if (pid <= 0) goto out; + if (pid <= 0) + goto out; for (jp = curjob; jp; jp = jp->prev_job) { struct procstat *sp; struct procstat *spend; - if (jp->state == JOBDONE) continue; + if (jp->state == JOBDONE) + continue; state = JOBDONE; spend = jp->ps + jp->nprocs; sp = jp->ps; @@ -6791,14 +7064,17 @@ static int waitone(int block, struct job *job) { sp->status = status; thisjob = jp; } - if (sp->status == -1) state = JOBRUNNING; - if (state == JOBRUNNING) continue; + if (sp->status == -1) + state = JOBRUNNING; + if (state == JOBRUNNING) + continue; if (WIFSTOPPED(sp->status)) { jp->stopstatus = sp->status; state = JOBSTOPPED; } } while (++sp < spend); - if (thisjob) goto gotjob; + if (thisjob) + goto gotjob; } goto out; gotjob: @@ -6832,14 +7108,17 @@ static int dowait(int block, struct job *jp) { int gotchld = *(volatile int *)&gotsigchld; int rpid; int pid; - if (jp && jp->state != JOBRUNNING) block = DOWAIT_NONBLOCK; - if (block == DOWAIT_NONBLOCK && !gotchld) return 1; + if (jp && jp->state != JOBRUNNING) + block = DOWAIT_NONBLOCK; + if (block == DOWAIT_NONBLOCK && !gotchld) + return 1; rpid = 1; do { pid = waitone(block, jp); rpid &= !!pid; block &= ~DOWAIT_WAITCMD_ALL; - if (!pid || (jp && jp->state != JOBRUNNING)) block = DOWAIT_NONBLOCK; + if (!pid || (jp && jp->state != JOBRUNNING)) + block = DOWAIT_NONBLOCK; } while (pid >= 0); return rpid; } @@ -6862,14 +7141,18 @@ static int waitproc(int block, int *status) { sigset_t oldmask; int flags = block == DOWAIT_BLOCK ? 0 : WNOHANG; int err; - if (jobctl) flags |= WUNTRACED; + if (jobctl) + flags |= WUNTRACED; do { gotsigchld = 0; - do err = wait3(status, flags, NULL); + do + err = wait3(status, flags, NULL); while (err < 0 && errno == EINTR); - if (err || (err = -!block)) break; + if (err || (err = -!block)) + break; sigblockall(&oldmask); - while (!gotsigchld && !pending_sig) sigsuspend(&oldmask); + while (!gotsigchld && !pending_sig) + sigsuspend(&oldmask); sigclearmask(); } while (gotsigchld); return err; @@ -6882,7 +7165,8 @@ static int stoppedjobs(void) { struct job *jp; int retval; retval = 0; - if (job_warning) goto out; + if (job_warning) + goto out; jp = curjob; if (jp && jp->state == JOBSTOPPED) { outstr("You have stopped jobs.\n", out2); @@ -6911,7 +7195,8 @@ static void cmdtxt(union node *n) { struct nodelist *lp; const char *p; char s[2]; - if (!n) return; + if (!n) + return; switch (n->type) { default: case NPIPE: @@ -6919,7 +7204,8 @@ static void cmdtxt(union node *n) { for (;;) { cmdtxt(lp->n); lp = lp->next; - if (!lp) break; + if (!lp) + break; cmdputs(" | "); } break; @@ -7054,9 +7340,11 @@ static void cmdtxt(union node *n) { static void cmdlist(union node *np, int sep) { for (; np; np = np->narg.next) { - if (!sep) cmdputs(spcstr); + if (!sep) + cmdputs(spcstr); cmdtxt(np); - if (sep && np->narg.next) cmdputs(spcstr); + if (sep && np->narg.next) + cmdputs(spcstr); } } @@ -7104,8 +7392,10 @@ static void cmdputs(const char *s) { c = '"'; break; case '=': - if (subtype == 0) break; - if ((subtype & VSTYPE) != VSNORMAL) quoted <<= 1; + if (subtype == 0) + break; + if ((subtype & VSTYPE) != VSNORMAL) + quoted <<= 1; str = vstype[subtype & VSTYPE]; if (subtype & VSNUL) c = ':'; @@ -7126,7 +7416,8 @@ static void cmdputs(const char *s) { } USTPUTC(c, nextc); checkstr: - if (!str) continue; + if (!str) + continue; dostr: while ((c = *str++)) { USTPUTC(c, nextc); @@ -7143,7 +7434,8 @@ static void showpipe(struct job *jp, struct output *out) { struct procstat *sp; struct procstat *spend; spend = jp->ps + jp->nprocs; - for (sp = jp->ps + 1; sp < spend; sp++) outfmt(out, " | %s", sp->cmd); + for (sp = jp->ps + 1; sp < spend; sp++) + outfmt(out, " | %s", sp->cmd); outcslow('\n', out); flushall(); } @@ -7153,7 +7445,8 @@ static void xtcsetpgrp(int fd, int pgrp) { sigblockall(NULL); err = tcsetpgrp(fd, pgrp); sigclearmask(); - if (err) sh_error("Cannot set tty process group (%s)", strerror(errno)); + if (err) + sh_error("Cannot set tty process group (%s)", strerror(errno)); } static int getstatus(struct job *job) { @@ -7166,7 +7459,8 @@ static int getstatus(struct job *job) { if (!WIFSTOPPED(status)) { /* XXX: limits number of signals */ retval = WTERMSIG(status); - if (retval == SIGINT) job->sigint = 1; + if (retval == SIGINT) + job->sigint = 1; } retval += 128; } @@ -7236,7 +7530,8 @@ static int readcmd(int argc, char **argv) { if (prompt && isatty(0)) { outstr(prompt, out2); } - if (!*(ap = argptr)) sh_error("arg count"); + if (!*(ap = argptr)) + sh_error("arg count"); status = 0; STARTSTACKSTR(p); goto start; @@ -7245,25 +7540,30 @@ static int readcmd(int argc, char **argv) { case 1: break; default: - if (errno == EINTR && !pending_sig) continue; + if (errno == EINTR && !pending_sig) + continue; /* fall through */ case 0: status = 1; goto out; } - if (!c) continue; + if (!c) + continue; if (newloc >= startloc) { - if (c == '\n') goto resetbs; + if (c == '\n') + goto resetbs; goto put; } if (!rflag && c == '\\') { newloc = p - (char *)stackblock(); continue; } - if (c == '\n') break; + if (c == '\n') + break; put: CHECKSTRSPACE(2, p); - if (strchr(qchars, c)) USTPUTC(CTLESC, p); + if (strchr(qchars, c)) + USTPUTC(CTLESC, p); USTPUTC(c, p); if (newloc >= startloc) { resetbs: @@ -7308,7 +7608,8 @@ static int umaskcmd(int argc, char **argv) { *ap++ = "ugo"[i]; *ap++ = '='; for (j = 0; j < 3; j++) - if (mask & (1u << (8 - (3 * i + j)))) *ap++ = "rwx"[j]; + if (mask & (1u << (8 - (3 * i + j)))) + *ap++ = "rwx"[j]; *ap++ = ','; } ap[-1] = '\0'; @@ -7321,7 +7622,8 @@ static int umaskcmd(int argc, char **argv) { if (isdigit((unsigned char)*ap)) { new_mask = 0; do { - if (*ap >= '8' || *ap < '0') sh_error(illnum, *argptr); + if (*ap >= '8' || *ap < '0') + sh_error(illnum, *argptr); new_mask = (new_mask << 3) + (*ap - '0'); } while (*++ap != '\0'); } else { @@ -7331,7 +7633,8 @@ static int umaskcmd(int argc, char **argv) { new_mask = mask; positions = 0; while (*ap) { - while (*ap && strchr("augo", *ap)) switch (*ap++) { + while (*ap && strchr("augo", *ap)) + switch (*ap++) { case 'a': positions |= 0111; break; @@ -7345,11 +7648,14 @@ static int umaskcmd(int argc, char **argv) { positions |= 0001; break; } - if (!positions) positions = 0111; /* default is a */ - if (!strchr("=+-", op = *ap)) break; + if (!positions) + positions = 0111; /* default is a */ + if (!strchr("=+-", op = *ap)) + break; ap++; new_val = 0; - while (*ap && strchr("rwxugoXs", *ap)) switch (*ap++) { + while (*ap && strchr("rwxugoXs", *ap)) + switch (*ap++) { case 'r': new_val |= 04; break; @@ -7369,7 +7675,8 @@ static int umaskcmd(int argc, char **argv) { new_val |= mask >> 0; break; case 'X': - if (mask & 0111) new_val |= 01; + if (mask & 0111) + new_val |= 01; break; case 's': /* ignored */ break; @@ -7415,7 +7722,8 @@ static void printlim(enum limtype how, const struct rlimit *limit, const struct limits *l) { uint64_t val; val = limit->rlim_max; - if (how & SOFT) val = limit->rlim_cur; + if (how & SOFT) + val = limit->rlim_cur; if (val == RLIM_INFINITY) out1fmt("unlimited\n"); else { @@ -7453,16 +7761,19 @@ static int ulimitcmd(int argc, char **argv) { set = *argptr ? 1 : 0; if (set) { char *p = *argptr; - if (all || argptr[1]) sh_error("too many arguments"); + if (all || argptr[1]) + sh_error("too many arguments"); if (strcmp(p, "unlimited") == 0) val = RLIM_INFINITY; else { val = (uint64_t)0; while ((c = *p++) >= '0' && c <= '9') { val = (val * 10) + (long)(c - '0'); - if (val < (uint64_t)0) break; + if (val < (uint64_t)0) + break; } - if (c) sh_error("bad number"); + if (c) + sh_error("bad number"); val *= l->factor; } } @@ -7476,8 +7787,10 @@ static int ulimitcmd(int argc, char **argv) { } getrlimit(l->cmd, &limit); if (set) { - if (how & HARD) limit.rlim_max = val; - if (how & SOFT) limit.rlim_cur = val; + if (how & HARD) + limit.rlim_max = val; + if (how & SOFT) + limit.rlim_cur = val; if (setrlimit(l->cmd, &limit) < 0) sh_error("error setting limit (%s)", strerror(errno)); } else { @@ -7504,7 +7817,8 @@ static char *single_quote(const char *s) { s += len; STADJUST(q - p, p); len = strspn(s, "'"); - if (!len) break; + if (!len) + break; q = p = makestrspace(len + 3, p); *q++ = '"'; q = mempcpy(q, s, len); @@ -7527,25 +7841,32 @@ static int procargs(int argc, char **argv) { xargv = argv; login = xargv[0] && xargv[0][0] == '-'; arg0 = xargv[0]; - if (argc > 0) xargv++; - for (i = 0; i < NOPTS; i++) optlist[i] = 2; + if (argc > 0) + xargv++; + for (i = 0; i < NOPTS; i++) + optlist[i] = 2; argptr = xargv; login |= options(1); xargv = argptr; xminusc = minusc; if (*xargv == NULL) { - if (xminusc) sh_error("-c requires an argument"); + if (xminusc) + sh_error("-c requires an argument"); sflag = 1; } /* JART: fuck tty check this is documented behavior w/ no args */ - if (iflag == 2 && sflag == 1 /* && isatty(0) && isatty(1) */) iflag = 1; - if (mflag == 2) mflag = iflag; + if (iflag == 2 && sflag == 1 /* && isatty(0) && isatty(1) */) + iflag = 1; + if (mflag == 2) + mflag = iflag; for (i = 0; i < NOPTS; i++) - if (optlist[i] == 2) optlist[i] = 0; + if (optlist[i] == 2) + optlist[i] = 0; /* POSIX 1003.2: first arg after -c cmd is $0, remainder $1... */ if (xminusc) { minusc = *xargv++; - if (*xargv) goto setarg0; + if (*xargv) + goto setarg0; } else if (!sflag) { setinputfile(*xargv, 0); setarg0: @@ -7595,7 +7916,8 @@ static int options(int cmdline) { int val; int c; int login = 0; - if (cmdline) minusc = NULL; + if (cmdline) + minusc = NULL; while ((p = *argptr) != NULL) { argptr++; if ((c = *p++) == '-') { @@ -7603,7 +7925,8 @@ static int options(int cmdline) { if (p[0] == '\0' || (p[0] == '-' && p[1] == '\0')) { if (!cmdline) { /* "-" means turn off -x and -v */ - if (p[0] == '\0') xflag = vflag = 0; + if (p[0] == '\0') + xflag = vflag = 0; /* "--" means reset params */ else if (*argptr == NULL) setparam(argptr); @@ -7623,7 +7946,8 @@ static int options(int cmdline) { login = 1; } else if (c == 'o') { minus_o(*argptr, val); - if (*argptr) argptr++; + if (*argptr) + argptr++; } else { setoption(c, val); } @@ -7682,7 +8006,8 @@ static void setparam(char **argv) { static void freeparam(volatile struct shparam *param) { char **ap; if (param->malloc) { - for (ap = param->p; *ap; ap++) ckfree(*ap); + for (ap = param->p; *ap; ap++) + ckfree(*ap); ckfree(param->p); } } @@ -7694,15 +8019,19 @@ static int shiftcmd(int argc, char **argv) { int n; char **ap1, **ap2; n = 1; - if (argc > 1) n = number(argv[1]); - if (n > shellparam.nparam) sh_error("can't shift that many"); + if (argc > 1) + n = number(argv[1]); + if (n > shellparam.nparam) + sh_error("can't shift that many"); INTOFF; shellparam.nparam -= n; for (ap1 = shellparam.p; --n >= 0; ap1++) { - if (shellparam.malloc) ckfree(*ap1); + if (shellparam.malloc) + ckfree(*ap1); } ap2 = shellparam.p; - while ((*ap2++ = *ap1++) != NULL); + while ((*ap2++ = *ap1++) != NULL) + ; shellparam.optind = 1; shellparam.optoff = -1; INTON; @@ -7713,7 +8042,8 @@ static int shiftcmd(int argc, char **argv) { * The set command builtin. */ static int setcmd(int argc, char **argv) { - if (argc == 1) return showvars(nullstr, 0, VUNSET); + if (argc == 1) + return showvars(nullstr, 0, VUNSET); INTOFF; options(0); optschanged(); @@ -7797,7 +8127,8 @@ static int getopts(char *optstr, char *optvar, char **optfirst) { c = '?'; goto out; } - if (*++q == ':') q++; + if (*++q == ':') + q++; } if (*++q == ':') { if (*p == '\0' && (p = *optnext) == NULL) { @@ -7813,7 +8144,8 @@ static int getopts(char *optstr, char *optvar, char **optfirst) { } goto out; } - if (p == *optnext) optnext++; + if (p == *optnext) + optnext++; setvar("OPTARG", p, 0); p = NULL; } else @@ -7845,15 +8177,18 @@ static int nextopt(const char *optstring) { char c; if ((p = optptr) == NULL || *p == '\0') { p = *argptr; - if (p == NULL || *p != '-' || *++p == '\0') return '\0'; + if (p == NULL || *p != '-' || *++p == '\0') + return '\0'; argptr++; if (p[0] == '-' && p[1] == '\0') /* check for "--" */ return '\0'; } c = *p++; for (q = optstring; *q != c;) { - if (*q == '\0') sh_error("Illegal option -%c", c); - if (*++q == ':') q++; + if (*q == '\0') + sh_error("Illegal option -%c", c); + if (*++q == ':') + q++; } if (*++q == ':') { if (*p == '\0' && (p = *argptr++) == NULL) { @@ -7869,7 +8204,8 @@ static int nextopt(const char *optstring) { /* values returned by readtoken */ static int isassignment(const char *p) { const char *q = endofname(p); - if (p == q) return 0; + if (p == q) + return 0; return *q == '='; } @@ -7886,7 +8222,8 @@ static union node *parsecmd(int interact) { checkkwd = 0; heredoclist = 0; doprompt = interact; - if (doprompt) setprompt(doprompt); + if (doprompt) + setprompt(doprompt); needprompt = 0; return list(1); } @@ -7904,7 +8241,8 @@ static union node *list(int nlflag) { parseheredoc(); return n1; case TEOF: - if (!n1 && !chknl) n1 = NEOF; + if (!n1 && !chknl) + n1 = NEOF; out_eof: parseheredoc(); tokpushback++; @@ -7912,7 +8250,8 @@ static union node *list(int nlflag) { return n1; } tokpushback++; - if (nlflag == 2 && tokendlist[tok]) return n1; + if (nlflag == 2 && tokendlist[tok]) + return n1; nlflag |= 2; n2 = andor(); tok = readtoken(); @@ -7948,7 +8287,8 @@ static union node *list(int nlflag) { case TSEMI: break; default: - if (!chknl) synexpect(-1); + if (!chknl) + synexpect(-1); tokpushback++; return n1; } @@ -8036,7 +8376,8 @@ static union node *command(void) { n1 = (union node *)stalloc(sizeof(struct nif)); n1->type = NIF; n1->nif.test = list(0); - if (readtoken() != TTHEN) synexpect(TTHEN); + if (readtoken() != TTHEN) + synexpect(TTHEN); n1->nif.ifpart = list(0); n2 = n1; while (readtoken() == TELIF) { @@ -8044,7 +8385,8 @@ static union node *command(void) { n2 = n2->nif.elsepart; n2->type = NIF; n2->nif.test = list(0); - if (readtoken() != TTHEN) synexpect(TTHEN); + if (readtoken() != TTHEN) + synexpect(TTHEN); n2->nif.ifpart = list(0); } if (lasttoken == TELSE) @@ -8090,7 +8432,8 @@ static union node *command(void) { } *app = NULL; n1->nfor.args = ap; - if (lasttoken != TNL && lasttoken != TSEMI) synexpect(-1); + if (lasttoken != TNL && lasttoken != TSEMI) + synexpect(-1); } else { n2 = (union node *)stalloc(sizeof(struct narg)); n2->type = NARG; @@ -8102,10 +8445,12 @@ static union node *command(void) { * Newline or semicolon here is optional (but note * that the original Bourne shell only allowed NL). */ - if (lasttoken != TSEMI) tokpushback++; + if (lasttoken != TSEMI) + tokpushback++; } checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (readtoken() != TDO) synexpect(TDO); + if (readtoken() != TDO) + synexpect(TDO); n1->nfor.body = list(0); t = TDONE; break; @@ -8113,20 +8458,23 @@ static union node *command(void) { n1 = (union node *)stalloc(sizeof(struct ncase)); n1->type = NCASE; n1->ncase.linno = savelinno; - if (readtoken() != TWORD) synexpect(TWORD); + if (readtoken() != TWORD) + synexpect(TWORD); n1->ncase.expr = n2 = (union node *)stalloc(sizeof(struct narg)); n2->type = NARG; n2->narg.text = wordtext; n2->narg.backquote = backquotelist; n2->narg.next = NULL; checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (readtoken() != TIN) synexpect(TIN); + if (readtoken() != TIN) + synexpect(TIN); cpp = &n1->ncase.cases; next_case: checkkwd = CHKNL | CHKKWD; t = readtoken(); while (t != TESAC) { - if (lasttoken == TLP) readtoken(); + if (lasttoken == TLP) + readtoken(); *cpp = cp = (union node *)stalloc(sizeof(struct nclist)); cp->type = NCLIST; app = &cp->nclist.pattern; @@ -8135,12 +8483,14 @@ static union node *command(void) { ap->type = NARG; ap->narg.text = wordtext; ap->narg.backquote = backquotelist; - if (readtoken() != TPIPE) break; + if (readtoken() != TPIPE) + break; app = &ap->narg.next; readtoken(); } ap->narg.next = NULL; - if (lasttoken != TRP) synexpect(TRP); + if (lasttoken != TRP) + synexpect(TRP); cp->nclist.body = list(2); cpp = &cp->nclist.next; checkkwd = CHKNL | CHKKWD; @@ -8170,7 +8520,8 @@ static union node *command(void) { tokpushback++; return simplecmd(); } - if (readtoken() != t) synexpect(t); + if (readtoken() != t) + synexpect(t); redir: /* Now check for redirection which may follow command */ checkkwd = CHKKWD | CHKALIAS; @@ -8237,7 +8588,8 @@ static union node *simplecmd(void) { struct builtincmd *bcmd; const char *name; /* We have a function */ - if (readtoken() != TRP) synexpect(TRP); + if (readtoken() != TRP) + synexpect(TRP); name = n->narg.text; if (!goodname(name) || ((bcmd = find_builtin(name)) && bcmd->flags & BUILTIN_SPECIAL)) @@ -8280,7 +8632,8 @@ static union node *makename(void) { static void fixredir(union node *n, const char *text, int err) { TRACE(("Fix redir %s %d\n", text, err)); - if (!err) n->ndup.vname = NULL; + if (!err) + n->ndup.vname = NULL; if (is_digit(text[0]) && text[1] == '\0') n->ndup.dupfd = digit_val(text[0]); else if (text[0] == '-' && text[1] == '\0') @@ -8295,12 +8648,15 @@ static void fixredir(union node *n, const char *text, int err) { static void parsefname(void) { union node *n = redirnode; - if (n->type == NHERE) checkkwd = CHKEOFMARK; - if (readtoken() != TWORD) synexpect(-1); + if (n->type == NHERE) + checkkwd = CHKEOFMARK; + if (readtoken() != TWORD) + synexpect(-1); if (n->type == NHERE) { struct heredoc *here = heredoc; struct heredoc *p; - if (quoteflag == 0) n->type = NXHERE; + if (quoteflag == 0) + n->type = NXHERE; TRACE(("Here document %d\n", n->type)); rmescapes(wordtext, 0); here->eofmark = wordtext; @@ -8391,7 +8747,8 @@ out: static void nlprompt(void) { plinno++; - if (doprompt) setprompt(2); + if (doprompt) + setprompt(2); } static void nlnoprompt(void) { @@ -8440,15 +8797,18 @@ static int xxreadtoken(void) { case PEOF: RETURN(TEOF); case '&': - if (pgetc_eatbnl() == '&') RETURN(TAND); + if (pgetc_eatbnl() == '&') + RETURN(TAND); pungetc(); RETURN(TBACKGND); case '|': - if (pgetc_eatbnl() == '|') RETURN(TOR); + if (pgetc_eatbnl() == '|') + RETURN(TOR); pungetc(); RETURN(TPIPE); case ';': - if (pgetc_eatbnl() == ';') RETURN(TENDCASE); + if (pgetc_eatbnl() == ';') + RETURN(TENDCASE); pungetc(); RETURN(TSEMI); case '(': @@ -8547,7 +8907,8 @@ static int readtoken1(int firstc, char const *syntax, char *eofmark, /* syntax stack */ struct synstack synbase = {.syntax = syntax}; struct synstack *synstack = &synbase; - if (syntax == DQSYNTAX) synstack->dblquote = 1; + if (syntax == DQSYNTAX) + synstack->dblquote = 1; quotef = 0; bqlist = NULL; STARTSTACKSTR(out); @@ -8601,7 +8962,8 @@ loop: { /* for each line, until end of word */ synstack->syntax = DQSYNTAX; synstack->dblquote = 1; toggledq: - if (synstack->varnest) synstack->innerdq ^= 1; + if (synstack->varnest) + synstack->innerdq ^= 1; goto quotemark; case CENDQUOTE: if (eofmark && !synstack->varnest) { @@ -8613,7 +8975,8 @@ loop: { /* for each line, until end of word */ synstack->dblquote = 0; } quotef++; - if (c == '"') goto toggledq; + if (c == '"') + goto toggledq; goto quotemark; case CVAR: /* '$' */ PARSESUB(); /* parse substitution */ @@ -8661,14 +9024,16 @@ loop: { /* for each line, until end of word */ case CEOF: goto endword; /* exit outer loop */ default: - if (synstack->varnest == 0) goto endword; /* exit outer loop */ + if (synstack->varnest == 0) + goto endword; /* exit outer loop */ USTPUTC(c, out); } c = pgetc_top(synstack); } } endword: - if (synstack->syntax == ARISYNTAX) synerror("Missing '))'"); + if (synstack->syntax == ARISYNTAX) + synerror("Missing '))'"); if (synstack->syntax != BASESYNTAX && eofmark == NULL) synerror("Unterminated quoted string"); if (synstack->varnest != 0) { @@ -8704,11 +9069,13 @@ checkend: { int markloc; char *p; if (striptabs) { - while (c == '\t') c = pgetc(); + while (c == '\t') + c = pgetc(); } markloc = out - (char *)stackblock(); for (p = eofmark; STPUTC(c, out), *p; p++) { - if (c != *p) goto more_heredoc; + if (c != *p) + goto more_heredoc; c = pgetc(); } if (c == '\n' || c == PEOF) { @@ -8787,7 +9154,8 @@ parseredir: { break; } } - if (fd != '\0') np->nfile.fd = digit_val(fd); + if (fd != '\0') + np->nfile.fd = digit_val(fd); redirnode = np; goto parseredir_return; } @@ -8839,7 +9207,8 @@ parsesub: { c = pgetc_eatbnl(); if (!subtype && cc == '#') { subtype = VSLENGTH; - if (c == '_' || isalnum(c)) goto varname; + if (c == '_' || isalnum(c)) + goto varname; cc = c; c = pgetc_eatbnl(); if (cc == '}' || c != '}') { @@ -8850,7 +9219,8 @@ parsesub: { } } if (!is_special(cc)) { - if (subtype == VSLENGTH) subtype = 0; + if (subtype == VSLENGTH) + subtype = 0; goto badsub; } USTPUTC(cc, out); @@ -8865,7 +9235,8 @@ parsesub: { /*FALLTHROUGH*/ default: p = strchr(types, c); - if (p == NULL) break; + if (p == NULL) + break; subtype |= p - types + VSNORMAL; break; case '%': @@ -8880,11 +9251,13 @@ parsesub: { break; } } else { - if (subtype == VSLENGTH && c != '}') subtype = 0; + if (subtype == VSLENGTH && c != '}') + subtype = 0; badsub: pungetc(); } - if (newsyn == ARISYNTAX) newsyn = DQSYNTAX; + if (newsyn == ARISYNTAX) + newsyn = DQSYNTAX; if ((newsyn != synstack->syntax || synstack->innerdq) && subtype != VSNORMAL) { synstack_push(&synstack, synstack->prev ?: alloca(sizeof(*synstack)), @@ -8895,7 +9268,8 @@ parsesub: { *((char *)stackblock() + typeloc) = subtype; if (subtype != VSNORMAL) { synstack->varnest++; - if (synstack->dblquote) synstack->dqvarnest++; + if (synstack->dblquote) + synstack->dqvarnest++; } STPUTC('=', out); } @@ -8962,7 +9336,8 @@ parsebackq: { } } nlpp = &bqlist; - while (*nlpp) nlpp = &(*nlpp)->next; + while (*nlpp) + nlpp = &(*nlpp)->next; *nlpp = (struct nodelist *)stalloc(sizeof(struct nodelist)); (*nlpp)->next = NULL; saveheredoclist = heredoclist; @@ -8975,7 +9350,8 @@ parsebackq: { if (oldstyle) doprompt = saveprompt; else { - if (readtoken() != TRP) synexpect(TRP); + if (readtoken() != TRP) + synexpect(TRP); setinputstring(nullstr); } parseheredoc(); @@ -8984,7 +9360,8 @@ parsebackq: { /* Start reading from old file again. */ popfile(); /* Ignore any pushed back tokens left from the backquote parsing. */ - if (oldstyle) tokpushback = 0; + if (oldstyle) + tokpushback = 0; out = growstackto(savelen + 1); if (str) { memcpy(out, str, savelen); @@ -9040,7 +9417,8 @@ static const char *expandstr(const char *ps) { doprompt = 0; result = ps; savehandler = handler; - if (unlikely(err = setjmp(jmploc.loc))) goto out; + if (unlikely(err = setjmp(jmploc.loc))) + goto out; handler = &jmploc; readtoken1(pgetc_eatbnl(), DQSYNTAX, FAKEEOFMARK, 0); n.narg.type = NARG; @@ -9051,7 +9429,8 @@ static const char *expandstr(const char *ps) { result = stackblock(); out: handler = savehandler; - if (err && exception != EXERROR) longjmp(handler->loc, 1); + if (err && exception != EXERROR) + longjmp(handler->loc, 1); doprompt = saveprompt; unwindfiles(file_stop); heredoclist = saveheredoclist; @@ -9106,14 +9485,17 @@ static void redirect(union node *redir, int flags) { int fd; int newfd; int *p; - if (!redir) return; + if (!redir) + return; sv = NULL; INTOFF; - if (likely(flags & REDIR_PUSH)) sv = redirlist; + if (likely(flags & REDIR_PUSH)) + sv = redirlist; n = redir; do { newfd = openredirect(n); - if (newfd < -1) continue; + if (newfd < -1) + continue; fd = n->nfile.fd; if (sv) { int closed; @@ -9129,7 +9511,8 @@ static void redirect(union node *redir, int flags) { } *p = i; } - if (fd == newfd) continue; + if (fd == newfd) + continue; dupredirect(n, newfd); } while ((n = n->nfile.next)); INTON; @@ -9156,7 +9539,8 @@ static int sh_open(const char *pathname, int flags, int mayfail) { fd = open(pathname, flags, 0666); e = errno; } while (fd < 0 && e == EINTR && !pending_sig); - if (mayfail || fd >= 0) return fd; + if (mayfail || fd >= 0) + return fd; sh_open_fail(pathname, flags, e); } @@ -9182,7 +9566,8 @@ static int openredirect(union node *redir) { flags = O_WRONLY | O_CREAT | O_EXCL; goto do_open; } - if (S_ISREG(sb.st_mode)) goto ecreate; + if (S_ISREG(sb.st_mode)) + goto ecreate; f = sh_open(fname, O_WRONLY, 0); if (!fstat(f, &sb) && S_ISREG(sb.st_mode)) { close(f); @@ -9200,7 +9585,8 @@ static int openredirect(union node *redir) { case NTOFD: case NFROMFD: f = redir->ndup.dupfd; - if (f == redir->nfile.fd) f = -2; + if (f == redir->nfile.fd) + f = -2; break; default: /* Fall through to eliminate warning. */ @@ -9231,7 +9617,8 @@ static void dupredirect(union node *redir, int f) { err = errno; } close(f); - if (err < 0) goto err; + if (err < 0) + goto err; return; err: sh_error("%ld: %s", f, strerror(err)); @@ -9246,7 +9633,8 @@ static int64_t openhere(union node *redir) { char *p; int pip[2]; unsigned len = 0; - if (pipe(pip) < 0) sh_error("Pipe call failed"); + if (pipe(pip) < 0) + sh_error("Pipe call failed"); p = redir->nhere.doc->narg.text; if (redir->type == NXHERE) { expandarg(redir->nhere.doc, NULL, EXP_QUOTED); @@ -9281,14 +9669,17 @@ static void popredir(int drop) { rp = redirlist; for (i = 0; i < 10; i++) { int closed; - if (rp->renamed[i] == EMPTY) continue; + if (rp->renamed[i] == EMPTY) + continue; closed = drop ? 1 : update_closed_redirs(i, rp->renamed[i]); switch (rp->renamed[i]) { case CLOSED: - if (!closed) close(i); + if (!closed) + close(i); break; default: - if (!drop) dup2(rp->renamed[i], i); + if (!drop) + dup2(rp->renamed[i], i); close(rp->renamed[i]); break; } @@ -9329,13 +9720,15 @@ static int redirectsafe(union node *redir, int flags) { redirect(redir, flags); } handler = savehandler; - if (err && exception != EXERROR) longjmp(handler->loc, 1); + if (err && exception != EXERROR) + longjmp(handler->loc, 1); RESTOREINT(saveint); return err; } static void unwindredir(struct redirtab *stop) { - while (redirlist != stop) popredir(0); + while (redirlist != stop) + popredir(0); } static struct redirtab *pushredir(union node *redir) { @@ -9343,11 +9736,13 @@ static struct redirtab *pushredir(union node *redir) { struct redirtab *q; int i; q = redirlist; - if (!redir) goto out; + if (!redir) + goto out; sv = ckmalloc(sizeof(struct redirtab)); sv->next = q; redirlist = sv; - for (i = 0; i < 10; i++) sv->renamed[i] = EMPTY; + for (i = 0; i < 10; i++) + sv->renamed[i] = EMPTY; out: return q; } @@ -9383,16 +9778,19 @@ static int trapcmd(int argc, char **argv) { if (action[0] == '-' && action[1] == '\0') action = NULL; else { - if (*action) trapcnt++; + if (*action) + trapcnt++; action = savestr(action); } } if (trap[signo]) { - if (*trap[signo]) trapcnt--; + if (*trap[signo]) + trapcnt--; ckfree(trap[signo]); } trap[signo] = action; - if (signo != 0) setsignal(signo); + if (signo != 0) + setsignal(signo); INTON; ap++; } @@ -9417,14 +9815,18 @@ static void setsignal(int signo) { action = S_IGN; if (rootshell && action == S_DFL && !lvforked) { if (signo == SIGINT) { - if (iflag || minusc || sflag == 0) action = S_CATCH; + if (iflag || minusc || sflag == 0) + action = S_CATCH; } else if (signo == SIGQUIT || signo == SIGTERM) { - if (iflag) action = S_IGN; + if (iflag) + action = S_IGN; } else if (signo == SIGTSTP || signo == SIGTTOU) { - if (mflag) action = S_IGN; + if (mflag) + action = S_IGN; } } - if (signo == SIGCHLD) action = S_CATCH; + if (signo == SIGCHLD) + action = S_CATCH; t = &sigmode[signo - 1]; tsig = *t; if (tsig == 0) { @@ -9448,7 +9850,8 @@ static void setsignal(int signo) { tsig = S_RESET; /* force to be set */ } } - if (tsig == S_HARD_IGN || tsig == action) return; + if (tsig == S_HARD_IGN || tsig == action) + return; switch (action) { case S_CATCH: act.sa_handler = onsig; @@ -9459,7 +9862,8 @@ static void setsignal(int signo) { default: act.sa_handler = SIG_DFL; } - if (!lvforked) *t = action; + if (!lvforked) + *t = action; act.sa_flags = 0; sigfillset(&act.sa_mask); sigaction(signo, &act, 0); @@ -9472,22 +9876,26 @@ static void ignoresig(int signo) { if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) { signal(signo, SIG_IGN); } - if (!vforked) sigmode[signo - 1] = S_HARD_IGN; + if (!vforked) + sigmode[signo - 1] = S_HARD_IGN; } /* * Signal handler. */ static void onsig(int signo) { - if (vforked) return; + if (vforked) + return; if (signo == SIGCHLD) { gotsigchld = 1; - if (!trap[SIGCHLD]) return; + if (!trap[SIGCHLD]) + return; } gotsig[signo - 1] = 1; pending_sig = signo; if (signo == SIGINT && !trap[SIGINT]) { - if (!suppressint) onint(); + if (!suppressint) + onint(); intpending = 1; } } @@ -9501,7 +9909,8 @@ static void dotrap(void) { char *q; int i; int status, last_status; - if (!pending_sig) return; + if (!pending_sig) + return; status = savestatus; last_status = status; if (likely(status < 0)) { @@ -9511,16 +9920,19 @@ static void dotrap(void) { pending_sig = 0; barrier(); for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) { - if (!*q) continue; + if (!*q) + continue; if (evalskip) { pending_sig = i + 1; break; } *q = 0; p = trap[i + 1]; - if (!p) continue; + if (!p) + continue; evalstring(p, 0); - if (evalskip != SKIPFUNC) exitstatus = status; + if (evalskip != SKIPFUNC) + exitstatus = status; } savestatus = last_status; } @@ -9530,7 +9942,8 @@ static void dotrap(void) { */ static void setinteractive(int on) { static int is_interactive; - if (++on == is_interactive) return; + if (++on == is_interactive) + return; is_interactive = on; setsignal(SIGINT); setsignal(SIGQUIT); @@ -9545,7 +9958,8 @@ wontreturn static void exitshell(void) { char *p; savestatus = exitstatus; TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus)); - if (setjmp(loc.loc)) goto out; + if (setjmp(loc.loc)) + goto out; handler = &loc; if ((p = trap[0])) { trap[0] = NULL; @@ -9559,7 +9973,8 @@ out: * Disable job control so that whoever had the foreground before we * started can get it back. */ - if (likely(!setjmp(loc.loc))) setjobctl(0); + if (likely(!setjmp(loc.loc))) + setjobctl(0); flushall(); _exit(exitstatus); } @@ -9567,7 +9982,8 @@ out: static int decode_signal(const char *string, int minsig) { int signo; signo = decode_signum(string); - if (signo >= 0) return signo; + if (signo >= 0) + return signo; for (signo = minsig; signo < NSIG; signo++) { if (!strcasecmp(string, strsignal(signo))) { return signo; @@ -9627,7 +10043,8 @@ static int print_escape_str(const char *f, int *param, int *array, char *s) { total = len - 1; q[-1] = (!!((f[1] - 's') | done) - 1) & f[2]; total += !!q[-1]; - if (f[1] == 's') goto easy; + if (f[1] == 's') + goto easy; p = makestrspace(len, q); memset(p, 'X', total); p[total] = 0; @@ -9651,7 +10068,8 @@ static int printfcmd(int argc, char *argv[]) { nextopt(nullstr); argv = argptr; format = *argv; - if (!format) sh_error("usage: printf format [arg ...]"); + if (!format) + sh_error("usage: printf format [arg ...]"); gargv = ++argv; do { /* @@ -9703,7 +10121,8 @@ static int printfcmd(int argc, char *argv[]) { fmt += strspn(fmt, kSkip2); } ch = *fmt; - if (!ch) sh_error("missing format character"); + if (!ch) + sh_error("missing format character"); /* null terminate format string to we can use it as an argument to printf. */ nextch = fmt[1]; @@ -9712,7 +10131,8 @@ static int printfcmd(int argc, char *argv[]) { case 'b': *fmt = 's'; /* escape if a \c was encountered */ - if (print_escape_str(start, param, array, getstr())) goto out; + if (print_escape_str(start, param, array, getstr())) + goto out; *fmt = 'b'; break; case 'c': { @@ -9775,7 +10195,8 @@ static int conv_escape_str(char *str, char **sp) { STARTSTACKSTR(cp); do { c = ch = *str++; - if (ch != '\\') continue; + if (ch != '\\') + continue; c = *str++; if (c == 'c') { /* \c as in SYSV echo - abort all processing.... */ @@ -9787,7 +10208,8 @@ static int conv_escape_str(char *str, char **sp) { * They start with a \0, and are followed by 0, 1, 2, * or 3 octal digits. */ - if (c == '0' && isodigit(*str)) str++; + if (c == '0' && isodigit(*str)) + str++; /* Finally test for sequences valid in the format string */ str = conv_escape(str - 1, &c); } while (STPUTC(c, cp), (char)ch); @@ -9875,10 +10297,12 @@ static uint64_t getuintmax(int sign) { uint64_t val = 0; char *cp, *ep; cp = *gargv; - if (cp == NULL) goto out; + if (cp == NULL) + goto out; gargv++; val = (unsigned char)cp[1]; - if (*cp == '\"' || *cp == '\'') goto out; + if (*cp == '\"' || *cp == '\'') + goto out; errno = 0; val = sign ? strtoimax(cp, &ep, 0) : strtoumax(cp, &ep, 0); check_conversion(cp, ep); @@ -9890,9 +10314,11 @@ static double getdouble(void) { double val; char *cp, *ep; cp = *gargv; - if (cp == NULL) return 0; + if (cp == NULL) + return 0; gargv++; - if (*cp == '\"' || *cp == '\'') return (unsigned char)cp[1]; + if (*cp == '\"' || *cp == '\'') + return (unsigned char)cp[1]; errno = 0; val = strtod(cp, &ep); check_conversion(cp, ep); @@ -9922,7 +10348,8 @@ static int echocmd(int argc, char **argv) { do { const char *fmt = "%s "; char *s = *argv; - if (!s || !*++argv) fmt = lastfmt; + if (!s || !*++argv) + fmt = lastfmt; nonl = print_escape_str(fmt, NULL, NULL, s ?: nullstr); } while (!nonl && *argv); return 0; @@ -9961,7 +10388,8 @@ static inline int faccessat_confused_about_superuser(void) { static const struct t_op *getop(const char *s) { const struct t_op *op; for (op = ops; op->op_text; op++) { - if (strcmp(s, op->op_text) == 0) return op; + if (strcmp(s, op->op_text) == 0) + return op; } return NULL; } @@ -9971,14 +10399,16 @@ static int testcmd(int argc, char **argv) { enum token n; int res = 1; if (*argv[0] == '[') { - if (*argv[--argc] != ']') sh_error("missing ]"); + if (*argv[--argc] != ']') + sh_error("missing ]"); argv[argc] = NULL; } t_wp_op = NULL; recheck: argv++; argc--; - if (argc < 1) return res; + if (argc < 1) + return res; /* * POSIX prescriptions: he who wrote this deserves the Nobel * peace prize. @@ -10024,7 +10454,8 @@ static int oexpr(enum token n) { for (;;) { res |= aexpr(n); n = t_lex(t_wp + 1); - if (n != BOR) break; + if (n != BOR) + break; n = t_lex(t_wp += 2); } return res; @@ -10033,34 +10464,42 @@ static int oexpr(enum token n) { static int aexpr(enum token n) { int res = 1; for (;;) { - if (!nexpr(n)) res = 0; + if (!nexpr(n)) + res = 0; n = t_lex(t_wp + 1); - if (n != BAND) break; + if (n != BAND) + break; n = t_lex(t_wp += 2); } return res; } static int nexpr(enum token n) { - if (n != UNOT) return primary1(n); + if (n != UNOT) + return primary1(n); n = t_lex(t_wp + 1); - if (n != EOI) t_wp++; + if (n != EOI) + t_wp++; return !nexpr(n); } static int primary1(enum token n) { enum token nn; int res; - if (n == EOI) return 0; /* missing expression */ + if (n == EOI) + return 0; /* missing expression */ if (n == LPAREN) { - if ((nn = t_lex(++t_wp)) == RPAREN) return 0; /* missing expression */ + if ((nn = t_lex(++t_wp)) == RPAREN) + return 0; /* missing expression */ res = oexpr(nn); - if (t_lex(++t_wp) != RPAREN) syntax(NULL, "closing paren expected"); + if (t_lex(++t_wp) != RPAREN) + syntax(NULL, "closing paren expected"); return res; } if (t_wp_op && t_wp_op->op_type == UNOP) { /* unary expression */ - if (*++t_wp == NULL) syntax(t_wp_op->op_text, "argument expected"); + if (*++t_wp == NULL) + syntax(t_wp_op->op_text, "argument expected"); switch (n) { case STREZ: return strlen(*t_wp) == 0; @@ -10090,7 +10529,8 @@ static int binop0(void) { opnd1 = *t_wp; (void)t_lex(++t_wp); op = t_wp_op; - if ((opnd2 = *++t_wp) == (char *)0) syntax(op->op_text, "argument expected"); + if ((opnd2 = *++t_wp) == (char *)0) + syntax(op->op_text, "argument expected"); switch (op->op_num) { default: case STREQ: @@ -10124,7 +10564,8 @@ static int binop0(void) { static int filstat(char *nm, enum token mode) { struct stat s; - if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s)) return 0; + if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s)) + return 0; switch (mode) { case FILEXIST: return 1; @@ -10179,8 +10620,10 @@ static enum token t_lex(char **tp) { static int isoperand(char **tp) { struct t_op const *op; char *s; - if (!(s = tp[1])) return 1; - if (!tp[2]) return 0; + if (!(s = tp[1])) + return 1; + if (!tp[2]) + return 0; op = getop(s); return op && op->op_type == BINOP; } @@ -10209,7 +10652,8 @@ static int equalf(const char *f1, const char *f2) { static int has_exec_bit_set(const char *path) { struct stat st; - if (stat(path, &st)) return 0; + if (stat(path, &st)) + return 0; return st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH); } @@ -10250,7 +10694,8 @@ static int timescmd() { static struct Var **hashvar(const char *p) { unsigned int hashval; hashval = ((unsigned char)*p) << 4; - while (*p && *p != '=') hashval += (unsigned char)*p++; + while (*p && *p != '=') + hashval += (unsigned char)*p++; return &vartab[hashval % VTABSIZE]; } @@ -10288,7 +10733,8 @@ static struct Var *setvar(const char *name, const char *val, int flags) { q = endofname(name); p = strchrnul(q, '='); namelen = p - name; - if (!namelen || p != q) sh_error("%.*s: bad variable name", namelen, name); + if (!namelen || p != q) + sh_error("%.*s: bad variable name", namelen, name); vallen = 0; if (val == NULL) { flags |= VUNSET; @@ -10344,24 +10790,30 @@ static struct Var *setvareq(char *s, int flags) { if (vp) { if (vp->flags & VREADONLY) { const char *n; - if (flags & VNOSAVE) free(s); + if (flags & VNOSAVE) + free(s); n = vp->text; sh_error("%.*s: is read only", strchrnul(n, '=') - n, n); } - if (flags & VNOSET) goto out; - if (vp->func && (flags & VNOFUNC) == 0) (*vp->func)(strchrnul(s, '=') + 1); - if ((vp->flags & (VTEXTFIXED | VSTACK)) == 0) ckfree(vp->text); + if (flags & VNOSET) + goto out; + if (vp->func && (flags & VNOFUNC) == 0) + (*vp->func)(strchrnul(s, '=') + 1); + if ((vp->flags & (VTEXTFIXED | VSTACK)) == 0) + ckfree(vp->text); if (((flags & (VEXPORT | VREADONLY | VSTRFIXED | VUNSET)) | (vp->flags & VSTRFIXED)) == VUNSET) { *vpp = vp->next; ckfree(vp); out_free: - if ((flags & (VTEXTFIXED | VSTACK | VNOSAVE)) == VNOSAVE) ckfree(s); + if ((flags & (VTEXTFIXED | VSTACK | VNOSAVE)) == VNOSAVE) + ckfree(s); goto out; } flags |= vp->flags & ~(VTEXTFIXED | VSTACK | VNOSAVE | VUNSET); } else { - if (flags & VNOSET) goto out; + if (flags & VNOSET) + goto out; if ((flags & (VEXPORT | VREADONLY | VSTRFIXED | VUNSET)) == VUNSET) goto out_free; /* not found */ @@ -10370,7 +10822,8 @@ static struct Var *setvareq(char *s, int flags) { vp->func = NULL; *vpp = vp; } - if (!(flags & (VTEXTFIXED | VSTACK | VNOSAVE))) s = savestr(s); + if (!(flags & (VTEXTFIXED | VSTACK | VNOSAVE))) + s = savestr(s); vp->text = s; vp->flags = flags; out: @@ -10409,12 +10862,15 @@ static char **listvars(int on, int off, char ***end) { do { for (vp = *vpp; vp; vp = vp->next) if ((vp->flags & mask) == on) { - if (ep == stackstrend()) ep = growstackstr(); + if (ep == stackstrend()) + ep = growstackstr(); *ep++ = (char *)vp->text; } } while (++vpp < vartab + VTABSIZE); - if (ep == stackstrend()) ep = growstackstr(); - if (end) *end = ep; + if (ep == stackstrend()) + ep = growstackstr(); + if (end) + *end = ep; *ep++ = NULL; return grabstackstr(ep); } @@ -10441,7 +10897,8 @@ static int showvars(const char *prefix, int on, int off) { const char *q; p = strchrnul(*ep, '='); q = nullstr; - if (*p) q = single_quote(++p); + if (*p) + q = single_quote(++p); out1fmt("%s%s%.*s%s\n", prefix, sep, (int)(p - *ep), *ep, q); } return 0; @@ -10481,7 +10938,8 @@ static int exportcmd(int argc, char **argv) { */ static int localcmd(int argc, char **argv) { char *name; - if (!localvar_stack) sh_error("not in a function"); + if (!localvar_stack) + sh_error("not in a function"); argv = argptr; while ((name = *argv++) != NULL) { mklocal(name, 0); @@ -10521,7 +10979,8 @@ static void mklocal(char *name, int flags) { lvp->text = vp->text; lvp->flags = vp->flags; vp->flags |= VSTRFIXED | VTEXTFIXED; - if (eq) setvareq(name, flags); + if (eq) + setvareq(name, flags); } } lvp->vp = vp; @@ -10555,8 +11014,10 @@ static void poplocalvars(void) { vp->flags &= ~(VSTRFIXED | VREADONLY); unsetvar(vp->text); } else { - if (vp->func) (*vp->func)(strchrnul(lvp->text, '=') + 1); - if ((vp->flags & (VTEXTFIXED | VSTACK)) == 0) ckfree(vp->text); + if (vp->func) + (*vp->func)(strchrnul(lvp->text, '=') + 1); + if ((vp->flags & (VTEXTFIXED | VSTACK)) == 0) + ckfree(vp->text); vp->flags = lvp->flags; vp->text = lvp->text; } @@ -10572,7 +11033,8 @@ static struct localvar_list *pushlocalvars(int push) { struct localvar_list *ll; struct localvar_list *top; top = localvar_stack; - if (!push) goto out; + if (!push) + goto out; INTOFF; ll = ckmalloc(sizeof(*ll)); ll->lv = NULL; @@ -10584,7 +11046,8 @@ out: } static void unwindlocalvars(struct localvar_list *stop) { - while (localvar_stack != stop) poplocalvars(); + while (localvar_stack != stop) + poplocalvars(); } /* @@ -10604,7 +11067,8 @@ static int unsetcmd(int argc, char **argv) { unsetvar(*ap); continue; } - if (flag != 'v') unsetfunc(*ap); + if (flag != 'v') + unsetfunc(*ap); } return 0; } @@ -10707,7 +11171,8 @@ static void forkreset() { if (*tp && **tp) { /* trap not NULL or SIG_IGN */ ckfree(*tp); *tp = NULL; - if (tp != &trap[0]) setsignal(tp - trap); + if (tp != &trap[0]) + setsignal(tp - trap); } } trapcnt = 0; @@ -10732,7 +11197,8 @@ static void reset() { } static void calcsize(union node *n) { - if (n == NULL) return; + if (n == NULL) + return; funcblocksize += nodesize[n->type]; switch (n->type) { case NCMD: @@ -10837,7 +11303,8 @@ static void sizenodelist(struct nodelist *lp) { static union node *copynode(union node *n) { union node *new; - if (n == NULL) return NULL; + if (n == NULL) + return NULL; new = funcblock; funcblock = (char *)funcblock + nodesize[n->type]; switch (n->type) { @@ -10956,7 +11423,8 @@ static int cmdloop(int top) { for (;;) { int skip; setstackmark(&smark); - if (jobctl) showjobs(out2, SHOW_CHANGED); + if (jobctl) + showjobs(out2, SHOW_CHANGED); inter = 0; if (iflag && top) { inter++; @@ -10965,10 +11433,12 @@ static int cmdloop(int top) { n = parsecmd(inter); /* showtree(n); DEBUG */ if (n == NEOF) { - if (!top || numeof >= 50) break; + if (!top || numeof >= 50) + break; if (!stoppedjobs()) { if (!Iflag) { - if (iflag) outcslow('\n', out2); + if (iflag) + outcslow('\n', out2); break; } outstr("\nUse \"exit\" to leave shell.\n", out2); @@ -10979,7 +11449,8 @@ static int cmdloop(int top) { job_warning = (job_warning == 2) ? 1 : 0; numeof = 0; i = evaltree(n, 0); - if (n) status = i; + if (n) + status = i; } popstackmark(&smark); skip = evalskip; @@ -10996,7 +11467,8 @@ static int cmdloop(int top) { */ static void read_profile(const char *name) { name = expandstr(name); - if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) return; + if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) + return; cmdloop(0); popfile(); } @@ -11011,7 +11483,8 @@ static char *find_dot_file(char *basename) { struct stat statb; int len; /* don't try this for absolute or relative paths */ - if (strchr(basename, '/')) return basename; + if (strchr(basename, '/')) + return basename; while ((len = padvance(&path, basename)) >= 0) { fullname = stackblock(); if ((!pathopt || *pathopt == 'f') && !stat(fullname, &statb) && @@ -11040,8 +11513,10 @@ static int dotcmd(int argc, char **argv) { } static int exitcmd(int argc, char **argv) { - if (stoppedjobs()) return 0; - if (argc > 1) savestatus = number(argv[1]); + if (stoppedjobs()) + return 0; + if (argc > 1) + savestatus = number(argv[1]); exraise(EXEXIT); } @@ -11064,7 +11539,8 @@ int main(int argc, char **argv) { exitreset(); e = exception; s = state; - if (e == EXEND || e == EXEXIT || s == 0 || iflag == 0 || shlvl) exitshell(); + if (e == EXEND || e == EXEXIT || s == 0 || iflag == 0 || shlvl) + exitshell(); reset(); if (e == EXINT) { outcslow('\n', out2); @@ -11103,7 +11579,8 @@ state2: popstackmark(&smark); state3: state = 4; - if (minusc) evalstring(minusc, sflag ? 0 : EV_EXIT); + if (minusc) + evalstring(minusc, sflag ? 0 : EV_EXIT); if (sflag || minusc == NULL) { state4: /* XXX ??? - why isn't this before the "if" statement */ cmdloop(1); diff --git a/examples/walk.c b/examples/walk.c index 09df2ddfd..b41f6d981 100644 --- a/examples/walk.c +++ b/examples/walk.c @@ -44,8 +44,10 @@ static int display_info(const char *fpath, const struct stat *sb, int tflag, int main(int argc, char *argv[]) { int flags = 0; const char *dir; - if (argc > 2 && strchr(argv[2], 'd') != NULL) flags |= FTW_DEPTH; - if (argc > 2 && strchr(argv[2], 'p') != NULL) flags |= FTW_PHYS; + if (argc > 2 && strchr(argv[2], 'd') != NULL) + flags |= FTW_DEPTH; + if (argc > 2 && strchr(argv[2], 'p') != NULL) + flags |= FTW_PHYS; dir = argc < 2 ? "." : argv[1]; if (nftw(dir, display_info, 20, flags) == -1) { fprintf(stderr, "nftw() failed: %s: %s\n", strerror(errno), dir); diff --git a/examples/wall.c b/examples/wall.c index 6b6eeddc2..e0fece754 100644 --- a/examples/wall.c +++ b/examples/wall.c @@ -96,7 +96,8 @@ int main(int argc, char *argv[]) { appends(&msg, "\e[1m"); // bold text appendf(&msg, "Broadcast message from %s@%s", getpwuid(getuid())->pw_name, GetHost()); - if (isatty(0) && (s = ttyname(0))) appendf(&msg, " (%s)", s); + if (isatty(0) && (s = ttyname(0))) + appendf(&msg, " (%s)", s); appendf(&msg, " (%s):\r\n", GetTime()); appends(&msg, "\e[K"); @@ -104,7 +105,8 @@ int main(int argc, char *argv[]) { if (optind < argc) { // use cli arguments as message if they exist for (int i = 0; optind + i < argc; ++i) { - if (i) appends(&msg, " "); + if (i) + appends(&msg, " "); for (s = argv[optind + i]; *s; ++s) { if (*s == '\n') { appends(&msg, "\r\n\e[K"); @@ -135,8 +137,10 @@ int main(int argc, char *argv[]) { char pts[32]; snprintf(pts, sizeof(pts), "/dev/pts/%d", i); if ((fd = open(pts, O_WRONLY | O_NOCTTY)) == -1) { - if (errno == ENOENT) continue; - if (g_verbose) perror(pts); + if (errno == ENOENT) + continue; + if (g_verbose) + perror(pts); } write(fd, msg, appendz(msg).i); close(fd); diff --git a/libc/calls/_ptsname.c b/libc/calls/_ptsname.c index a44cc6b54..d28b229ec 100644 --- a/libc/calls/_ptsname.c +++ b/libc/calls/_ptsname.c @@ -59,7 +59,8 @@ int _ptsname(int fd, char *buf, size_t size) { t.sn[5] = 0; if (IsLinux()) { - if (sys_ioctl(fd, TIOCGPTN, &pty)) return -1; + if (sys_ioctl(fd, TIOCGPTN, &pty)) + return -1; t.sn[5] = 'p'; t.sn[6] = 't'; t.sn[7] = 's'; diff --git a/libc/calls/cfspeed.c b/libc/calls/cfspeed.c index 4aaeee2bc..9ecbe2517 100644 --- a/libc/calls/cfspeed.c +++ b/libc/calls/cfspeed.c @@ -101,7 +101,9 @@ int cfsetispeed(struct termios *t, uint32_t speed) { * @asyncsignalsafe */ int cfsetspeed(struct termios *t, uint32_t speed) { - if (cfsetispeed(t, speed) == -1) return -1; - if (cfsetospeed(t, speed) == -1) return -1; + if (cfsetispeed(t, speed) == -1) + return -1; + if (cfsetospeed(t, speed) == -1) + return -1; return 0; } diff --git a/libc/calls/chdir-nt.c b/libc/calls/chdir-nt.c index 9982d36ca..ebc052c5a 100644 --- a/libc/calls/chdir-nt.c +++ b/libc/calls/chdir-nt.c @@ -33,7 +33,8 @@ textwindows int sys_chdir_nt_impl(char16_t path[hasatleast PATH_MAX], char16_t var[4]; if (len && path[len - 1] != u'\\') { - if (len + 2 > PATH_MAX) return enametoolong(); + if (len + 2 > PATH_MAX) + return enametoolong(); path[len + 0] = u'\\'; path[len + 1] = u'\0'; } @@ -84,7 +85,9 @@ textwindows int sys_chdir_nt_impl(char16_t path[hasatleast PATH_MAX], textwindows int sys_chdir_nt(const char *path) { int len; char16_t path16[PATH_MAX]; - if ((len = __mkntpath(path, path16)) == -1) return -1; - if (!len) return enoent(); + if ((len = __mkntpath(path, path16)) == -1) + return -1; + if (!len) + return enoent(); return sys_chdir_nt_impl(path16, len); } diff --git a/libc/calls/checksignal.c b/libc/calls/checksignal.c index 07f34d55f..be2221676 100644 --- a/libc/calls/checksignal.c +++ b/libc/calls/checksignal.c @@ -24,11 +24,16 @@ textwindows int _check_signal(bool restartable) { int status; - if (_check_cancel() == -1) return -1; - if (!_weaken(__sig_check)) return 0; - if (!(status = _weaken(__sig_check)())) return 0; - if (_check_cancel() == -1) return -1; - if (status == 2 && restartable) return 0; + if (_check_cancel() == -1) + return -1; + if (!_weaken(__sig_check)) + return 0; + if (!(status = _weaken(__sig_check)())) + return 0; + if (_check_cancel() == -1) + return -1; + if (status == 2 && restartable) + return 0; return eintr(); } diff --git a/libc/calls/clktck.c b/libc/calls/clktck.c index 1436a0ffa..ead1400e0 100644 --- a/libc/calls/clktck.c +++ b/libc/calls/clktck.c @@ -61,7 +61,8 @@ static dontinline int __clk_tck_init(void) { } else { x = __getauxval(AT_CLKTCK).value; } - if (x < 1) x = 100; + if (x < 1) + x = 100; clk_tck = x; return x; } diff --git a/libc/calls/clock_gettime-mono.c b/libc/calls/clock_gettime-mono.c index d65a288dd..3bc38f37f 100644 --- a/libc/calls/clock_gettime-mono.c +++ b/libc/calls/clock_gettime-mono.c @@ -44,7 +44,8 @@ int sys_clock_gettime_mono(struct timespec *time) { #ifdef __x86_64__ // intel architecture guarantees that a mapping exists between rdtsc & // nanoseconds only if the cpu advertises invariant timestamps support - if (!X86_HAVE(INVTSC)) return -EINVAL; + if (!X86_HAVE(INVTSC)) + return -EINVAL; #endif cosmo_once(&g_mono.once, sys_clock_gettime_mono_init); cycles = rdtsc() - g_mono.base_tick; diff --git a/libc/calls/clock_gettime-xnu.c b/libc/calls/clock_gettime-xnu.c index d0a7c9427..990f87331 100644 --- a/libc/calls/clock_gettime-xnu.c +++ b/libc/calls/clock_gettime-xnu.c @@ -60,14 +60,17 @@ int sys_clock_gettime_xnu(int clock, struct timespec *ts) { } return 0; } else if (clock == CLOCK_MONOTONIC) { - if (!ts) return 0; + if (!ts) + return 0; return sys_clock_gettime_mono(ts); } else if (clock == CLOCK_BOOTTIME) { struct timeval x; size_t n = sizeof(x); int mib[] = {CTL_KERN, KERN_BOOTTIME}; - if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return -1; - if (ts) *ts = timeval_totimespec(timeval_sub(timeval_real(), x)); + if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) + return -1; + if (ts) + *ts = timeval_totimespec(timeval_sub(timeval_real(), x)); return 0; } else { return -EINVAL; diff --git a/libc/calls/clock_nanosleep-cosmo.c b/libc/calls/clock_nanosleep-cosmo.c index ca438eac4..f49c4c50f 100644 --- a/libc/calls/clock_nanosleep-cosmo.c +++ b/libc/calls/clock_nanosleep-cosmo.c @@ -57,7 +57,8 @@ int cosmo_clock_nanosleep(int clock, int flags, const struct timespec *req, struct timespec quantum = timespec_fromnanos(1000000000 / CLK_TCK); clock_gettime(time_clock, &start); deadline = flags & TIMER_ABSTIME ? *req : timespec_add(start, *req); - if (timespec_cmp(start, deadline) >= 0) return 0; + if (timespec_cmp(start, deadline) >= 0) + return 0; remain = timespec_sub(deadline, start); if (timespec_cmp(remain, quantum) > 0) { waitfor = timespec_sub(remain, quantum); diff --git a/libc/calls/clock_nanosleep-nt.c b/libc/calls/clock_nanosleep-nt.c index 3d17adddf..6d7adc5be 100644 --- a/libc/calls/clock_nanosleep-nt.c +++ b/libc/calls/clock_nanosleep-nt.c @@ -32,10 +32,13 @@ static textwindows int sys_clock_nanosleep_nt_impl(int clock, uint32_t msdelay; struct timespec now; for (;;) { - if (sys_clock_gettime_nt(clock, &now)) return -1; - if (timespec_cmp(now, abs) >= 0) return 0; + if (sys_clock_gettime_nt(clock, &now)) + return -1; + if (timespec_cmp(now, abs) >= 0) + return 0; msdelay = timespec_tomillis(timespec_sub(abs, now)); - if (_park_norestart(msdelay, waitmask)) return -1; + if (_park_norestart(msdelay, waitmask)) + return -1; } } @@ -48,7 +51,8 @@ textwindows int sys_clock_nanosleep_nt(int clock, int flags, if (flags & TIMER_ABSTIME) { abs = *req; } else { - if ((rc = sys_clock_gettime_nt(clock, &now))) goto BailOut; + if ((rc = sys_clock_gettime_nt(clock, &now))) + goto BailOut; abs = timespec_add(now, *req); } rc = sys_clock_nanosleep_nt_impl(clock, abs, m); diff --git a/libc/calls/clock_nanosleep-xnu.c b/libc/calls/clock_nanosleep-xnu.c index 249759272..23d0f2125 100644 --- a/libc/calls/clock_nanosleep-xnu.c +++ b/libc/calls/clock_nanosleep-xnu.c @@ -46,7 +46,8 @@ int sys_clock_nanosleep_xnu(int clock, int flags, const struct timespec *req, } else { int rc; struct timespec beg; - if (rem) sys_clock_gettime_xnu(CLOCK_REALTIME, &beg); + if (rem) + sys_clock_gettime_xnu(CLOCK_REALTIME, &beg); struct timeval rel = timespec_totimeval(*req); // rounds up rc = sys_select(0, 0, 0, 0, &rel); if (rc == -1 && rem && errno == EINTR) { diff --git a/libc/calls/close-nt.c b/libc/calls/close-nt.c index 79199b3e7..5d5b49645 100644 --- a/libc/calls/close-nt.c +++ b/libc/calls/close-nt.c @@ -30,7 +30,8 @@ #include "libc/sysv/errfuns.h" textwindows int sys_close_nt(int fd, int fildes) { - if (fd + 0u >= g_fds.n) return ebadf(); + if (fd + 0u >= g_fds.n) + return ebadf(); struct Fd *f = g_fds.p + fd; switch (f->kind) { case kFdZip: diff --git a/libc/calls/close.c b/libc/calls/close.c index 7c8a35f50..d054f8199 100644 --- a/libc/calls/close.c +++ b/libc/calls/close.c @@ -97,12 +97,14 @@ int close(int fd) { BLOCK_SIGNALS; __fds_lock(); rc = close_impl(fd); - if (!__vforked) __releasefd(fd); + if (!__vforked) + __releasefd(fd); __fds_unlock(); ALLOW_SIGNALS; } else { rc = close_impl(fd); - if (!__vforked) __releasefd(fd); + if (!__vforked) + __releasefd(fd); } STRACE("close(%d) → %d% m", fd, rc); return rc; diff --git a/libc/calls/copy.c b/libc/calls/copy.c index 5535e499d..8be9d5c36 100644 --- a/libc/calls/copy.c +++ b/libc/calls/copy.c @@ -37,10 +37,13 @@ ssize_t copyfd(int in, int out, size_t n) { ssize_t dr, dw; for (i = 0; i < n; i += dr) { dr = read(in, buf, MIN(n - i, sizeof(buf))); - if (dr == -1) return -1; - if (!dr) break; + if (dr == -1) + return -1; + if (!dr) + break; dw = write(out, buf, dr); - if (dw == -1) return -1; + if (dw == -1) + return -1; if (dw != dr) { // POSIX requires atomic IO up to PIPE_BUF // The minimum permissible PIPE_BUF is 512 diff --git a/libc/calls/createfileflags.c b/libc/calls/createfileflags.c index 17bd9f94c..5a7a08c26 100644 --- a/libc/calls/createfileflags.c +++ b/libc/calls/createfileflags.c @@ -156,9 +156,12 @@ textwindows int GetNtOpenFlags(int flags, int mode, uint32_t *out_perm, } // Not certain yet what benefit these flags offer. - if (flags & _O_SEQUENTIAL) attr |= kNtFileFlagSequentialScan; - if (flags & _O_RANDOM) attr |= kNtFileFlagRandomAccess; - if (flags & _O_DIRECT) attr |= kNtFileFlagNoBuffering; + if (flags & _O_SEQUENTIAL) + attr |= kNtFileFlagSequentialScan; + if (flags & _O_RANDOM) + attr |= kNtFileFlagRandomAccess; + if (flags & _O_DIRECT) + attr |= kNtFileFlagNoBuffering; // TODO(jart): Should we *always* open with write permission if the // kernel will give it to us? We'd then deny write access @@ -172,9 +175,13 @@ textwindows int GetNtOpenFlags(int flags, int mode, uint32_t *out_perm, // writing to a file across a network can occasionally return // kNtErrorAccessDenied." -Quoth MSDN - if (out_perm) *out_perm = perm; - if (out_share) *out_share = share; - if (out_disp) *out_disp = disp; - if (out_attr) *out_attr = attr; + if (out_perm) + *out_perm = perm; + if (out_share) + *out_share = share; + if (out_disp) + *out_disp = disp; + if (out_attr) + *out_attr = attr; return 0; } diff --git a/libc/calls/createpipename.c b/libc/calls/createpipename.c index 1a2550307..a5d518522 100644 --- a/libc/calls/createpipename.c +++ b/libc/calls/createpipename.c @@ -42,7 +42,8 @@ textwindows char16_t *__create_pipe_name(char16_t *a) { char16_t *p = a; const char *q = "\\\\?\\pipe\\cosmo\\"; static atomic_uint x; - while (*q) *p++ = *q++; + while (*q) + *p++ = *q++; p = itoa16(p, __pid); *p++ = '-'; p = itoa16(p, atomic_fetch_add(&x, 1)); diff --git a/libc/calls/dup2.c b/libc/calls/dup2.c index a1c370879..72d0f3e38 100644 --- a/libc/calls/dup2.c +++ b/libc/calls/dup2.c @@ -66,12 +66,14 @@ int dup2(int oldfd, int newfd) { int rc; // helps guarantee stderr log gets duplicated before user closes - if (_weaken(kloghandle)) _weaken(kloghandle)(); + if (_weaken(kloghandle)) + _weaken(kloghandle)(); #ifdef __aarch64__ if (oldfd == newfd) { // linux aarch64 defines dup3() but not dup2(), which wasn't such a // great decision, since the two syscalls don't behave the same way - if (!(rc = read(oldfd, 0, 0))) rc = oldfd; + if (!(rc = read(oldfd, 0, 0))) + rc = oldfd; } else #endif if (!IsWindows()) { diff --git a/libc/calls/dup3.c b/libc/calls/dup3.c index 571a6e2c2..368942c61 100644 --- a/libc/calls/dup3.c +++ b/libc/calls/dup3.c @@ -65,7 +65,8 @@ int dup3(int oldfd, int newfd, int flags) { int rc; // helps guarantee stderr log gets duplicated before user closes - if (_weaken(kloghandle)) _weaken(kloghandle)(); + if (_weaken(kloghandle)) + _weaken(kloghandle)(); if (oldfd == newfd || (flags & ~O_CLOEXEC)) { rc = einval(); // NetBSD doesn't do this } else if (oldfd < 0 || newfd < 0) { diff --git a/libc/calls/faccessat-nt.c b/libc/calls/faccessat-nt.c index 17ded7bfe..a51ce3d7a 100644 --- a/libc/calls/faccessat-nt.c +++ b/libc/calls/faccessat-nt.c @@ -24,6 +24,7 @@ textwindows int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) { char16_t path16[PATH_MAX]; - if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; + if (__mkntpathat(dirfd, path, 0, path16) == -1) + return -1; return __fix_enotdir(ntaccesscheck(path16, mode), path16); } diff --git a/libc/calls/faccessat.c b/libc/calls/faccessat.c index bcd940e35..c5f3066e0 100644 --- a/libc/calls/faccessat.c +++ b/libc/calls/faccessat.c @@ -64,7 +64,8 @@ int faccessat(int dirfd, const char *path, int amode, int flags) { rc = _weaken(__zipos_access)(&zipname, amode); } else if (!IsWindows()) { e = errno; - if (!flags) goto NoFlags; + if (!flags) + goto NoFlags; if ((rc = sys_faccessat2(dirfd, path, amode, flags)) == -1) { if (errno == ENOSYS) { errno = e; diff --git a/libc/calls/fadvise-nt.c b/libc/calls/fadvise-nt.c index 974e4d297..d57ff504f 100644 --- a/libc/calls/fadvise-nt.c +++ b/libc/calls/fadvise-nt.c @@ -37,8 +37,10 @@ static textwindows int sys_fadvise_nt_impl(int fd, uint64_t offset, int rc, flags, mode; uint32_t perm, share, attr; - if ((int64_t)len < 0) return einval(); - if (!__isfdkind(fd, kFdFile)) return ebadf(); + if ((int64_t)len < 0) + return einval(); + if (!__isfdkind(fd, kFdFile)) + return ebadf(); h1 = g_fds.p[fd].handle; mode = g_fds.p[fd].mode; flags = g_fds.p[fd].flags; diff --git a/libc/calls/fchdir-nt.c b/libc/calls/fchdir-nt.c index 60835ce06..561f6d838 100644 --- a/libc/calls/fchdir-nt.c +++ b/libc/calls/fchdir-nt.c @@ -27,7 +27,8 @@ int sys_chdir_nt_impl(char16_t[hasatleast PATH_MAX], uint32_t); textwindows int sys_fchdir_nt(int dirfd) { char16_t dir[PATH_MAX]; - if (!__isfdkind(dirfd, kFdFile)) return ebadf(); + if (!__isfdkind(dirfd, kFdFile)) + return ebadf(); return sys_chdir_nt_impl( dir, GetFinalPathNameByHandle(g_fds.p[dirfd].handle, dir, ARRAYLEN(dir), kNtFileNameNormalized | kNtVolumeNameDos)); diff --git a/libc/calls/fchmod-nt.c b/libc/calls/fchmod-nt.c index 85797486b..5b31226c0 100644 --- a/libc/calls/fchmod-nt.c +++ b/libc/calls/fchmod-nt.c @@ -29,8 +29,10 @@ textwindows int sys_fchmod_nt(int fd, uint32_t mode) { // validate file descriptor - if (fd + 0u >= g_fds.n) return ebadf(); - if (g_fds.p[fd].kind == kFdEmpty) return ebadf(); + if (fd + 0u >= g_fds.n) + return ebadf(); + if (g_fds.p[fd].kind == kFdEmpty) + return ebadf(); // get current information struct NtFileBasicInfo fbi; diff --git a/libc/calls/fchmodat-nt.c b/libc/calls/fchmodat-nt.c index 473c6c3ae..fe275e498 100644 --- a/libc/calls/fchmodat-nt.c +++ b/libc/calls/fchmodat-nt.c @@ -26,7 +26,8 @@ textwindows int sys_fchmodat_nt(int dirfd, const char *path, uint32_t mode, int flags) { uint32_t attr; uint16_t path16[PATH_MAX]; - if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; + if (__mkntpathat(dirfd, path, 0, path16) == -1) + return -1; if ((attr = GetFileAttributes(path16)) != -1u) { if (mode & 0222) { attr &= ~kNtFileAttributeReadonly; diff --git a/libc/calls/fcntl-nt.c b/libc/calls/fcntl-nt.c index dfa70b74f..09483e6e1 100644 --- a/libc/calls/fcntl-nt.c +++ b/libc/calls/fcntl-nt.c @@ -129,7 +129,8 @@ textwindows void sys_fcntl_nt_lock_cleanup(int fd) { static textwindows int64_t GetfileSize(int64_t handle) { struct NtByHandleFileInformation wst; - if (!GetFileInformationByHandle(handle, &wst)) return __winerr(); + if (!GetFileInformationByHandle(handle, &wst)) + return __winerr(); return (wst.nFileSizeHigh + 0ull) << 32 | wst.nFileSizeLow; } @@ -156,7 +157,8 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, break; case SEEK_END: { int64_t size; - if ((size = GetfileSize(f->handle)) == -1) return -1; + if ((size = GetfileSize(f->handle)) == -1) + return -1; off = size - off; break; } @@ -254,7 +256,8 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, } if (l->l_type == F_UNLCK) { - if (cmd == F_GETLK) return einval(); + if (cmd == F_GETLK) + return einval(); // allow a big range to unlock many small ranges for (flp = &g_locks.list, fl = *flp; fl;) { @@ -318,7 +321,8 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, } static textwindows int sys_fcntl_nt_dupfd(int fd, int cmd, int start) { - if (start < 0) return einval(); + if (start < 0) + return einval(); return sys_dup_nt(fd, -1, (cmd == F_DUPFD_CLOEXEC ? _O_CLOEXEC : 0), start); } diff --git a/libc/calls/fdatasync-nt.c b/libc/calls/fdatasync-nt.c index a39a8d685..ae48d9459 100644 --- a/libc/calls/fdatasync-nt.c +++ b/libc/calls/fdatasync-nt.c @@ -27,17 +27,23 @@ textwindows int sys_fdatasync_nt(int fd, bool fake) { struct NtByHandleFileInformation wst; - if (!__isfdopen(fd)) return ebadf(); - if (!__isfdkind(fd, kFdFile)) return einval(); - if (GetFileType(g_fds.p[fd].handle) != kNtFileTypeDisk) return einval(); - if (!GetFileInformationByHandle(g_fds.p[fd].handle, &wst)) return __winerr(); + if (!__isfdopen(fd)) + return ebadf(); + if (!__isfdkind(fd, kFdFile)) + return einval(); + if (GetFileType(g_fds.p[fd].handle) != kNtFileTypeDisk) + return einval(); + if (!GetFileInformationByHandle(g_fds.p[fd].handle, &wst)) + return __winerr(); if (wst.dwFileAttributes & kNtFileAttributeDirectory) { // Flushing a directory handle is possible, but it needs // kNtGenericWrite access, and MSDN doesn't document it. return 0; } - if (fake) return 0; - if (_check_signal(false) == -1) return -1; + if (fake) + return 0; + if (_check_signal(false) == -1) + return -1; return FlushFileBuffers(g_fds.p[fd].handle) ? 0 : __winerr(); } diff --git a/libc/calls/flock-nt.c b/libc/calls/flock-nt.c index 13c8814bc..734362ffa 100644 --- a/libc/calls/flock-nt.c +++ b/libc/calls/flock-nt.c @@ -34,7 +34,8 @@ textwindows int sys_flock_nt(int fd, int op) { int64_t h; struct NtByHandleFileInformation info; - if (!__isfdkind(fd, kFdFile)) return ebadf(); + if (!__isfdkind(fd, kFdFile)) + return ebadf(); h = g_fds.p[fd].handle; struct NtOverlapped ov = {.hEvent = h}; diff --git a/libc/calls/fstat-metal.c b/libc/calls/fstat-metal.c index 3c35c569b..1ca05ad79 100644 --- a/libc/calls/fstat-metal.c +++ b/libc/calls/fstat-metal.c @@ -23,7 +23,8 @@ #include "libc/sysv/errfuns.h" int sys_fstat_metal(int fd, struct stat *st) { - if (fd < 0) return einval(); + if (fd < 0) + return einval(); if (fd < g_fds.n && g_fds.p[fd].kind == kFdSerial) { bzero(st, sizeof(*st)); st->st_dev = g_fds.p[fd].handle; diff --git a/libc/calls/fstat-nt.c b/libc/calls/fstat-nt.c index c5b54def5..9fd4874cf 100644 --- a/libc/calls/fstat-nt.c +++ b/libc/calls/fstat-nt.c @@ -97,7 +97,8 @@ textwindows int sys_fstat_nt_special(int kind, struct stat *st) { } textwindows int sys_fstat_nt(int fd, struct stat *st) { - if (fd + 0u >= g_fds.n) return ebadf(); + if (fd + 0u >= g_fds.n) + return ebadf(); switch (g_fds.p[fd].kind) { case kFdEmpty: return ebadf(); @@ -174,7 +175,8 @@ textwindows int sys_fstat_nt_handle(int64_t handle, const char16_t *path, if (S_ISLNK(st.st_mode)) { if (!st.st_size) { long size = GetSizeOfReparsePoint(handle); - if (size == -1) return -1; + if (size == -1) + return -1; st.st_size = size; } } else { diff --git a/libc/calls/fstatat-nt.c b/libc/calls/fstatat-nt.c index 821b07e6e..63e24b9b4 100644 --- a/libc/calls/fstatat-nt.c +++ b/libc/calls/fstatat-nt.c @@ -36,7 +36,8 @@ static int Atoi(const char *str) { int c; unsigned x = 0; - if (!*str) return -1; + if (!*str) + return -1; while ((c = *str++)) { if ('0' <= c && c <= '9') { x *= 10; diff --git a/libc/calls/fstatat.c b/libc/calls/fstatat.c index 5c164df3e..ebb291cef 100644 --- a/libc/calls/fstatat.c +++ b/libc/calls/fstatat.c @@ -35,7 +35,8 @@ #include "libc/sysv/errfuns.h" static inline const char *__strace_fstatat_flags(char buf[12], int flags) { - if (flags == AT_SYMLINK_NOFOLLOW) return "AT_SYMLINK_NOFOLLOW"; + if (flags == AT_SYMLINK_NOFOLLOW) + return "AT_SYMLINK_NOFOLLOW"; FormatInt32(buf, flags); return buf; } diff --git a/libc/calls/fstatfs-nt.c b/libc/calls/fstatfs-nt.c index b58d708fa..06c0ce515 100644 --- a/libc/calls/fstatfs-nt.c +++ b/libc/calls/fstatfs-nt.c @@ -54,7 +54,8 @@ textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) { st = NtQueryVolumeInformationFile(handle, &io, &fs, sizeof(fs), kNtFileFsFullSizeInformation); if (!NtSuccess(st)) { - if (st == kNtStatusDllNotFound) return enosys(); + if (st == kNtStatusDllNotFound) + return enosys(); return eio(); } for (h = j = i = 0; FileSystemNameBuffer[i]; i++) { diff --git a/libc/calls/ftok.c b/libc/calls/ftok.c index 641643729..012a048f2 100644 --- a/libc/calls/ftok.c +++ b/libc/calls/ftok.c @@ -26,6 +26,7 @@ */ int ftok(const char *path, int id) { struct stat st; - if (stat(path, &st) == -1) return -1; + if (stat(path, &st) == -1) + return -1; return (uint32_t)id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff); } diff --git a/libc/calls/getcpu.c b/libc/calls/getcpu.c index c25c52bad..900a04ec3 100644 --- a/libc/calls/getcpu.c +++ b/libc/calls/getcpu.c @@ -64,7 +64,8 @@ int getcpu(unsigned *out_opt_cpu, unsigned *out_opt_node) { } } else { int rc = sys_getcpu(&cpu, &node, 0); - if (rc == -1) return -1; + if (rc == -1) + return -1; } if (out_opt_cpu) { *out_opt_cpu = cpu; diff --git a/libc/calls/getcwd.greg.c b/libc/calls/getcwd.greg.c index ead09a218..edabb8af1 100644 --- a/libc/calls/getcwd.greg.c +++ b/libc/calls/getcwd.greg.c @@ -82,14 +82,17 @@ static dontinline textwindows int sys_getcwd_nt(char *buf, size_t size) { // get current directory from the system char16_t p16[PATH_MAX]; uint32_t n = GetCurrentDirectory(PATH_MAX, p16); - if (!n) return eacces(); // system call failed - if (n >= PATH_MAX) return erange(); // not enough room?!? + if (!n) + return eacces(); // system call failed + if (n >= PATH_MAX) + return erange(); // not enough room?!? // convert utf-16 to utf-8 // we can't modify `buf` until we're certain of success char p8[PATH_MAX], *p = p8; n = tprecode16to8(p, PATH_MAX, p16).ax; - if (n >= PATH_MAX) return erange(); // utf-8 explosion + if (n >= PATH_MAX) + return erange(); // utf-8 explosion // turn \\?\c:\... into c:\... if (p[0] == '\\' && // diff --git a/libc/calls/getloadavg.c b/libc/calls/getloadavg.c index b28291eff..818a63c67 100644 --- a/libc/calls/getloadavg.c +++ b/libc/calls/getloadavg.c @@ -43,7 +43,8 @@ struct loadavg { int getloadavg(double *a, int n) { // cat /proc/loadavg int i, rc; - if (n > 3) n = 3; + if (n > 3) + n = 3; if (!n) { rc = 0; } else if (n < 0) { diff --git a/libc/calls/getrandom-metal.c b/libc/calls/getrandom-metal.c index cc757981a..573470290 100644 --- a/libc/calls/getrandom-metal.c +++ b/libc/calls/getrandom-metal.c @@ -64,7 +64,8 @@ static ssize_t GetRandomCpu(char *p, size_t n, int f, bool impl(uint64_t *)) { for (i = 0; i < n; i += j) { TryAgain: if (!impl(&x)) { - if (f || i >= 256) break; + if (f || i >= 256) + break; goto TryAgain; } for (j = 0; j < 8 && i + j < n; ++j) { diff --git a/libc/calls/getrandom.c b/libc/calls/getrandom.c index cdc7b13e5..643801fac 100644 --- a/libc/calls/getrandom.c +++ b/libc/calls/getrandom.c @@ -60,7 +60,8 @@ static bool have_getrandom; static void GetRandomEntropy(char *p, size_t n) { unassert(n <= 256); - if (sys_getentropy(p, n)) notpossible; + if (sys_getentropy(p, n)) + notpossible; } static void GetRandomArnd(char *p, size_t n) { @@ -69,8 +70,10 @@ static void GetRandomArnd(char *p, size_t n) { cmd[0] = 1; // CTL_KERN cmd[1] = IsFreebsd() ? 37 : 81; // KERN_ARND unassert((m = n) <= 256); - if (sys_sysctl(cmd, 2, p, &n, 0, 0) == -1) notpossible; - if (m != n) notpossible; + if (sys_sysctl(cmd, 2, p, &n, 0, 0) == -1) + notpossible; + if (m != n) + notpossible; } static ssize_t GetRandomBsd(char *p, size_t n, void impl(char *, size_t)) { @@ -193,7 +196,8 @@ ssize_t getrandom(void *p, size_t n, unsigned f) { __attribute__((__constructor__(30))) static textstartup void getrandom_init( void) { int e, rc; - if (IsWindows() || IsMetal()) return; + if (IsWindows() || IsMetal()) + return; BLOCK_CANCELATION; e = errno; if (!(rc = sys_getrandom(0, 0, 0))) { diff --git a/libc/calls/getresgid.c b/libc/calls/getresgid.c index 3cdd4c31a..53edea9f1 100644 --- a/libc/calls/getresgid.c +++ b/libc/calls/getresgid.c @@ -34,15 +34,20 @@ int getresgid(uint32_t *real, uint32_t *effective, uint32_t *saved) { int rc, gid; if (IsWindows()) { gid = getgid(); - if (real) *real = gid; - if (effective) *effective = gid; - if (saved) *saved = gid; + if (real) + *real = gid; + if (effective) + *effective = gid; + if (saved) + *saved = gid; rc = 0; } else if (saved) { rc = sys_getresgid(real, effective, saved); } else { - if (real) *real = sys_getgid(); - if (effective) *effective = sys_getegid(); + if (real) + *real = sys_getgid(); + if (effective) + *effective = sys_getegid(); rc = 0; } STRACE("getresgid([%d], [%d], [%d]) → %d% m", real ? *real : 0, diff --git a/libc/calls/getresuid.c b/libc/calls/getresuid.c index 02959c9ab..7234882e1 100644 --- a/libc/calls/getresuid.c +++ b/libc/calls/getresuid.c @@ -34,15 +34,20 @@ int getresuid(uint32_t *real, uint32_t *effective, uint32_t *saved) { int rc, uid; if (IsWindows()) { uid = getuid(); - if (real) *real = uid; - if (effective) *effective = uid; - if (saved) *saved = uid; + if (real) + *real = uid; + if (effective) + *effective = uid; + if (saved) + *saved = uid; rc = 0; } else if (saved) { rc = sys_getresuid(real, effective, saved); } else { - if (real) *real = sys_getuid(); - if (effective) *effective = sys_geteuid(); + if (real) + *real = sys_getuid(); + if (effective) + *effective = sys_geteuid(); rc = 0; } STRACE("getresuid([%d], [%d], [%d]) → %d% m", real ? *real : 0, diff --git a/libc/calls/getsystemdirectorypath.c b/libc/calls/getsystemdirectorypath.c index 4030e3913..9d0b7f74e 100644 --- a/libc/calls/getsystemdirectorypath.c +++ b/libc/calls/getsystemdirectorypath.c @@ -25,7 +25,8 @@ textwindows char *GetSystemDirectoryPath(char *buf, const char *path, uint32_t syslen = GetSystemDirectoryA(buf, size); size_t pathlen = strlen(path); if (syslen && syslen + pathlen + 1 < size) { - if (buf[syslen] == '\\') --syslen; + if (buf[syslen] == '\\') + --syslen; memcpy(buf + syslen, path, pathlen + 1); return buf; } else { diff --git a/libc/calls/getuid-nt.c b/libc/calls/getuid-nt.c index 7a8896ee9..7f191db4e 100644 --- a/libc/calls/getuid-nt.c +++ b/libc/calls/getuid-nt.c @@ -29,7 +29,8 @@ textwindows uint32_t sys_getuid_nt(void) { if (!(tmp = atomic_load_explicit(&uid, memory_order_acquire))) { GetUserName(&buf, &size); tmp = __fnv(buf, size >> 1) & 32767; - if (!tmp) ++tmp; + if (!tmp) + ++tmp; atomic_store_explicit(&uid, tmp, memory_order_release); } return tmp; diff --git a/libc/calls/ioctl.c b/libc/calls/ioctl.c index 9416c03c7..4d96e6d61 100644 --- a/libc/calls/ioctl.c +++ b/libc/calls/ioctl.c @@ -244,11 +244,16 @@ static textwindows struct HostAdapterInfoNode *appendHostInfo( * IFF_PROMISC ** NOT SUPPORTED, unknown how to retrieve it */ flags = 0; - if (aa->OperStatus == kNtIfOperStatusUp) flags |= IFF_UP | IFF_RUNNING; - if (aa->IfType == kNtIfTypePpp) flags |= IFF_POINTOPOINT; - if (!(aa->Flags & kNtIpAdapterNoMulticast)) flags |= IFF_MULTICAST; - if (aa->IfType == kNtIfTypeSoftwareLoopback) flags |= IFF_LOOPBACK; - if (aa->FirstPrefix) flags |= IFF_BROADCAST; + if (aa->OperStatus == kNtIfOperStatusUp) + flags |= IFF_UP | IFF_RUNNING; + if (aa->IfType == kNtIfTypePpp) + flags |= IFF_POINTOPOINT; + if (!(aa->Flags & kNtIpAdapterNoMulticast)) + flags |= IFF_MULTICAST; + if (aa->IfType == kNtIfTypeSoftwareLoopback) + flags |= IFF_LOOPBACK; + if (aa->FirstPrefix) + flags |= IFF_BROADCAST; node->flags = flags; } else { /* Copy from previous node */ @@ -344,13 +349,16 @@ static textwindows int createHostInfo( baseName[IFNAMSIZ - 2] = '\0'; /* Replace any space with a '_' */ for (i = 0; i < IFNAMSIZ - 2; ++i) { - if (baseName[i] == ' ') baseName[i] = '_'; - if (!baseName[i]) break; + if (baseName[i] == ' ') + baseName[i] = '_'; + if (!baseName[i]) + break; } for (count = 0, ua = aa->FirstUnicastAddress, ap = aa->FirstPrefix; (ua != NULL) && (count < MAX_UNICAST_ADDR); ++count) { node = appendHostInfo(node, baseName, aa, &ua, &ap, count); - if (!node) goto err; + if (!node) + goto err; if (!__hostInfo) { __hostInfo = node; if (_cmpxchg(&once, false, true)) { @@ -444,7 +452,8 @@ static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) { static textwindows int ioctl_siocgifaddr_nt(int fd, struct ifreq *ifr) { struct HostAdapterInfoNode *node; node = findAdapterByName(ifr->ifr_name); - if (!node) return ebadf(); + if (!node) + return ebadf(); memcpy(&ifr->ifr_addr, &node->unicast, sizeof(struct sockaddr)); return 0; } @@ -453,7 +462,8 @@ static textwindows int ioctl_siocgifaddr_nt(int fd, struct ifreq *ifr) { static textwindows int ioctl_siocgifflags_nt(int fd, struct ifreq *ifr) { struct HostAdapterInfoNode *node; node = findAdapterByName(ifr->ifr_name); - if (!node) return ebadf(); + if (!node) + return ebadf(); ifr->ifr_flags = node->flags; return 0; } @@ -462,7 +472,8 @@ static textwindows int ioctl_siocgifflags_nt(int fd, struct ifreq *ifr) { static textwindows int ioctl_siocgifnetmask_nt(int fd, struct ifreq *ifr) { struct HostAdapterInfoNode *node; node = findAdapterByName(ifr->ifr_name); - if (!node) return ebadf(); + if (!node) + return ebadf(); memcpy(&ifr->ifr_netmask, &node->netmask, sizeof(struct sockaddr)); return 0; } @@ -473,7 +484,8 @@ static textwindows int ioctl_siocgifnetmask_nt(int fd, struct ifreq *ifr) { static textwindows int ioctl_siocgifbrdaddr_nt(int fd, struct ifreq *ifr) { struct HostAdapterInfoNode *node; node = findAdapterByName(ifr->ifr_name); - if (!node) return ebadf(); + if (!node) + return ebadf(); memcpy(&ifr->ifr_broadaddr, &node->broadcast, sizeof(struct sockaddr)); return 0; } @@ -513,7 +525,8 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { for (p = b, e = p + MIN(bufMax, READ32LE(ifcBsd)); p + 16 + 16 <= e; p += IsBsd() ? 16 + MAX(16, p[16] & 255) : 40) { fam = p[IsBsd() ? 17 : 16] & 255; - if (fam != AF_INET) continue; + if (fam != AF_INET) + continue; ip = READ32BE(p + 20); bzero(req, sizeof(*req)); memcpy(req->ifr_name, p, 16); @@ -541,8 +554,10 @@ static inline void ioctl_sockaddr2linux(void *saddr) { * requires adjustment between Linux and XNU */ static int ioctl_siocgifaddr_sysv(int fd, uint64_t op, struct ifreq *ifr) { - if (sys_ioctl(fd, op, ifr) == -1) return -1; - if (IsBsd()) ioctl_sockaddr2linux(&ifr->ifr_addr); + if (sys_ioctl(fd, op, ifr) == -1) + return -1; + if (IsBsd()) + ioctl_sockaddr2linux(&ifr->ifr_addr); return 0; } diff --git a/libc/calls/isdirectory-nt.c b/libc/calls/isdirectory-nt.c index 236b140c9..67a6cdcd8 100644 --- a/libc/calls/isdirectory-nt.c +++ b/libc/calls/isdirectory-nt.c @@ -28,7 +28,8 @@ bool isdirectory_nt(const char *path) { uint32_t x; char16_t path16[PATH_MAX]; - if (__mkntpath(path, path16) == -1) return -1; + if (__mkntpath(path, path16) == -1) + return -1; if ((x = GetFileAttributes(path16)) != -1u) { return !!(x & kNtFileAttributeDirectory); } else { diff --git a/libc/calls/isexecutable.c b/libc/calls/isexecutable.c index f09d0381c..8e33f9fad 100644 --- a/libc/calls/isexecutable.c +++ b/libc/calls/isexecutable.c @@ -30,6 +30,7 @@ */ bool32 isexecutable(const char *path) { struct stat st; - if (fstatat(AT_FDCWD, path, &st, 0)) return 0; + if (fstatat(AT_FDCWD, path, &st, 0)) + return 0; return !S_ISDIR(st.st_mode) && !!(st.st_mode & 0111); } diff --git a/libc/calls/islinux.c b/libc/calls/islinux.c index fe432298f..019016c70 100644 --- a/libc/calls/islinux.c +++ b/libc/calls/islinux.c @@ -33,7 +33,8 @@ static struct { static bool __is_linux_2_6_23_impl(void) { int rc; - if (IsGenuineBlink()) return true; + if (IsGenuineBlink()) + return true; asm volatile("syscall" : "=a"(rc) : "0"(157), "D"(PR_GET_SECCOMP) diff --git a/libc/calls/isregularfile-nt.c b/libc/calls/isregularfile-nt.c index 2b335b919..93df87776 100644 --- a/libc/calls/isregularfile-nt.c +++ b/libc/calls/isregularfile-nt.c @@ -28,7 +28,8 @@ bool isregularfile_nt(const char *path) { uint32_t x; char16_t path16[PATH_MAX]; - if (__mkntpath(path, path16) == -1) return -1; + if (__mkntpath(path, path16) == -1) + return -1; if ((x = GetFileAttributes(path16)) != -1u) { return !(x & (kNtFileAttributeDirectory | kNtFileAttributeReparsePoint)); } else { diff --git a/libc/calls/issymlink-nt.c b/libc/calls/issymlink-nt.c index 165473235..4d56f22cc 100644 --- a/libc/calls/issymlink-nt.c +++ b/libc/calls/issymlink-nt.c @@ -26,7 +26,8 @@ bool issymlink_nt(const char *path) { uint32_t x; char16_t path16[PATH_MAX]; - if (__mkntpath(path, path16) == -1) return -1; + if (__mkntpath(path, path16) == -1) + return -1; if ((x = GetFileAttributes(path16)) != -1u) { return !!(x & kNtFileAttributeReparsePoint); } else { diff --git a/libc/calls/makedirs.c b/libc/calls/makedirs.c index 8c5c77e72..6a319cbaf 100644 --- a/libc/calls/makedirs.c +++ b/libc/calls/makedirs.c @@ -52,31 +52,42 @@ int makedirs(const char *path, unsigned mode) { e = errno; n = strlen(path); - if (n >= PATH_MAX) return enametoolong(); + if (n >= PATH_MAX) + return enametoolong(); memcpy(buf, path, n + 1); i = n; // descend while (i) { - if (!mkdir(buf, mode)) break; + if (!mkdir(buf, mode)) + break; if (errno == EEXIST) { - if (i == n) goto CheckTop; + if (i == n) + goto CheckTop; break; } - if (errno != ENOENT) return -1; - while (i && buf[i - 1] == '/') buf[--i] = 0; - while (i && buf[i - 1] != '/') buf[--i] = 0; + if (errno != ENOENT) + return -1; + while (i && buf[i - 1] == '/') + buf[--i] = 0; + while (i && buf[i - 1] != '/') + buf[--i] = 0; } // ascend for (;;) { if (mkdir(buf, mode)) { - if (errno != EEXIST) return -1; - if (i == n) goto CheckTop; + if (errno != EEXIST) + return -1; + if (i == n) + goto CheckTop; } - if (i == n) break; - while (i < n && (c = path[i]) != '/') buf[i++] = c; - while (i < n && (c = path[i]) == '/') buf[i++] = c; + if (i == n) + break; + while (i < n && (c = path[i]) != '/') + buf[i++] = c; + while (i < n && (c = path[i]) == '/') + buf[i++] = c; } Finish: @@ -84,7 +95,9 @@ Finish: return 0; CheckTop: - if (stat(path, &st)) return -1; - if (S_ISDIR(st.st_mode)) goto Finish; + if (stat(path, &st)) + return -1; + if (S_ISDIR(st.st_mode)) + goto Finish; return eexist(); } diff --git a/libc/calls/mkdirat-nt.c b/libc/calls/mkdirat-nt.c index 5d1768740..efc9eabc8 100644 --- a/libc/calls/mkdirat-nt.c +++ b/libc/calls/mkdirat-nt.c @@ -23,7 +23,9 @@ textwindows int sys_mkdirat_nt(int dirfd, const char *path, uint32_t mode) { char16_t path16[PATH_MAX]; - if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; - if (CreateDirectory(path16, 0)) return 0; + if (__mkntpathat(dirfd, path, 0, path16) == -1) + return -1; + if (CreateDirectory(path16, 0)) + return 0; return __fix_enotdir(-1, path16); } diff --git a/libc/calls/mknod.c b/libc/calls/mknod.c index 172dd1017..75e7090ed 100644 --- a/libc/calls/mknod.c +++ b/libc/calls/mknod.c @@ -42,10 +42,14 @@ */ int mknod(const char *path, uint32_t mode, uint64_t dev) { int e, rc; - if (IsAsan() && !__asan_is_valid_str(path)) return efault(); - if (mode & S_IFREG) return creat(path, mode & ~S_IFREG); - if (mode & S_IFDIR) return mkdir(path, mode & ~S_IFDIR); - if (mode & S_IFIFO) return enosys(); // no named pipes! + if (IsAsan() && !__asan_is_valid_str(path)) + return efault(); + if (mode & S_IFREG) + return creat(path, mode & ~S_IFREG); + if (mode & S_IFDIR) + return mkdir(path, mode & ~S_IFDIR); + if (mode & S_IFIFO) + return enosys(); // no named pipes! if (!IsWindows()) { // TODO(jart): Whys there code out there w/ S_xxx passed via dev? e = errno; diff --git a/libc/calls/mkntcmdline.c b/libc/calls/mkntcmdline.c index 6f75dc75e..1ece520f4 100644 --- a/libc/calls/mkntcmdline.c +++ b/libc/calls/mkntcmdline.c @@ -86,7 +86,8 @@ textwindows int mkntcmdline(char16_t cmdline[32767], char *const argv[]) { size_t i, j, k, s; char argbuf[PATH_MAX]; for (k = i = 0; argv[i]; ++i) { - if (i) APPEND(u' '); + if (i) + APPEND(u' '); if (LooksLikeCosmoDrivePath(argv[i]) && strlcpy(argbuf, argv[i], PATH_MAX) < PATH_MAX) { mungentpath(argbuf); @@ -112,7 +113,8 @@ textwindows int mkntcmdline(char16_t cmdline[32767], char *const argv[]) { } } } - if (!x) break; + if (!x) + break; if (x == '\\') { ++slashes; } else if (x == '"') { @@ -125,7 +127,8 @@ textwindows int mkntcmdline(char16_t cmdline[32767], char *const argv[]) { } slashes = 0; uint32_t w = EncodeUtf16(x); - do APPEND(w); + do + APPEND(w); while ((w >>= 16)); } } diff --git a/libc/calls/mkntenvblock.c b/libc/calls/mkntenvblock.c index 827e213bb..9ea54b03e 100644 --- a/libc/calls/mkntenvblock.c +++ b/libc/calls/mkntenvblock.c @@ -44,9 +44,12 @@ static textwindows int Compare(const char *l, const char *r) { for (;;) { a = l[i] & 255; b = r[i] & 255; - if (a == '=') a = 0; - if (b == '=') b = 0; - if (a != b || !b) break; + if (a == '=') + a = 0; + if (b == '=') + b = 0; + if (a != b || !b) + break; ++i; } return a - b; @@ -56,13 +59,15 @@ static textwindows int InsertString(struct EnvBuilder *env, const char *str) { int c, i, cmp; char *var, *path = 0; - if (!str) return 0; + if (!str) + return 0; // copy key=val to buf var = env->buf + env->bufi; do { c = *str++; - if (env->bufi + 2 > 32767) return e2big(); + if (env->bufi + 2 > 32767) + return e2big(); env->buf[env->bufi++] = c; if (c == '=' && str[0] == '/' && IsAlpha(str[1]) && str[2] == '/') { path = env->buf + env->bufi; @@ -70,7 +75,8 @@ static textwindows int InsertString(struct EnvBuilder *env, const char *str) { } while (c); // fixup key=/c/... → key=c:\... - if (path) mungentpath(path); + if (path) + mungentpath(path); // append key=val to sorted list using insertion sort technique for (i = env->vari;; --i) { @@ -143,8 +149,10 @@ textwindows int mkntenvblock(char16_t envblock[32767], char *const envp[], #pragma GCC pop_options // load new environment into string pointer array and fix file paths - if (InsertStrings(&env, envp) == -1) return -1; - if (InsertStrings(&env, extravars) == -1) return -1; + if (InsertStrings(&env, envp) == -1) + return -1; + if (InsertStrings(&env, extravars) == -1) + return -1; if (environ) { // https://jpassing.com/2009/12/28/the-hidden-danger-of-forgetting-to-specify-systemroot-in-a-custom-environment-block/ e = __getenv(environ, "SYSTEMROOT"); diff --git a/libc/calls/mkntpath.c b/libc/calls/mkntpath.c index b0bad5f15..4b9f58641 100644 --- a/libc/calls/mkntpath.c +++ b/libc/calls/mkntpath.c @@ -54,8 +54,10 @@ textwindows size_t __normntpath(char16_t *p, size_t n) { (i + 1 < n && p[i + 1] == '.') && // (i + 2 == n || IsSlash(p[i + 2]))) { // matched "/../" or "/..$" - while (j && p[j - 1] == '\\') --j; - while (j && p[j - 1] != '\\') --j; + while (j && p[j - 1] == '\\') + --j; + while (j && p[j - 1] != '\\') + --j; } else { p[j++] = c; } @@ -156,7 +158,8 @@ textwindows int __mkntpath2(const char *path, if (!x && IsSlash(q[0]) && q[1] == 't' && q[2] == 'm' && q[3] == 'p' && (IsSlash(q[4]) || !q[4])) { m = GetTempPath(z, p); - if (!q[4]) return m; + if (!q[4]) + return m; q += 5; p += m; z -= m; diff --git a/libc/calls/mkntpathat.c b/libc/calls/mkntpathat.c index 8bddbf8d7..8eec12b4c 100644 --- a/libc/calls/mkntpathat.c +++ b/libc/calls/mkntpathat.c @@ -33,14 +33,19 @@ static textwindows int __mkntpathath_impl(int64_t dirhand, const char *path, size_t n; char16_t dir[PATH_MAX]; uint32_t dirlen, filelen; - if (!isutf8(path, -1)) return eilseq(); // thwart overlong nul in conversion - if ((filelen = __mkntpath2(path, file, flags)) == -1) return -1; - if (!filelen) return enoent(); + if (!isutf8(path, -1)) + return eilseq(); // thwart overlong nul in conversion + if ((filelen = __mkntpath2(path, file, flags)) == -1) + return -1; + if (!filelen) + return enoent(); if (file[0] != u'\\' && dirhand != AT_FDCWD) { // ProTip: \\?\C:\foo dirlen = GetFinalPathNameByHandle(dirhand, dir, ARRAYLEN(dir), kNtFileNameNormalized | kNtVolumeNameDos); - if (!dirlen) return __winerr(); - if (dirlen + 1 + filelen + 1 > ARRAYLEN(dir)) return enametoolong(); + if (!dirlen) + return __winerr(); + if (dirlen + 1 + filelen + 1 > ARRAYLEN(dir)) + return enametoolong(); dir[dirlen] = u'\\'; memcpy(dir + dirlen + 1, file, (filelen + 1) * sizeof(char16_t)); memcpy(file, dir, ((n = dirlen + 1 + filelen) + 1) * sizeof(char16_t)); diff --git a/libc/calls/mount.c b/libc/calls/mount.c index 1c1551f2c..ee383461c 100644 --- a/libc/calls/mount.c +++ b/libc/calls/mount.c @@ -84,7 +84,8 @@ int mount(const char *source, const char *target, const char *type, if (!IsBsd()) { return sys_mount_linux(source, target, type, flags, data); } else { - if (!strcmp(type, "iso9660")) type = "cd9660"; + if (!strcmp(type, "iso9660")) + type = "cd9660"; if (!strcmp(type, "vfat")) { if (IsOpenbsd() || IsNetbsd()) { type = "msdos"; diff --git a/libc/calls/mremap-sysv.greg.c b/libc/calls/mremap-sysv.greg.c index 9f66d45b8..e65d9af0a 100644 --- a/libc/calls/mremap-sysv.greg.c +++ b/libc/calls/mremap-sysv.greg.c @@ -47,7 +47,8 @@ void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) { : "=a"(res) : "0"(0x019), "D"(p), "S"(n), "d"(m), "r"(r10), "r"(r8) : "rcx", "r11", "memory", "cc"); - if (res > -4096ul) errno = -res, res = -1; + if (res > -4096ul) + errno = -res, res = -1; } else if (IsNetbsd()) { if (f & MREMAP_MAYMOVE) { res = 0x19B; @@ -57,7 +58,8 @@ void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) { : CFLAG_CONSTRAINT(cf), "+a"(res), "=d"(rdx) : "D"(p), "S"(n), "2"(q), "r"(r10), "r"(r8) : "rcx", "r9", "r11", "memory", "cc"); - if (cf) errno = res, res = -1; + if (cf) + errno = res, res = -1; } else { res = einval(); } diff --git a/libc/calls/ntaccesscheck.c b/libc/calls/ntaccesscheck.c index b3c2a3af0..708238736 100644 --- a/libc/calls/ntaccesscheck.c +++ b/libc/calls/ntaccesscheck.c @@ -69,7 +69,8 @@ textwindows int ntaccesscheck(const char16_t *pathname, uint32_t flags) { int64_t hToken, hImpersonatedToken, hFile; intptr_t buffer[1024 / sizeof(intptr_t)]; BLOCK_SIGNALS; - if (flags & X_OK) flags |= R_OK; + if (flags & X_OK) + flags |= R_OK; granted = 0; result = false; flagmask = flags; diff --git a/libc/calls/ntspawn.c b/libc/calls/ntspawn.c index e16eb439f..305950b25 100644 --- a/libc/calls/ntspawn.c +++ b/libc/calls/ntspawn.c @@ -157,7 +157,8 @@ textwindows int ntspawn( } } } - if (sb) ntspawn_free(sb); + if (sb) + ntspawn_free(sb); ALLOW_SIGNALS; return rc; } diff --git a/libc/calls/open-nt.c b/libc/calls/open-nt.c index 50b7954ba..663164c53 100644 --- a/libc/calls/open-nt.c +++ b/libc/calls/open-nt.c @@ -184,7 +184,8 @@ static textwindows int sys_open_nt_dup(int fd, int flags, int mode, int oldfd) { static int Atoi(const char *str) { int c; unsigned x = 0; - if (!*str) return -1; + if (!*str) + return -1; while ((c = *str++)) { if ('0' <= c && c <= '9') { x *= 10; @@ -202,7 +203,8 @@ textwindows int sys_open_nt(int dirfd, const char *file, uint32_t flags, int fd, oldfd; BLOCK_SIGNALS; __fds_lock(); - if (!(flags & _O_CREAT)) mode = 0; + if (!(flags & _O_CREAT)) + mode = 0; if ((rc = fd = __reservefd_unlocked(-1)) != -1) { if (startswith(file, "/dev/")) { if (!strcmp(file + 5, "tty")) { diff --git a/libc/calls/openat-metal.c b/libc/calls/openat-metal.c index fa2b45b82..92baca705 100644 --- a/libc/calls/openat-metal.c +++ b/libc/calls/openat-metal.c @@ -40,20 +40,26 @@ int sys_openat_metal(int dirfd, const char *file, int flags, unsigned mode) { int fd; struct MetalFile *state; - if (dirfd != AT_FDCWD || strcmp(file, APE_COM_NAME)) return enoent(); - if (flags != O_RDONLY) return eacces(); - if (!_weaken(__ape_com_base) || !_weaken(__ape_com_size)) return eopnotsupp(); - if ((fd = __reservefd(-1)) == -1) return -1; + if (dirfd != AT_FDCWD || strcmp(file, APE_COM_NAME)) + return enoent(); + if (flags != O_RDONLY) + return eacces(); + if (!_weaken(__ape_com_base) || !_weaken(__ape_com_size)) + return eopnotsupp(); + if ((fd = __reservefd(-1)) == -1) + return -1; if (!_weaken(calloc) || !_weaken(free)) { struct DirectMap dm; dm = sys_mmap_metal(NULL, ROUNDUP(sizeof(struct MetalFile), 4096), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); state = dm.addr; - if (state == (void *)-1) return -1; + if (state == (void *)-1) + return -1; } else { state = _weaken(calloc)(1, sizeof(struct MetalFile)); - if (!state) return -1; + if (!state) + return -1; } state->base = (char *)__ape_com_base; state->size = __ape_com_size; diff --git a/libc/calls/openpty.c b/libc/calls/openpty.c index 29f2a6cbb..fd9c26cf4 100644 --- a/libc/calls/openpty.c +++ b/libc/calls/openpty.c @@ -64,12 +64,16 @@ static int openpty_impl(int *mfd, int *sfd, char *name, } *mfd = m; *sfd = s; - if (name) strcpy(name, t.sname); - if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio)); - if (wsz) npassert(!tcsetwinsize(s, wsz)); + if (name) + strcpy(name, t.sname); + if (tio) + npassert(!tcsetattr(s, TCSAFLUSH, tio)); + if (wsz) + npassert(!tcsetwinsize(s, wsz)); return 0; OnError: - if (m != -1) sys_close(m); + if (m != -1) + sys_close(m); return -1; } diff --git a/libc/calls/park.c b/libc/calls/park.c index b3cc550c2..286c77555 100644 --- a/libc/calls/park.c +++ b/libc/calls/park.c @@ -32,7 +32,8 @@ static textwindows int _park_thread(uint32_t msdelay, sigset_t waitmask, bool restartable) { int sig, handler_was_called; - if (_check_cancel() == -1) return -1; + if (_check_cancel() == -1) + return -1; if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { goto HandleSignal; } @@ -46,7 +47,8 @@ static textwindows int _park_thread(uint32_t msdelay, sigset_t waitmask, if (ok && _weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { HandleSignal: handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask); - if (_check_cancel() == -1) return -1; + if (_check_cancel() == -1) + return -1; if (!restartable || (handler_was_called & SIG_HANDLED_NO_RESTART)) { return eintr(); } diff --git a/libc/calls/pause-nt.c b/libc/calls/pause-nt.c index 480031006..0a43e5089 100644 --- a/libc/calls/pause-nt.c +++ b/libc/calls/pause-nt.c @@ -22,7 +22,8 @@ textwindows int sys_pause_nt(void) { int rc; - while (!(rc = _park_norestart(-1u, 0))) donothing; + while (!(rc = _park_norestart(-1u, 0))) + donothing; return rc; } diff --git a/libc/calls/perror.c b/libc/calls/perror.c index 3097521e3..63d4f0be9 100644 --- a/libc/calls/perror.c +++ b/libc/calls/perror.c @@ -26,6 +26,7 @@ */ void perror(const char *thing) { const char *reason; - if (!(reason = _strerdoc(errno))) reason = "Unknown error"; + if (!(reason = _strerdoc(errno))) + reason = "Unknown error"; tinyprint(2, thing ? thing : "", thing ? ": " : "", reason, "\n", NULL); } diff --git a/libc/calls/pipe2-sysv.c b/libc/calls/pipe2-sysv.c index 1cbf98ee4..dbecc02cf 100644 --- a/libc/calls/pipe2-sysv.c +++ b/libc/calls/pipe2-sysv.c @@ -25,7 +25,8 @@ int32_t sys_pipe2(int pipefd[hasatleast 2], unsigned flags) { int e, rc; - if (!flags) goto OldSkool; + if (!flags) + goto OldSkool; e = errno; rc = __sys_pipe2(pipefd, flags); if (rc == -1 && errno == ENOSYS) { diff --git a/libc/calls/pledge-linux.c b/libc/calls/pledge-linux.c index b682af953..1a1dce028 100644 --- a/libc/calls/pledge-linux.c +++ b/libc/calls/pledge-linux.c @@ -1023,18 +1023,21 @@ static const struct sock_filter kFilterIgnoreExitGroup[] = { static privileged unsigned long StrLen(const char *s) { unsigned long n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; } static privileged void *MemCpy(void *d, const void *s, unsigned long n) { unsigned long i = 0; - for (; i < n; ++i) ((char *)d)[i] = ((char *)s)[i]; + for (; i < n; ++i) + ((char *)d)[i] = ((char *)s)[i]; return (char *)d + n; } static privileged char *FixCpy(char p[17], uint64_t x, int k) { - while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; + while (k > 0) + *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; *p = '\0'; return p; } @@ -1305,7 +1308,8 @@ static privileged void MonitorSigSys(void) { static privileged void AppendFilter(struct Filter *f, const struct sock_filter *p, size_t n) { - if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible; + if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) + notpossible; MemCpy(f->p + f->n, p, n * sizeof(*f->p)); f->n += n; } @@ -2170,7 +2174,8 @@ static privileged void AppendPledge(struct Filter *f, // if ((count = CountUnspecial(p, len))) { if (count < 256) { for (j = i = 0; i < len; ++i) { - if (p[i] & SPECIAL) continue; + if (p[i] & SPECIAL) + continue; // jump to ALLOW rule below if accumulator equals ordinal struct sock_filter fragment[] = { BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, // instruction @@ -2192,7 +2197,8 @@ static privileged void AppendPledge(struct Filter *f, // // handle "special" ordinals which use hand-crafted bpf for (i = 0; i < len; ++i) { - if (!(p[i] & SPECIAL)) continue; + if (!(p[i] & SPECIAL)) + continue; switch (p[i]) { case __NR_linux_mmap | EXEC: AllowMmapExec(f); diff --git a/libc/calls/pledge.c b/libc/calls/pledge.c index 964b77fbd..3ce335cfd 100644 --- a/libc/calls/pledge.c +++ b/libc/calls/pledge.c @@ -249,12 +249,17 @@ int pledge(const char *promises, const char *execpromises) { // may use pledge(0,0) to perform a support check, to determine if // pledge() will be able to impose the restrictions it advertises // within the host environment. - if (execpromises) return einval(); - if (IsGenuineBlink()) return enosys(); - if (IsOpenbsd()) return sys_pledge(0, 0); - if (!IsLinux()) return enosys(); + if (execpromises) + return einval(); + if (IsGenuineBlink()) + return enosys(); + if (IsOpenbsd()) + return sys_pledge(0, 0); + if (!IsLinux()) + return enosys(); rc = sys_prctl(PR_GET_SECCOMP, 0, 0, 0, 0); - if (rc == 0 || rc == 2) return 0; // 2 means we're already filtered + if (rc == 0 || rc == 2) + return 0; // 2 means we're already filtered unassert(rc < 0); errno = -rc; return -1; @@ -274,9 +279,11 @@ int pledge(const char *promises, const char *execpromises) { STRACE("execpromises must be a subset of promises"); rc = einval(); } else { - if (notsubset) iexecpromises = ipromises; + if (notsubset) + iexecpromises = ipromises; rc = sys_pledge_linux(ipromises, __pledge_mode); - if (rc > -4096u) errno = -rc, rc = -1; + if (rc > -4096u) + errno = -rc, rc = -1; } } else { e = errno; diff --git a/libc/calls/poll-metal.c b/libc/calls/poll-metal.c index 918914cf0..613d4d415 100644 --- a/libc/calls/poll-metal.c +++ b/libc/calls/poll-metal.c @@ -71,7 +71,8 @@ int sys_poll_metal(struct pollfd *fds, size_t nfds, unsigned timeout_ms) { fds[i].revents = POLLNVAL; } } - if (fds[i].revents) ++rc; + if (fds[i].revents) + ++rc; } if (rc || !blocking || unsignedsubtract(rdtsc(), start) >= timeout) { break; diff --git a/libc/calls/poll-nt.c b/libc/calls/poll-nt.c index aa0cd2723..f2b16e91d 100644 --- a/libc/calls/poll-nt.c +++ b/libc/calls/poll-nt.c @@ -81,7 +81,8 @@ static textwindows int sys_poll_nt_impl(struct pollfd *fds, uint64_t nfds, // we might need to spawn threads and open pipes __fds_lock(); for (gotinvals = rc = sn = pn = i = 0; i < nfds; ++i) { - if (fds[i].fd < 0) continue; + if (fds[i].fd < 0) + continue; if (__isfdopen(fds[i].fd)) { if (__isfdkind(fds[i].fd, kFdSocket)) { if (sn < ARRAYLEN(sockfds)) { diff --git a/libc/calls/posix_openpt.c b/libc/calls/posix_openpt.c index 09de289c5..ae36362fb 100644 --- a/libc/calls/posix_openpt.c +++ b/libc/calls/posix_openpt.c @@ -43,7 +43,8 @@ int posix_openpt(int flags) { rc = sys_openat(AT_FDCWD, "/dev/ptm", flags, 0); } else if (IsFreebsd()) { rc = sys_posix_openpt(flags); - if (rc == -1 && errno == ENOSPC) errno = EAGAIN; + if (rc == -1 && errno == ENOSPC) + errno = EAGAIN; } else { rc = enosys(); } diff --git a/libc/calls/ppoll.c b/libc/calls/ppoll.c index 320f961a0..14d210f13 100644 --- a/libc/calls/ppoll.c +++ b/libc/calls/ppoll.c @@ -87,9 +87,11 @@ int ppoll(struct pollfd *fds, size_t nfds, const struct timespec *timeout, (timeout->tv_nsec + 999999) / 1000000)) { ms = -1; } - if (sigmask) sys_sigprocmask(SIG_SETMASK, sigmask, &oldmask); + if (sigmask) + sys_sigprocmask(SIG_SETMASK, sigmask, &oldmask); rc = poll(fds, nfds, ms); - if (sigmask) sys_sigprocmask(SIG_SETMASK, &oldmask, 0); + if (sigmask) + sys_sigprocmask(SIG_SETMASK, &oldmask, 0); } } else { uint32_t ms; diff --git a/libc/calls/preadv.c b/libc/calls/preadv.c index 9cba11979..b0fc220dd 100644 --- a/libc/calls/preadv.c +++ b/libc/calls/preadv.c @@ -84,7 +84,8 @@ static ssize_t Preadv(int fd, struct iovec *iov, int iovlen, int64_t off) { e = errno; rc = sys_preadv(fd, iov, iovlen, off, off); - if (rc != -1 || errno != ENOSYS) return rc; + if (rc != -1 || errno != ENOSYS) + return rc; errno = e; for (toto = i = 0; i < iovlen; ++i) { diff --git a/libc/calls/printfds.c b/libc/calls/printfds.c index 4f05e1680..9b81e1e00 100644 --- a/libc/calls/printfds.c +++ b/libc/calls/printfds.c @@ -49,13 +49,16 @@ void __printfds(struct Fd *fds, size_t fdslen) { int i; char buf[128]; for (i = 0; i < fdslen; ++i) { - if (!fds[i].kind) continue; + if (!fds[i].kind) + continue; kprintf("%3d %s", i, __fdkind2str(fds[i].kind)); if (fds[i].flags) { kprintf(" flags=%s", (DescribeOpenFlags)(buf, fds[i].flags)); } - if (fds[i].mode) kprintf(" mode=%#o", fds[i].mode); - if (fds[i].handle) kprintf(" handle=%ld", fds[i].handle); + if (fds[i].mode) + kprintf(" mode=%#o", fds[i].mode); + if (fds[i].handle) + kprintf(" handle=%ld", fds[i].handle); kprintf("\n"); } } diff --git a/libc/calls/program_invocation_short_name.c b/libc/calls/program_invocation_short_name.c index 396d55f47..06911e42d 100644 --- a/libc/calls/program_invocation_short_name.c +++ b/libc/calls/program_invocation_short_name.c @@ -24,7 +24,8 @@ char *program_invocation_short_name; __attribute__((__constructor__(10))) static textstartup void program_invocation_short_name_init(void) { char *p, *r; - if (!__argc) return; + if (!__argc) + return; if ((p = strrchr(__argv[0], '/'))) { r = p + 1; } else { diff --git a/libc/calls/ptrace.c b/libc/calls/ptrace.c index ae77a4a35..8acb3c8de 100644 --- a/libc/calls/ptrace.c +++ b/libc/calls/ptrace.c @@ -47,9 +47,11 @@ long ptrace(int request, ...) { rc = einval(); /* see consts.sh */ } else { ispeek = IsLinux() && request - 1u < 3; - if (ispeek) data = &peek; + if (ispeek) + data = &peek; rc = __sys_ptrace(request, pid, addr, data); - if (rc != -1 && ispeek) rc = peek; + if (rc != -1 && ispeek) + rc = peek; } STRACE("ptrace(%s, %d, %p, %p) → %p% m", DescribePtrace(request), pid, addr, data, rc); diff --git a/libc/calls/pwritev.c b/libc/calls/pwritev.c index 4f612a79e..fd70331fb 100644 --- a/libc/calls/pwritev.c +++ b/libc/calls/pwritev.c @@ -83,7 +83,8 @@ static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen, e = errno; rc = sys_pwritev(fd, iov, iovlen, off, off); - if (rc != -1 || errno != ENOSYS) return rc; + if (rc != -1 || errno != ENOSYS) + return rc; errno = e; for (toto = i = 0; i < iovlen; ++i) { diff --git a/libc/calls/rdrand.c b/libc/calls/rdrand.c index c499c3752..358a0795d 100644 --- a/libc/calls/rdrand.c +++ b/libc/calls/rdrand.c @@ -73,7 +73,8 @@ uint64_t rdrand(void) { : CFLAG_CONSTRAINT(cf), "=r"(x) : /* no inputs */ : "cc"); - if (cf) return x; + if (cf) + return x; asm volatile("pause"); } } diff --git a/libc/calls/read-nt.c b/libc/calls/read-nt.c index 2d76062da..699a7e2d8 100644 --- a/libc/calls/read-nt.c +++ b/libc/calls/read-nt.c @@ -276,7 +276,8 @@ static textwindows int ProcessKeyEvent(const struct NtInputRecord *r, char *p) { } else { v = -v; } - do p[n++] = v; + do + p[n++] = v; while ((v >>= 8)); return n; } @@ -360,7 +361,8 @@ static textwindows int ProcessKeyEvent(const struct NtInputRecord *r, char *p) { // finally apply thompson-pike varint encoding uint64_t w = tpenc(c); - do p[n++] = w; + do + p[n++] = w; while ((w >>= 8)); return n; } @@ -482,7 +484,8 @@ static textwindows bool EraseKeystroke(void) { struct Keystroke *k = KEYSTROKE_CONTAINER(e); FreeKeystroke(&__keystroke.line, e); for (int i = k->buflen; i--;) { - if ((k->buf[i] & 0300) == 0200) continue; // utf-8 cont + if ((k->buf[i] & 0300) == 0200) + continue; // utf-8 cont EraseCharacter(); if (!(__ttyconf.magic & kTtyEchoRaw) && IsCtl(k->buf[i])) { EraseCharacter(); @@ -552,12 +555,15 @@ static textwindows void IngestConsoleInput(void) { uint32_t i, n; struct NtInputRecord records[16]; for (;;) { - if (!__keystroke.freekeys) return; - if (__keystroke.end_of_file) return; + if (!__keystroke.freekeys) + return; + if (__keystroke.end_of_file) + return; if (!GetNumberOfConsoleInputEvents(__keystroke.cin, &n)) { goto UnexpectedEof; } - if (!n) return; + if (!n) + return; n = MIN(__keystroke.freekeys, MIN(ARRAYLEN(records), n)); if (!ReadConsoleInput(__keystroke.cin, records, n, &n)) { goto UnexpectedEof; @@ -722,8 +728,10 @@ static textwindows int WaitForConsole(struct Fd *f, sigset_t waitmask) { ms = __ttyconf.vtime * 100; } } - if (_check_cancel() == -1) return -1; - if (f->flags & _O_NONBLOCK) return eagain(); + if (_check_cancel() == -1) + return -1; + if (f->flags & _O_NONBLOCK) + return eagain(); if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { goto DeliverSignal; } @@ -734,15 +742,21 @@ static textwindows int WaitForConsole(struct Fd *f, sigset_t waitmask) { wi = WaitForMultipleObjects(2, (int64_t[2]){__keystroke.cin, sem}, 0, ms); atomic_store_explicit(&pt->pt_blocker, 0, memory_order_release); CloseHandle(sem); - if (wi == kNtWaitTimeout) return 0; // vtime elapsed - if (wi == 0) return -2; // console data - if (wi != 1) return __winerr(); // wait failed + if (wi == kNtWaitTimeout) + return 0; // vtime elapsed + if (wi == 0) + return -2; // console data + if (wi != 1) + return __winerr(); // wait failed if (_weaken(__sig_get)) { - if (!(sig = _weaken(__sig_get)(waitmask))) return eintr(); + if (!(sig = _weaken(__sig_get)(waitmask))) + return eintr(); DeliverSignal: int handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask); - if (_check_cancel() == -1) return -1; - if (!(handler_was_called & SIG_HANDLED_NO_RESTART)) return -2; + if (_check_cancel() == -1) + return -1; + if (!(handler_was_called & SIG_HANDLED_NO_RESTART)) + return -2; } return eintr(); } @@ -756,7 +770,8 @@ static textwindows ssize_t ReadFromConsole(struct Fd *f, void *data, IngestConsoleInput(); bool done = DigestConsoleInput(data, size, &rc); UnlockKeystrokes(); - if (done) return rc; + if (done) + return rc; } while ((rc = WaitForConsole(f, waitmask)) == -2); return rc; } @@ -778,7 +793,8 @@ textwindows ssize_t ReadBuffer(int fd, void *data, size_t size, int64_t offset, // perform heavy lifting ssize_t rc; rc = sys_readwrite_nt(fd, data, size, offset, f->handle, waitmask, ReadFile); - if (rc != -2) return rc; + if (rc != -2) + return rc; // mops up win32 errors switch (GetLastError()) { @@ -798,11 +814,14 @@ static textwindows ssize_t ReadIovecs(int fd, const struct iovec *iov, sigset_t waitmask) { ssize_t rc; size_t i, total; - if (opt_offset < -1) return einval(); - while (iovlen && !iov[0].iov_len) iov++, iovlen--; + if (opt_offset < -1) + return einval(); + while (iovlen && !iov[0].iov_len) + iov++, iovlen--; if (iovlen) { for (total = i = 0; i < iovlen; ++i) { - if (!iov[i].iov_len) continue; + if (!iov[i].iov_len) + continue; rc = ReadBuffer(fd, iov[i].iov_base, iov[i].iov_len, opt_offset, waitmask); if (rc == -1) { @@ -813,8 +832,10 @@ static textwindows ssize_t ReadIovecs(int fd, const struct iovec *iov, } } total += rc; - if (opt_offset != -1) opt_offset += rc; - if (rc < iov[i].iov_len) break; + if (opt_offset != -1) + opt_offset += rc; + if (rc < iov[i].iov_len) + break; } return total; } else { diff --git a/libc/calls/readansi.c b/libc/calls/readansi.c index 8cd6afe67..315e4b364 100644 --- a/libc/calls/readansi.c +++ b/libc/calls/readansi.c @@ -68,7 +68,8 @@ ssize_t readansi(int fd, char *p, size_t n) { e = errno; t = kAscii; x = i = j = 0; - if (n) p[0] = 0; + if (n) + p[0] = 0; do { for (;;) { if (n) { @@ -102,7 +103,8 @@ ssize_t readansi(int fd, char *p, size_t n) { ++i; switch (t) { Whoopsie: - if (n) p[0] = c; + if (n) + p[0] = c; t = kAscii; i = 1; /* fallthrough */ diff --git a/libc/calls/readlinkat-nt.c b/libc/calls/readlinkat-nt.c index 5d5e855da..ff9a6eca2 100644 --- a/libc/calls/readlinkat-nt.c +++ b/libc/calls/readlinkat-nt.c @@ -40,10 +40,12 @@ static textwindows ssize_t sys_readlinkat_nt_impl(int dirfd, const char *path, char *buf, size_t bufsiz) { char16_t path16[PATH_MAX]; - if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; + if (__mkntpathat(dirfd, path, 0, path16) == -1) + return -1; size_t len = strlen16(path16); bool must_be_directory = len > 1 && path16[len - 1] == '\\'; - if (must_be_directory) path16[--len] = 0; + if (must_be_directory) + path16[--len] = 0; int64_t h; ssize_t rc; diff --git a/libc/calls/readv-metal.c b/libc/calls/readv-metal.c index a10fc88fe..6e43f431a 100644 --- a/libc/calls/readv-metal.c +++ b/libc/calls/readv-metal.c @@ -41,7 +41,8 @@ ssize_t sys_readv_metal(int fd, const struct iovec *iov, int iovlen) { */ if (_weaken(sys_readv_vga)) { ssize_t res = _weaken(sys_readv_vga)(g_fds.p + fd, iov, iovlen); - if (res > 0) return res; + if (res > 0) + return res; } /* fall through */ case kFdSerial: @@ -50,7 +51,8 @@ ssize_t sys_readv_metal(int fd, const struct iovec *iov, int iovlen) { file = (struct MetalFile *)g_fds.p[fd].handle; for (toto = i = 0; i < iovlen && file->pos < file->size; ++i) { got = MIN(iov[i].iov_len, file->size - file->pos); - if (got) memcpy(iov[i].iov_base, file->base, got); + if (got) + memcpy(iov[i].iov_base, file->base, got); toto += got; } return toto; diff --git a/libc/calls/readwrite-nt.c b/libc/calls/readwrite-nt.c index 8ae3baa0d..3643cd9dc 100644 --- a/libc/calls/readwrite-nt.c +++ b/libc/calls/readwrite-nt.c @@ -82,7 +82,8 @@ sys_readwrite_nt(int fd, void *data, size_t size, ssize_t offset, RestartOperation: bool eagained = false; // check for signals and cancelation - if (_check_cancel() == -1) return -1; // ECANCELED + if (_check_cancel() == -1) + return -1; // ECANCELED if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { goto HandleInterrupt; } @@ -136,7 +137,8 @@ RestartOperation: if (_weaken(__sig_relay) && (sig = _weaken(__sig_get)(waitmask))) { HandleInterrupt: int handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask); - if (_check_cancel() == -1) return -1; // possible if we SIGTHR'd + if (_check_cancel() == -1) + return -1; // possible if we SIGTHR'd // read() is @restartable unless non-SA_RESTART hands were called if (!(handler_was_called & SIG_HANDLED_NO_RESTART)) { goto RestartOperation; diff --git a/libc/calls/releasefd.c b/libc/calls/releasefd.c index 6e98f5d09..f6947d22d 100644 --- a/libc/calls/releasefd.c +++ b/libc/calls/releasefd.c @@ -24,7 +24,8 @@ // really want to avoid locking here so close() needn't block signals void __releasefd(int fd) { int f1, f2; - if (!(0 <= fd && fd < g_fds.n)) return; + if (!(0 <= fd && fd < g_fds.n)) + return; g_fds.p[fd].kind = kFdEmpty; bzero(g_fds.p + fd, sizeof(*g_fds.p)); f1 = atomic_load_explicit(&g_fds.f, memory_order_relaxed); diff --git a/libc/calls/remove.c b/libc/calls/remove.c index 3db158bf8..f0197b932 100644 --- a/libc/calls/remove.c +++ b/libc/calls/remove.c @@ -28,8 +28,10 @@ */ int remove(const char *name) { int e = errno; - if (!unlinkat(AT_FDCWD, name, 0)) return 0; - if (errno != EISDIR) return -1; + if (!unlinkat(AT_FDCWD, name, 0)) + return 0; + if (errno != EISDIR) + return -1; errno = e; return unlinkat(AT_FDCWD, name, AT_REMOVEDIR); } diff --git a/libc/calls/restoretty.c b/libc/calls/restoretty.c index 1b92ce6e1..7b7269ff6 100644 --- a/libc/calls/restoretty.c +++ b/libc/calls/restoretty.c @@ -43,7 +43,8 @@ static struct termios __oldtermios; static size_t __strlen(const char *s) { size_t i = 0; - while (s[i]) ++i; + while (s[i]) + ++i; return i; } diff --git a/libc/calls/sched_getcpu.c b/libc/calls/sched_getcpu.c index ac80be47a..f738be649 100644 --- a/libc/calls/sched_getcpu.c +++ b/libc/calls/sched_getcpu.c @@ -58,7 +58,8 @@ int sched_getcpu(void) { } else { unsigned cpu = 0; int rc = sys_getcpu(&cpu, 0, 0); - if (rc == -1) return -1; + if (rc == -1) + return -1; return cpu; } } diff --git a/libc/calls/sedebug.c b/libc/calls/sedebug.c index fc6bf4ac8..64c4ac52d 100644 --- a/libc/calls/sedebug.c +++ b/libc/calls/sedebug.c @@ -84,7 +84,8 @@ static int64_t GetCurrentProcessSecurityToken(void) { bool32 ElevateSeDebugPrivilege(void) { int64_t hToken; - if (!(hToken = GetCurrentProcessSecurityToken())) return false; + if (!(hToken = GetCurrentProcessSecurityToken())) + return false; SetPrivilegeNt(hToken, u"SeDebugPrivilege", true); RevertToSelf(); CloseHandle(hToken); diff --git a/libc/calls/select-nt.c b/libc/calls/select-nt.c index bb895b135..8245f9f32 100644 --- a/libc/calls/select-nt.c +++ b/libc/calls/select-nt.c @@ -40,9 +40,12 @@ int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds, struct pollfd fds[64]; for (pfds = i = 0; i < nfds; ++i) { events = 0; - if (readfds && FD_ISSET(i, readfds)) events |= POLLIN; - if (writefds && FD_ISSET(i, writefds)) events |= POLLOUT; - if (exceptfds && FD_ISSET(i, exceptfds)) events |= POLLERR; + if (readfds && FD_ISSET(i, readfds)) + events |= POLLIN; + if (writefds && FD_ISSET(i, writefds)) + events |= POLLOUT; + if (exceptfds && FD_ISSET(i, exceptfds)) + events |= POLLERR; if (events) { if (pfds < ARRAYLEN(fds)) { fds[pfds].fd = i; @@ -71,12 +74,16 @@ int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds, // call our nt poll implementation fdcount = sys_poll_nt(fds, pfds, &millis, sigmask); unassert(fdcount < 64); - if (fdcount < 0) return -1; + if (fdcount < 0) + return -1; // convert pollfd back to bitsets - if (readfds) FD_ZERO(readfds); - if (writefds) FD_ZERO(writefds); - if (exceptfds) FD_ZERO(exceptfds); + if (readfds) + FD_ZERO(readfds); + if (writefds) + FD_ZERO(writefds); + if (exceptfds) + FD_ZERO(exceptfds); int bits = 0; for (i = 0; i < pfds; ++i) { if (fds[i].revents & POLLIN) { diff --git a/libc/calls/sig.c b/libc/calls/sig.c index b0011fdfe..12f116ccd 100644 --- a/libc/calls/sig.c +++ b/libc/calls/sig.c @@ -194,7 +194,8 @@ textwindows int __sig_raise(volatile int sig, int sic) { // update the signal mask in preparation for signal handller sigset_t blocksigs = __sighandmask[sig]; - if (!(flags & SA_NODEFER)) blocksigs |= 1ull << (sig - 1); + if (!(flags & SA_NODEFER)) + blocksigs |= 1ull << (sig - 1); ctx.uc_sigmask = atomic_fetch_or_explicit(&pt->tib->tib_sigmask, blocksigs, memory_order_acquire); @@ -265,7 +266,8 @@ static textwindows wontreturn void __sig_tramp(struct SignalFrame *sf) { // update the signal mask in preparation for signal handller sigset_t blocksigs = __sighandmask[sig]; - if (!(sf->flags & SA_NODEFER)) blocksigs |= 1ull << (sig - 1); + if (!(sf->flags & SA_NODEFER)) + blocksigs |= 1ull << (sig - 1); sf->ctx.uc_sigmask = atomic_fetch_or_explicit(&tib->tib_sigmask, blocksigs, memory_order_acquire); @@ -425,7 +427,8 @@ textwindows void __sig_generate(int sig, int sic) { for (e = dll_first(_pthread_list); e; e = dll_next(_pthread_list, e)) { pt = POSIXTHREAD_CONTAINER(e); // we don't want to signal ourself - if (pt == _pthread_self()) continue; + if (pt == _pthread_self()) + continue; // we don't want to signal a thread that isn't running if (atomic_load_explicit(&pt->pt_status, memory_order_acquire) >= kPosixThreadTerminated) { @@ -584,7 +587,8 @@ static void __sig_unmaskable(struct NtExceptionPointers *ep, int code, int sig, siginfo_t si = {.si_signo = sig, .si_code = code, .si_addr = si_addr}; _ntcontext2linux(&ctx, ep->ContextRecord); sigset_t blocksigs = __sighandmask[sig]; - if (!(flags & SA_NODEFER)) blocksigs |= 1ull << (sig - 1); + if (!(flags & SA_NODEFER)) + blocksigs |= 1ull << (sig - 1); ctx.uc_sigmask = atomic_fetch_or_explicit(&tib->tib_sigmask, blocksigs, memory_order_acquire); __sig_handler(rva)(sig, &si, &ctx); @@ -668,7 +672,8 @@ textwindows int __sig_check(void) { } __attribute__((__constructor__(10))) textstartup void __sig_init(void) { - if (!IsWindows()) return; + if (!IsWindows()) + return; AddVectoredExceptionHandler(true, (void *)__sig_crash); SetConsoleCtrlHandler((void *)__sig_console, true); } diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index 3d4edd901..1ee606403 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -58,7 +58,8 @@ static void sigaction_cosmo2native(union metasigaction *sa) { void *restorer; uint32_t masklo; uint32_t maskhi; - if (!sa) return; + if (!sa) + return; flags = sa->cosmo.sa_flags; handler = sa->cosmo.sa_handler; restorer = sa->cosmo.sa_restorer; @@ -106,7 +107,8 @@ static void sigaction_native2cosmo(union metasigaction *sa) { void *restorer = 0; uint32_t masklo; uint32_t maskhi = 0; - if (!sa) return; + if (!sa) + return; if (IsLinux()) { flags = sa->linux.sa_flags; handler = sa->linux.sa_handler; @@ -159,9 +161,12 @@ static int __sigaction(int sig, const struct sigaction *act, int rc, rva, oldrva; sigaction_f sigenter; struct sigaction *ap, copy; - if (IsMetal()) return enosys(); /* TODO: Signals on Metal */ - if (!(1 <= sig && sig <= _NSIG)) return einval(); - if (sig == SIGKILL || sig == SIGSTOP) return einval(); + if (IsMetal()) + return enosys(); /* TODO: Signals on Metal */ + if (!(1 <= sig && sig <= _NSIG)) + return einval(); + if (sig == SIGKILL || sig == SIGSTOP) + return einval(); if (IsAsan() && ((act && !__asan_is_valid(act, sizeof(*act))) || (oldact && !__asan_is_valid(oldact, sizeof(*oldact))))) { return efault(); diff --git a/libc/calls/sigaltstack.c b/libc/calls/sigaltstack.c index e2c93d74e..b6da79d0d 100644 --- a/libc/calls/sigaltstack.c +++ b/libc/calls/sigaltstack.c @@ -77,10 +77,12 @@ static textwindows int sigaltstack_cosmo(const struct sigaltstack *neu, sigaltstack_setnew(neu); if (tib->tib_sigstack_addr <= bp && bp <= tib->tib_sigstack_addr + tib->tib_sigstack_size) { - if (old) old->ss_flags |= SS_ONSTACK; + if (old) + old->ss_flags |= SS_ONSTACK; tib->tib_sigstack_flags = SS_ONSTACK; // can't disable if on it } else if (!tib->tib_sigstack_size) { - if (old) old->ss_flags = SS_DISABLE; + if (old) + old->ss_flags = SS_DISABLE; tib->tib_sigstack_flags = SS_DISABLE; } return 0; @@ -90,7 +92,8 @@ static int sigaltstack_bsd(const struct sigaltstack *neu, struct sigaltstack *old) { int rc; struct sigaltstack_bsd oldbsd, neubsd, *neup = 0; - if (neu) sigaltstack2bsd(&neubsd, neu), neup = &neubsd; + if (neu) + sigaltstack2bsd(&neubsd, neu), neup = &neubsd; if (IsXnuSilicon()) { rc = _sysret(__syslib->__sigaltstack(neup, &oldbsd)); } else { @@ -99,7 +102,8 @@ static int sigaltstack_bsd(const struct sigaltstack *neu, if (rc == -1) { return -1; } - if (old) sigaltstack2linux(old, &oldbsd); + if (old) + sigaltstack2linux(old, &oldbsd); return 0; } @@ -135,10 +139,12 @@ int sigaltstack(const struct sigaltstack *neu, struct sigaltstack *old) { rc = enomem(); } else if (IsLinux()) { rc = sys_sigaltstack(neu, old); - if (!rc) sigaltstack_setnew(neu); + if (!rc) + sigaltstack_setnew(neu); } else if (IsBsd()) { rc = sigaltstack_bsd(neu, old); - if (!rc) sigaltstack_setnew(neu); + if (!rc) + sigaltstack_setnew(neu); } else { rc = sigaltstack_cosmo(neu, old); } diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index 7d59a87e5..26a0a9d87 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -56,7 +56,8 @@ int sigsuspend(const sigset_t *ignore) { } else { sigset_t waitmask = ignore ? *ignore : 0; if (IsWindows() || IsMetal()) { - while (!(rc = _park_norestart(-1u, waitmask))) donothing; + while (!(rc = _park_norestart(-1u, waitmask))) + donothing; } else { rc = sys_sigsuspend((uint64_t[2]){waitmask}, 8); } diff --git a/libc/calls/sigwait.c b/libc/calls/sigwait.c index beabc1143..77dc014fa 100644 --- a/libc/calls/sigwait.c +++ b/libc/calls/sigwait.c @@ -20,7 +20,8 @@ int sigwait(const sigset_t *mask, int *sig) { siginfo_t si; - if (sigtimedwait(mask, &si, 0) < 0) return -1; + if (sigtimedwait(mask, &si, 0) < 0) + return -1; *sig = si.si_signo; return 0; } diff --git a/libc/calls/sleep.c b/libc/calls/sleep.c index c707b31ce..90debc667 100644 --- a/libc/calls/sleep.c +++ b/libc/calls/sleep.c @@ -54,7 +54,8 @@ unsigned sleep(unsigned seconds) { if (cs != -1) { _pthread_allow_cancelation(cs); } - if (!err) return 0; + if (!err) + return 0; unassert(err == EINTR); unslept = tv.tv_sec; if (tv.tv_nsec && unslept < UINT_MAX) { diff --git a/libc/calls/statfs-nt.c b/libc/calls/statfs-nt.c index 3f95cee99..1448c4a82 100644 --- a/libc/calls/statfs-nt.c +++ b/libc/calls/statfs-nt.c @@ -32,7 +32,8 @@ textwindows int sys_statfs_nt(const char *path, struct statfs *sf) { int rc; int64_t h; char16_t path16[PATH_MAX]; - if (__mkntpath(path, path16) == -1) return -1; + if (__mkntpath(path, path16) == -1) + return -1; BLOCK_SIGNALS; h = __fix_enotdir( CreateFile(path16, kNtFileGenericRead, diff --git a/libc/calls/symlinkat-nt.c b/libc/calls/symlinkat-nt.c index 94da0ea18..c1555848e 100644 --- a/libc/calls/symlinkat-nt.c +++ b/libc/calls/symlinkat-nt.c @@ -44,12 +44,15 @@ static textwindows void InitializeWinlink(void) { int64_t tok; struct NtLuid id; struct NtTokenPrivileges tp; - if (!OpenProcessToken(GetCurrentProcess(), kNtTokenAllAccess, &tok)) return; - if (!LookupPrivilegeValue(0, u"SeCreateSymbolicLinkPrivilege", &id)) return; + if (!OpenProcessToken(GetCurrentProcess(), kNtTokenAllAccess, &tok)) + return; + if (!LookupPrivilegeValue(0, u"SeCreateSymbolicLinkPrivilege", &id)) + return; tp.PrivilegeCount = 1; tp.Privileges[0].Luid = id; tp.Privileges[0].Attributes = kNtSePrivilegeEnabled; - if (!AdjustTokenPrivileges(tok, 0, &tp, sizeof(tp), 0, 0)) return; + if (!AdjustTokenPrivileges(tok, 0, &tp, sizeof(tp), 0, 0)) + return; g_winlink.allowed = GetLastError() != kNtErrorNotAllAssigned; } @@ -67,8 +70,10 @@ textwindows int sys_symlinkat_nt(const char *target, int newdirfd, uint32_t attrs, flags; // convert the paths - if (__mkntpathat(newdirfd, linkpath, 0, M.linkpath16) == -1) return -1; - if ((targetlen = __mkntpath(target, M.target16)) == -1) return -1; + if (__mkntpathat(newdirfd, linkpath, 0, M.linkpath16) == -1) + return -1; + if ((targetlen = __mkntpath(target, M.target16)) == -1) + return -1; // determine if we need directory flag if ((attrs = GetFileAttributes(M.target16)) != -1u) { diff --git a/libc/calls/sync-nt.c b/libc/calls/sync-nt.c index 881a505d5..6e98e8f45 100644 --- a/libc/calls/sync-nt.c +++ b/libc/calls/sync-nt.c @@ -41,7 +41,8 @@ textwindows int sys_sync_nt(void) { } } for (drives = GetLogicalDrives(), i = 0; i <= 'Z' - 'A'; ++i) { - if (!(drives & (1 << i))) continue; + if (!(drives & (1 << i))) + continue; path[4] = 'A' + i; if (ntaccesscheck(path, R_OK | W_OK) != -1) { BLOCK_SIGNALS; diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index aea937cc3..63661a7f1 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -41,11 +41,13 @@ struct loadavg { }; static int64_t GetUptime(void) { - if (IsNetbsd()) return 0; // TODO(jart): Why? + if (IsNetbsd()) + return 0; // TODO(jart): Why? struct timeval x; size_t n = sizeof(x); int mib[] = {CTL_KERN, KERN_BOOTTIME}; - if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0; + if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) + return 0; return timespec_real().tv_sec - x.tv_sec; } @@ -53,7 +55,8 @@ static int64_t GetPhysmem(void) { uint64_t x = 0; size_t n = sizeof(x); int mib[] = {CTL_HW, HW_PHYSMEM}; - if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0; + if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) + return 0; return x; } diff --git a/libc/calls/tcdrain.c b/libc/calls/tcdrain.c index 916abc3e7..c172d4027 100644 --- a/libc/calls/tcdrain.c +++ b/libc/calls/tcdrain.c @@ -33,7 +33,8 @@ #define TIOCDRAIN 0x2000745e // xnu, freebsd, openbsd, netbsd static dontinline textwindows int sys_tcdrain_nt(int fd) { - if (!sys_isatty(fd)) return -1; // ebadf, enotty + if (!sys_isatty(fd)) + return -1; // ebadf, enotty // Tried FlushFileBuffers but it made Emacs hang when run in cmd.exe // "Console output is not buffered." -Quoth MSDN on FlushFileBuffers return 0; diff --git a/libc/calls/tcflow.c b/libc/calls/tcflow.c index b50ac5c80..6543319c3 100644 --- a/libc/calls/tcflow.c +++ b/libc/calls/tcflow.c @@ -41,10 +41,14 @@ #define TIOCIXOFF 0x20007480 // xnu static const char *DescribeFlow(char buf[12], int action) { - if (action == TCOOFF) return "TCOOFF"; - if (action == TCOON) return "TCOON"; - if (action == TCIOFF) return "TCIOFF"; - if (action == TCION) return "TCION"; + if (action == TCOOFF) + return "TCOOFF"; + if (action == TCOON) + return "TCOON"; + if (action == TCIOFF) + return "TCIOFF"; + if (action == TCION) + return "TCION"; FormatInt32(buf, action); return buf; } @@ -89,7 +93,8 @@ static int sys_tcflow_bsd(int fd, int action) { static dontinline textwindows int sys_tcflow_nt(int fd, int action) { bool32 ok; int64_t h; - if (!__isfdopen(fd)) return ebadf(); + if (!__isfdopen(fd)) + return ebadf(); h = g_fds.p[fd].handle; switch (action) { case TCOON: diff --git a/libc/calls/tcflush.c b/libc/calls/tcflush.c index 1c7db3748..cfa4bd9a1 100644 --- a/libc/calls/tcflush.c +++ b/libc/calls/tcflush.c @@ -41,9 +41,12 @@ #define kNtPurgeRxclear 8 static const char *DescribeFlush(char buf[12], int action) { - if (action == TCIFLUSH) return "TCIFLUSH"; - if (action == TCOFLUSH) return "TCOFLUSH"; - if (action == TCIOFLUSH) return "TCIOFLUSH"; + if (action == TCIFLUSH) + return "TCIFLUSH"; + if (action == TCOFLUSH) + return "TCOFLUSH"; + if (action == TCIOFLUSH) + return "TCIOFLUSH"; FormatInt32(buf, action); return buf; } diff --git a/libc/calls/tcgetattr-nt.c b/libc/calls/tcgetattr-nt.c index 464ba9593..bf4262ebf 100644 --- a/libc/calls/tcgetattr-nt.c +++ b/libc/calls/tcgetattr-nt.c @@ -35,8 +35,10 @@ textwindows int tcgetattr_nt(int fd, struct termios *tio) { uint32_t inmode, outmode; // validate file descriptor - if (!__isfdopen(fd)) return ebadf(); - if (!__isfdkind(fd, kFdConsole)) return enotty(); + if (!__isfdopen(fd)) + return ebadf(); + if (!__isfdkind(fd, kFdConsole)) + return enotty(); // then completely ignore it hInput = GetConsoleInputHandle(); diff --git a/libc/calls/tcgetwinsize-nt.c b/libc/calls/tcgetwinsize-nt.c index f2956422c..3b9bfe4ed 100644 --- a/libc/calls/tcgetwinsize-nt.c +++ b/libc/calls/tcgetwinsize-nt.c @@ -28,7 +28,8 @@ textwindows int tcgetwinsize_nt(int fd, struct winsize *ws) { // The Linux man page doesn't list EBADF as an errno for this. - if (!sys_isatty(fd)) return enotty(); + if (!sys_isatty(fd)) + return enotty(); // Query the console which might fail if fd is a serial device. struct NtConsoleScreenBufferInfoEx sr = {.cbSize = sizeof(sr)}; diff --git a/libc/calls/tcsendbreak.c b/libc/calls/tcsendbreak.c index 3e75a706a..9e6e3b55b 100644 --- a/libc/calls/tcsendbreak.c +++ b/libc/calls/tcsendbreak.c @@ -30,15 +30,19 @@ #define TIOCCBRK 0x2000747a // bsd static int sys_tcsendbreak_bsd(int fd) { - if (sys_ioctl(fd, TIOCSBRK, 0) == -1) return -1; + if (sys_ioctl(fd, TIOCSBRK, 0) == -1) + return -1; usleep(400000); - if (sys_ioctl(fd, TIOCCBRK, 0) == -1) return -1; + if (sys_ioctl(fd, TIOCCBRK, 0) == -1) + return -1; return 0; } static textwindows int sys_tcsendbreak_nt(int fd) { - if (!__isfdopen(fd)) return ebadf(); - if (!TransmitCommChar(g_fds.p[fd].handle, '\0')) return __winerr(); + if (!__isfdopen(fd)) + return ebadf(); + if (!TransmitCommChar(g_fds.p[fd].handle, '\0')) + return __winerr(); return 0; } diff --git a/libc/calls/tcsetattr-nt.c b/libc/calls/tcsetattr-nt.c index eee5ccdf7..1eafdf66b 100644 --- a/libc/calls/tcsetattr-nt.c +++ b/libc/calls/tcsetattr-nt.c @@ -37,15 +37,18 @@ textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) { uint32_t inmode, outmode; // validate file descriptor - if (!__isfdopen(fd)) return ebadf(); - if (!__isfdkind(fd, kFdConsole)) return enotty(); + if (!__isfdopen(fd)) + return ebadf(); + if (!__isfdkind(fd, kFdConsole)) + return enotty(); // then completely ignore it hInput = GetConsoleInputHandle(); hOutput = GetConsoleOutputHandle(); unassert(GetConsoleMode(hInput, &inmode)); unassert(GetConsoleMode(hOutput, &outmode)); - if (opt == TCSAFLUSH) FlushConsoleInputBytes(); + if (opt == TCSAFLUSH) + FlushConsoleInputBytes(); // now work on the configuration inmode &= ~(kNtEnableLineInput | kNtEnableEchoInput | diff --git a/libc/calls/tcsetattr.c b/libc/calls/tcsetattr.c index f820fc0e6..33f36f7d0 100644 --- a/libc/calls/tcsetattr.c +++ b/libc/calls/tcsetattr.c @@ -35,9 +35,12 @@ void __on_tcsetattr(int); int tcsetattr_nt(int, int, const struct termios *); static const char *DescribeTcsa(char buf[12], int opt) { - if (opt == TCSANOW) return "TCSANOW"; - if (opt == TCSADRAIN) return "TCSADRAIN"; - if (opt == TCSAFLUSH) return "TCSAFLUSH"; + if (opt == TCSANOW) + return "TCSANOW"; + if (opt == TCSADRAIN) + return "TCSADRAIN"; + if (opt == TCSAFLUSH) + return "TCSAFLUSH"; FormatInt32(buf, opt); return buf; } diff --git a/libc/calls/tcsetwinsize-nt.c b/libc/calls/tcsetwinsize-nt.c index 2fbd1479e..431a582af 100644 --- a/libc/calls/tcsetwinsize-nt.c +++ b/libc/calls/tcsetwinsize-nt.c @@ -24,7 +24,8 @@ textwindows int tcsetwinsize_nt(int fd, const struct winsize *ws) { struct NtCoord coord; - if (!sys_isatty(fd)) return -1; // ebadf, enotty + if (!sys_isatty(fd)) + return -1; // ebadf, enotty coord.X = ws->ws_col; coord.Y = ws->ws_row; if (SetConsoleScreenBufferSize(fd, coord)) { diff --git a/libc/calls/tmpfd.c b/libc/calls/tmpfd.c index b33b147df..d8ceffacd 100644 --- a/libc/calls/tmpfd.c +++ b/libc/calls/tmpfd.c @@ -87,9 +87,11 @@ int tmpfd(void) { } path[0] = 0; strlcat(path, __get_tmpdir(), sizeof(path)); - if (!(prog = program_invocation_short_name)) prog = "tmp"; + if (!(prog = program_invocation_short_name)) + prog = "tmp"; strlcat(path, prog, sizeof(path)); strlcat(path, ".XXXXXX", sizeof(path)); - if ((fd = openatemp(AT_FDCWD, path, 0, O_UNLINK, 0)) == -1) return -1; + if ((fd = openatemp(AT_FDCWD, path, 0, O_UNLINK, 0)) == -1) + return -1; return fd; } diff --git a/libc/calls/touch.c b/libc/calls/touch.c index 89a6e1ca7..69384f752 100644 --- a/libc/calls/touch.c +++ b/libc/calls/touch.c @@ -38,7 +38,8 @@ int touch(const char *file, uint32_t mode) { BLOCK_CANCELATION; fd = open(file, O_CREAT | O_WRONLY, mode); ALLOW_CANCELATION; - if (fd == -1) return -1; + if (fd == -1) + return -1; return close(fd); } return rc; diff --git a/libc/calls/truncate-nt.c b/libc/calls/truncate-nt.c index 576b8335f..2e2fdb089 100644 --- a/libc/calls/truncate-nt.c +++ b/libc/calls/truncate-nt.c @@ -30,7 +30,8 @@ textwindows int sys_truncate_nt(const char *path, uint64_t length) { int rc; int64_t fh; uint16_t path16[PATH_MAX]; - if (__mkntpath(path, path16) == -1) return -1; + if (__mkntpath(path, path16) == -1) + return -1; BLOCK_SIGNALS; if ((fh = CreateFile( path16, kNtGenericWrite, diff --git a/libc/calls/ttyname_r.c b/libc/calls/ttyname_r.c index fa84cfaa5..c87d4a99a 100644 --- a/libc/calls/ttyname_r.c +++ b/libc/calls/ttyname_r.c @@ -36,9 +36,12 @@ #define FIODGNAME 0x80106678 // freebsd static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) { - if (fd + 0u >= g_fds.n) return EBADF; - if (g_fds.p[fd].kind != kFdConsole) return ENOTTY; - if (strlcpy(buf, "/dev/tty", size) >= size) return ERANGE; + if (fd + 0u >= g_fds.n) + return EBADF; + if (g_fds.p[fd].kind != kFdConsole) + return ENOTTY; + if (strlcpy(buf, "/dev/tty", size) >= size) + return ERANGE; return 0; } @@ -62,14 +65,19 @@ static errno_t ttyname_linux(int fd, char *buf, size_t size) { ssize_t got; struct stat st1, st2; char name[14 + 12 + 1]; - if (!isatty(fd)) return errno; + if (!isatty(fd)) + return errno; FormatInt32(stpcpy(name, "/proc/self/fd/"), fd); got = readlink(name, buf, size); - if (got == -1) return errno; - if (got >= size) return ERANGE; + if (got == -1) + return errno; + if (got >= size) + return ERANGE; buf[got] = 0; - if (stat(buf, &st1) || fstat(fd, &st2)) return errno; - if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) return ENODEV; + if (stat(buf, &st1) || fstat(fd, &st2)) + return errno; + if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) + return ENODEV; return 0; } diff --git a/libc/calls/unveil.c b/libc/calls/unveil.c index d47c84889..57f4cfc28 100644 --- a/libc/calls/unveil.c +++ b/libc/calls/unveil.c @@ -176,7 +176,8 @@ static int unveil_init(void) { }; // [undocumented] landlock_create_ruleset() always returns O_CLOEXEC // assert(__sys_fcntl(rc, F_GETFD) == FD_CLOEXEC); - if ((rc = landlock_create_ruleset(&attr, sizeof(attr), 0)) < 0) return -1; + if ((rc = landlock_create_ruleset(&attr, sizeof(attr), 0)) < 0) + return -1; // grant file descriptor a higher number that's less likely to interfere if ((fd = __sys_fcntl(rc, F_DUPFD_CLOEXEC, 100)) == -1) { return err_close(-1, rc); @@ -205,9 +206,12 @@ int sys_unveil_linux(const char *path, const char *permissions) { const char *last; const char *next; - if (!State.fd && (rc = unveil_init()) == -1) return rc; - if ((path && !permissions) || (!path && permissions)) return einval(); - if (!path && !permissions) return unveil_final(); + if (!State.fd && (rc = unveil_init()) == -1) + return rc; + if ((path && !permissions) || (!path && permissions)) + return einval(); + if (!path && !permissions) + return unveil_final(); struct landlock_path_beneath_attr pb = {0}; for (const char *c = permissions; *c != '\0'; c++) { switch (*c) { @@ -233,7 +237,8 @@ int sys_unveil_linux(const char *path, const char *permissions) { // realpath(path) to the ruleset. however a corner case exists where // it isn't valid, e.g. /dev/stdin -> /proc/2834/fd/pipe:[51032], so // we'll need to work around this, by adding the path which is valid - if (strlen(path) + 1 > PATH_MAX) return enametoolong(); + if (strlen(path) + 1 > PATH_MAX) + return enametoolong(); last = path; next = path; for (int i = 0;; ++i) { @@ -283,7 +288,8 @@ int sys_unveil_linux(const char *path, const char *permissions) { BLOCK_CANCELATION; rc = sys_openat(AT_FDCWD, path, O_PATH | O_NOFOLLOW | O_CLOEXEC, 0); ALLOW_CANCELATION; - if (rc == -1) return rc; + if (rc == -1) + return rc; pb.parent_fd = rc; struct stat st; @@ -421,8 +427,10 @@ int unveil(const char *path, const char *permissions) { // if the host environment enables unveil() to impose true security // restrictions because the default behavior is to silently succeed // so that programs will err on the side of working if distributed. - if (permissions) return einval(); - if (IsOpenbsd()) return 0; + if (permissions) + return einval(); + if (IsOpenbsd()) + return 0; if (landlock_abi_version != -1) { unassert(landlock_abi_version >= 1); return landlock_abi_version; diff --git a/libc/calls/usleep.c b/libc/calls/usleep.c index 2aefe53a4..6fafae9e8 100644 --- a/libc/calls/usleep.c +++ b/libc/calls/usleep.c @@ -37,6 +37,7 @@ int usleep(uint64_t micros) { errno_t err; struct timespec ts = timespec_frommicros(micros); err = clock_nanosleep(CLOCK_REALTIME, 0, &ts, 0); - if (err) return errno = err, -1; + if (err) + return errno = err, -1; return 0; } diff --git a/libc/calls/utimensat-nt.c b/libc/calls/utimensat-nt.c index b2c520a81..ce843388c 100644 --- a/libc/calls/utimensat-nt.c +++ b/libc/calls/utimensat-nt.c @@ -44,7 +44,8 @@ static textwindows int sys_utimensat_nt_impl(int dirfd, const char *path, struct NtFileTime ft[2], *ftp[2]; if (path) { - if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; + if (__mkntpathat(dirfd, path, 0, path16) == -1) + return -1; if ((fh = CreateFile( path16, kNtFileWriteAttributes, kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, NULL, diff --git a/libc/calls/vdsofunc.greg.c b/libc/calls/vdsofunc.greg.c index cc4ca2431..69b2f774d 100644 --- a/libc/calls/vdsofunc.greg.c +++ b/libc/calls/vdsofunc.greg.c @@ -35,7 +35,8 @@ // needed to avoid asan restrictions on strcmp static int StrCmp(const char *l, const char *r) { size_t i = 0; - while (l[i] == r[i] && r[i]) ++i; + while (l[i] == r[i] && r[i]) + ++i; return (l[i] & 255) - (r[i] & 255); } diff --git a/libc/calls/winexec.c b/libc/calls/winexec.c index e61afeaa6..cdb41dd72 100644 --- a/libc/calls/winexec.c +++ b/libc/calls/winexec.c @@ -40,9 +40,12 @@ static uint32_t GetFileExtension(const char16_t *s) { n = s ? strlen16(s) : 0; for (i = w = 0; n--;) { wint_t c = s[n]; - if (!IsGraph(c)) return 0; - if (c == '.') break; - if (++i > 4) return 0; + if (!IsGraph(c)) + return 0; + if (c == '.') + break; + if (++i > 4) + return 0; w <<= 8; w |= kToLower[c]; } diff --git a/libc/calls/write-nt.c b/libc/calls/write-nt.c index f885adaa3..c5ae7cb02 100644 --- a/libc/calls/write-nt.c +++ b/libc/calls/write-nt.c @@ -67,7 +67,8 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size, ssize_t rc; rc = sys_readwrite_nt(fd, data, size, offset, handle, waitmask, (void *)WriteFile); - if (rc != -2) return rc; + if (rc != -2) + return rc; // mops up win32 errors switch (GetLastError()) { @@ -91,11 +92,14 @@ static textwindows ssize_t sys_write_nt2(int fd, const struct iovec *iov, uint64_t waitmask) { ssize_t rc; size_t i, total; - if (opt_offset < -1) return einval(); - while (iovlen && !iov[0].iov_len) iov++, iovlen--; + if (opt_offset < -1) + return einval(); + while (iovlen && !iov[0].iov_len) + iov++, iovlen--; if (iovlen) { for (total = i = 0; i < iovlen; ++i) { - if (!iov[i].iov_len) continue; + if (!iov[i].iov_len) + continue; rc = sys_write_nt_impl(fd, iov[i].iov_base, iov[i].iov_len, opt_offset, waitmask); if (rc == -1) { @@ -106,8 +110,10 @@ static textwindows ssize_t sys_write_nt2(int fd, const struct iovec *iov, } } total += rc; - if (opt_offset != -1) opt_offset += rc; - if (rc < iov[i].iov_len) break; + if (opt_offset != -1) + opt_offset += rc; + if (rc < iov[i].iov_len) + break; } return total; } else { diff --git a/libc/calls/writev-metal.c b/libc/calls/writev-metal.c index 6c83b4385..a3e87c6cd 100644 --- a/libc/calls/writev-metal.c +++ b/libc/calls/writev-metal.c @@ -28,7 +28,8 @@ ssize_t sys_writev_metal(struct Fd *fd, const struct iovec *iov, int iovlen) { switch (fd->kind) { case kFdConsole: - if (_weaken(sys_writev_vga)) _weaken(sys_writev_vga)(fd, iov, iovlen); + if (_weaken(sys_writev_vga)) + _weaken(sys_writev_vga)(fd, iov, iovlen); /* fallthrough */ case kFdSerial: return sys_writev_serial(fd, iov, iovlen); diff --git a/libc/dlopen/dlopen.c b/libc/dlopen/dlopen.c index ae5af3e40..c5cb457ba 100644 --- a/libc/dlopen/dlopen.c +++ b/libc/dlopen/dlopen.c @@ -161,9 +161,12 @@ static int is_file_newer_than(const char *path, const char *other) { static unsigned elf2prot(unsigned x) { unsigned r = 0; - if (x & PF_R) r += PROT_READ; - if (x & PF_W) r += PROT_WRITE; - if (x & PF_X) r += PROT_EXEC; + if (x & PF_R) + r += PROT_READ; + if (x & PF_W) + r += PROT_WRITE; + if (x & PF_X) + r += PROT_EXEC; return r; } @@ -284,7 +287,8 @@ static dontinline bool elf_load(struct Loaded *l, const char *file, long pagesz, static long *push_strs(long *sp, char **list, int count) { *--sp = 0; - while (count) *--sp = (long)list[--count]; + while (count) + *--sp = (long)list[--count]; return sp; } @@ -316,12 +320,14 @@ static dontinline void elf_exec(const char *file, char **envp) { // count environment variables int envc = 0; - while (envp[envc]) envc++; + while (envp[envc]) + envc++; // count auxiliary values int auxc = 0; Elf64_auxv_t *av; - for (av = (Elf64_auxv_t *)__auxv; av->a_type; ++av) auxc++; + for (av = (Elf64_auxv_t *)__auxv; av->a_type; ++av) + auxc++; // create environment block for embedded process // the platform libc will save its location for getenv(), etc. @@ -332,10 +338,12 @@ static dontinline void elf_exec(const char *file, char **envp) { size_t argsize = (1 + 2 + 1 + envc + 1 + auxc * 2 + 1 + 3) * 8; size_t mapsize = (stksize + argsize + (pagesz - 1)) & -pagesz; size_t skew = (mapsize - argsize) & (stkalign - 1); - if (IsFreebsd()) skew += 8; // FreeBSD calls _start() like a C function + if (IsFreebsd()) + skew += 8; // FreeBSD calls _start() like a C function map = __sys_mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0, 0); - if (map == MAP_FAILED) return; + if (map == MAP_FAILED) + return; long *sp = (long *)(map + mapsize - skew); // push argument string @@ -348,14 +356,22 @@ static dontinline void elf_exec(const char *file, char **envp) { unsigned long key, val; for (av = (Elf64_auxv_t *)__auxv; (key = av->a_type); ++av) { val = av->a_un.a_val; - if (key == AT_PHDR) val = (long)(prog.base + prog.eh.e_phoff); - if (key == AT_PHENT) val = prog.eh.e_phentsize; - if (key == AT_PHNUM) val = prog.eh.e_phnum; - if (key == AT_PAGESZ) val = pagesz; - if (key == AT_BASE) val = (long)interp.base; - if (key == AT_FLAGS) val = 0; - if (key == AT_ENTRY) val = (long)prog.entry; - if (key == AT_EXECFN) val = (long)program_invocation_name; + if (key == AT_PHDR) + val = (long)(prog.base + prog.eh.e_phoff); + if (key == AT_PHENT) + val = prog.eh.e_phentsize; + if (key == AT_PHNUM) + val = prog.eh.e_phnum; + if (key == AT_PAGESZ) + val = pagesz; + if (key == AT_BASE) + val = (long)interp.base; + if (key == AT_FLAGS) + val = 0; + if (key == AT_ENTRY) + val = (long)prog.entry; + if (key == AT_EXECFN) + val = (long)program_invocation_name; *--sp = val; *--sp = key; } @@ -497,11 +513,13 @@ static void *foreign_thunk_sysv(void *func) { uint8_t *code, *p; #ifdef __x86_64__ // it is no longer needed - if (1) return func; + if (1) + return func; // movabs $func,%rax // movabs $foreign_tramp,%r10 // jmp *%r10 - if (!(p = code = foreign_alloc(23))) return 0; // 10 + 10 + 3 = 23 + if (!(p = code = foreign_alloc(23))) + return 0; // 10 + 10 + 3 = 23 p = movimm(p, 0, (uintptr_t)func); p = movimm(p, 10, (uintptr_t)foreign_tramp); *p++ = 0x41; @@ -524,7 +542,8 @@ static void *foreign_thunk_sysv(void *func) { static void *foreign_thunk_nt(void *func) { uint8_t *code; - if (!(code = foreign_alloc(27))) return 0; + if (!(code = foreign_alloc(27))) + return 0; // push %rbp code[0] = 0x55; // mov %rsp,%rbp diff --git a/libc/elf/getelfprogramheaderaddress.c b/libc/elf/getelfprogramheaderaddress.c index f2397ced0..10f42aff9 100644 --- a/libc/elf/getelfprogramheaderaddress.c +++ b/libc/elf/getelfprogramheaderaddress.c @@ -32,10 +32,15 @@ Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *elf, // size_t mapsize, // Elf64_Half i) { // Elf64_Off off; - if (i >= elf->e_phnum) return 0; - if (elf->e_phoff <= 0) return 0; - if (elf->e_phoff >= mapsize) return 0; - if (elf->e_phentsize < sizeof(Elf64_Phdr)) return 0; - if ((off = elf->e_phoff + (unsigned)i * elf->e_phentsize) > mapsize) return 0; + if (i >= elf->e_phnum) + return 0; + if (elf->e_phoff <= 0) + return 0; + if (elf->e_phoff >= mapsize) + return 0; + if (elf->e_phentsize < sizeof(Elf64_Phdr)) + return 0; + if ((off = elf->e_phoff + (unsigned)i * elf->e_phentsize) > mapsize) + return 0; return (Elf64_Phdr *)((char *)elf + off); } diff --git a/libc/elf/getelfsectionaddress.c b/libc/elf/getelfsectionaddress.c index 3d1fc4a61..b84e9c316 100644 --- a/libc/elf/getelfsectionaddress.c +++ b/libc/elf/getelfsectionaddress.c @@ -38,10 +38,15 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated size_t mapsize, // validated const Elf64_Shdr *shdr) { // foreign Elf64_Off last; - if (!shdr) return 0; - if (!shdr->sh_size) return (void *)elf; - if (shdr->sh_type == SHT_NOBITS) return 0; - if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0; - if (last > mapsize) return 0; + if (!shdr) + return 0; + if (!shdr->sh_size) + return (void *)elf; + if (shdr->sh_type == SHT_NOBITS) + return 0; + if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) + return 0; + if (last > mapsize) + return 0; return (char *)elf + shdr->sh_offset; } diff --git a/libc/elf/getelfsectionheaderaddress.c b/libc/elf/getelfsectionheaderaddress.c index 2a2207e13..60b6034a2 100644 --- a/libc/elf/getelfsectionheaderaddress.c +++ b/libc/elf/getelfsectionheaderaddress.c @@ -38,11 +38,17 @@ Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *elf, // size_t mapsize, // Elf64_Half i) { // Elf64_Off off; - if (i >= SHN_LORESERVE) return 0; - if (i >= elf->e_shnum) return 0; - if (elf->e_shoff <= 0) return 0; - if (elf->e_shoff >= mapsize) return 0; - if (elf->e_shentsize < sizeof(Elf64_Shdr)) return 0; - if ((off = elf->e_shoff + (unsigned)i * elf->e_shentsize) > mapsize) return 0; + if (i >= SHN_LORESERVE) + return 0; + if (i >= elf->e_shnum) + return 0; + if (elf->e_shoff <= 0) + return 0; + if (elf->e_shoff >= mapsize) + return 0; + if (elf->e_shentsize < sizeof(Elf64_Shdr)) + return 0; + if ((off = elf->e_shoff + (unsigned)i * elf->e_shentsize) > mapsize) + return 0; return (Elf64_Shdr *)((char *)elf + off); } diff --git a/libc/elf/getelfsectionname.c b/libc/elf/getelfsectionname.c index ab1d201b8..dd9c06faf 100644 --- a/libc/elf/getelfsectionname.c +++ b/libc/elf/getelfsectionname.c @@ -20,7 +20,8 @@ char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize, const Elf64_Shdr *shdr) { - if (!shdr) return 0; + if (!shdr) + return 0; return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize), shdr->sh_name); } diff --git a/libc/elf/getelfsegmentaddress.c b/libc/elf/getelfsegmentaddress.c index 210d29a4f..2d7944010 100644 --- a/libc/elf/getelfsegmentaddress.c +++ b/libc/elf/getelfsegmentaddress.c @@ -40,9 +40,13 @@ void *GetElfSegmentAddress(const Elf64_Ehdr *elf, // validated size_t mapsize, // validated const Elf64_Phdr *phdr) { // foreign Elf64_Off last; - if (!phdr) return 0; - if (phdr->p_filesz <= 0) return 0; - if (ckd_add(&last, phdr->p_offset, phdr->p_filesz)) return 0; - if (last > mapsize) return 0; + if (!phdr) + return 0; + if (phdr->p_filesz <= 0) + return 0; + if (ckd_add(&last, phdr->p_offset, phdr->p_filesz)) + return 0; + if (last > mapsize) + return 0; return (char *)elf + phdr->p_offset; } diff --git a/libc/elf/getelfstring.c b/libc/elf/getelfstring.c index 06c615988..78de4aec1 100644 --- a/libc/elf/getelfstring.c +++ b/libc/elf/getelfstring.c @@ -44,11 +44,16 @@ char *GetElfString(const Elf64_Ehdr *elf, // validated const char *strtab, // validated Elf64_Word i) { // foreign const char *e; - if (!i) return ""; + if (!i) + return ""; e = (const char *)elf; - if (!strtab) return 0; - if (i >= mapsize) return 0; - if (strtab + i >= e + mapsize) return 0; - if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0; + if (!strtab) + return 0; + if (i >= mapsize) + return 0; + if (strtab + i >= e + mapsize) + return 0; + if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) + return 0; return (char *)strtab + i; } diff --git a/libc/elf/iself64binary.c b/libc/elf/iself64binary.c index ad5a77f38..6f896e119 100644 --- a/libc/elf/iself64binary.c +++ b/libc/elf/iself64binary.c @@ -29,7 +29,9 @@ * @return true if elf header looks legit */ bool32 IsElf64Binary(const Elf64_Ehdr *elf, size_t mapsize) { - if (mapsize < sizeof(Elf64_Ehdr)) return false; - if (READ32LE(elf->e_ident) != READ32LE(ELFMAG)) return false; + if (mapsize < sizeof(Elf64_Ehdr)) + return false; + if (READ32LE(elf->e_ident) != READ32LE(ELFMAG)) + return false; return elf->e_ident[EI_CLASS] != ELFCLASS32; } diff --git a/libc/fmt/atoi.c b/libc/fmt/atoi.c index 9030bf468..bca5be980 100644 --- a/libc/fmt/atoi.c +++ b/libc/fmt/atoi.c @@ -31,10 +31,12 @@ */ int atoi(const char *nptr) { int x, c, d; - do c = *nptr++; + do + c = *nptr++; while (isspace(c)); d = c == '-' ? -1 : 1; - if (c == '-' || c == '+') c = *nptr++; + if (c == '-' || c == '+') + c = *nptr++; for (x = 0; isdigit(c); c = *nptr++) { x *= 10; x += (c - '0') * d; diff --git a/libc/fmt/atol.c b/libc/fmt/atol.c index 8102c3228..5bce5bcac 100644 --- a/libc/fmt/atol.c +++ b/libc/fmt/atol.c @@ -32,10 +32,12 @@ long atol(const char *nptr) { long x; int c, d; - do c = *nptr++; + do + c = *nptr++; while (isspace(c)); d = c == '-' ? -1 : 1; - if (c == '-' || c == '+') c = *nptr++; + if (c == '-' || c == '+') + c = *nptr++; for (x = 0; isdigit(c); c = *nptr++) { x *= 10; x += (c - '0') * d; diff --git a/libc/fmt/dirname.c b/libc/fmt/dirname.c index d8d001320..8daf49c34 100644 --- a/libc/fmt/dirname.c +++ b/libc/fmt/dirname.c @@ -41,13 +41,16 @@ char *dirname(char *path) { if (path && *path) { i = strlen(path) - 1; for (; path[i] == '/'; i--) { - if (!i) return "/"; + if (!i) + return "/"; } for (; path[i] != '/'; i--) { - if (!i) return "."; + if (!i) + return "."; } for (; path[i] == '/'; i--) { - if (!i) return "/"; + if (!i) + return "/"; } path[i + 1] = 0; return path; diff --git a/libc/fmt/formatbinary64.c b/libc/fmt/formatbinary64.c index 70b316856..616383167 100644 --- a/libc/fmt/formatbinary64.c +++ b/libc/fmt/formatbinary64.c @@ -21,11 +21,14 @@ static inline int PickGoodWidth(unsigned x) { if (x < 16) { - if (x < 2) return 1; - if (x < 8) return 7; + if (x < 2) + return 1; + if (x < 8) + return 7; return 15; } else { - if (x < 32) return 31; + if (x < 32) + return 31; return 63; } } diff --git a/libc/fmt/formatint64thousands.c b/libc/fmt/formatint64thousands.c index 9b20451dd..86e9c9c93 100644 --- a/libc/fmt/formatint64thousands.c +++ b/libc/fmt/formatint64thousands.c @@ -34,8 +34,10 @@ dontinline char *FormatUint64Thousands(char p[static 27], uint64_t x) { } while (x); for (;;) { *p++ = m[--i]; - if (!i) break; - if (!(i % 3)) *p++ = ','; + if (!i) + break; + if (!(i % 3)) + *p++ = ','; } *p = '\0'; return p; @@ -48,6 +50,7 @@ dontinline char *FormatUint64Thousands(char p[static 27], uint64_t x) { * @return pointer to nul byte */ char *FormatInt64Thousands(char p[static 27], int64_t x) { - if (x < 0) *p++ = '-', x = -(uint64_t)x; + if (x < 0) + *p++ = '-', x = -(uint64_t)x; return FormatUint64Thousands(p, x); } diff --git a/libc/fmt/formatoctal64.c b/libc/fmt/formatoctal64.c index 53a513118..75627613a 100644 --- a/libc/fmt/formatoctal64.c +++ b/libc/fmt/formatoctal64.c @@ -34,7 +34,8 @@ char *FormatOctal64(char p[hasatleast 24], uint64_t x, bool32 z) { p[i++] = x % 8 + '0'; x = x / 8; } while (x > 0); - if (z) p[i++] = '0'; + if (z) + p[i++] = '0'; p[i] = '\0'; if (i) { for (a = 0, b = i - 1; a < b; ++a, --b) { diff --git a/libc/fmt/itoa64fixed16.greg.c b/libc/fmt/itoa64fixed16.greg.c index 4342d35a1..92988023b 100644 --- a/libc/fmt/itoa64fixed16.greg.c +++ b/libc/fmt/itoa64fixed16.greg.c @@ -22,7 +22,8 @@ size_t uint64toarray_fixed16(uint64_t x, char b[hasatleast 17], uint8_t k) { char *p; unassert(k <= 64 && !(k & 3)); - for (p = b; k > 0;) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; + for (p = b; k > 0;) + *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; *p = '\0'; return p - b; } diff --git a/libc/fmt/sizetol.c b/libc/fmt/sizetol.c index 2f632ed38..e1828fc9d 100644 --- a/libc/fmt/sizetol.c +++ b/libc/fmt/sizetol.c @@ -83,7 +83,8 @@ long sizetol(const char *s, long b) { c = *s++; } while (c == ' ' || c == '\t'); d = c == '-' ? -1 : 1; - if (c == '-' || c == '+') c = *s++; + if (c == '-' || c == '+') + c = *s++; if (!isdigit(c)) { return einval(); } diff --git a/libc/fmt/unbing.c b/libc/fmt/unbing.c index 235d73411..ddee8e828 100644 --- a/libc/fmt/unbing.c +++ b/libc/fmt/unbing.c @@ -216,7 +216,8 @@ static const int kCp437i[] = { */ int unbing(int c) { int m, l, r; - if (32 <= c && c < 127) return c; + if (32 <= c && c < 127) + return c; l = 0; r = ARRAYLEN(kCp437i) - 1; while (l <= r) { diff --git a/libc/fmt/unzleb64.c b/libc/fmt/unzleb64.c index 1bb485b30..edc7c71c7 100644 --- a/libc/fmt/unzleb64.c +++ b/libc/fmt/unzleb64.c @@ -46,7 +46,8 @@ int unzleb64(const char *p, size_t n, int64_t *o) { i = 0; u = 0; do { - if (i == n) return -1; + if (i == n) + return -1; c = p[i] & 255; t = c & 127; if (i < 10) { @@ -55,6 +56,7 @@ int unzleb64(const char *p, size_t n, int64_t *o) { } ++i; } while (c & 128); - if (o) *o = (u >> 1) ^ -(u & 1); + if (o) + *o = (u >> 1) ^ -(u & 1); return i; } diff --git a/libc/intrin/__getenv.c b/libc/intrin/__getenv.c index 878213cbb..b94d09798 100644 --- a/libc/intrin/__getenv.c +++ b/libc/intrin/__getenv.c @@ -26,8 +26,10 @@ privileged struct Env __getenv(char **p, const char *k) { for (i = 0; (t = p[i]); ++i) { for (j = 0;; ++j) { if (!k[j] || k[j] == '=') { - if (!t[j]) return (struct Env){t + j, i}; - if (t[j] == '=') return (struct Env){t + j + 1, i}; + if (!t[j]) + return (struct Env){t + j, i}; + if (t[j] == '=') + return (struct Env){t + j + 1, i}; break; } if (k[j] != t[j]) { diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index dc28ff4aa..c472997b9 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -204,7 +204,8 @@ static uint64_t __asan_roundup2pow(uint64_t x) { static char *__asan_utf8cpy(char *p, unsigned c) { uint64_t z; z = tpenc(c); - do *p++ = z; + do + *p++ = z; while ((z >>= 8)); return p; } @@ -267,7 +268,8 @@ void __asan_memset(void *p, char c, size_t n) { asm volatile("" ::: "memory"); __builtin_memcpy(b + i + 8, &x, 8); } while ((i += 16) + 16 <= n); - for (; i < n; ++i) b[i] = x; + for (; i < n; ++i) + b[i] = x; break; } } @@ -331,7 +333,8 @@ static void *__asan_mempcpy(void *dst, const void *src, size_t n) { asm volatile("" ::: "memory"); __builtin_memcpy(d + i, &a, 8); } while ((i += 8) + 8 <= n); - for (; i < n; ++i) d[i] = s[i]; + for (; i < n; ++i) + d[i] = s[i]; return d + i; } } @@ -342,7 +345,8 @@ void *__asan_memcpy(void *dst, const void *src, size_t n) { } static char *__asan_hexcpy(char *p, uint64_t x, uint8_t k) { - while (k) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; + while (k) + *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; return p; } @@ -371,14 +375,16 @@ void __asan_poison(void *p, long n, signed char t) { signed char k, *s; s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000); if ((k = (intptr_t)p & 7)) { - if ((!*s && n >= 8 - k) || *s > k) *s = k; + if ((!*s && n >= 8 - k) || *s > k) + *s = k; n -= MIN(8 - k, n); s += 1; } __asan_memset(s, t, n >> 3); if ((k = n & 7)) { s += n >> 3; - if (*s < 0 || (*s > 0 && *s <= k)) *s = t; + if (*s < 0 || (*s > 0 && *s <= k)) + *s = t; } } @@ -388,7 +394,8 @@ void __asan_unpoison(void *p, long n) { s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000); if (UNLIKELY(k)) { if (k + n < 8) { - if (n > 0) *s = MAX(*s, k + n); + if (n > 0) + *s = MAX(*s, k + n); return; } n -= MIN(8 - k, n); @@ -397,8 +404,10 @@ void __asan_unpoison(void *p, long n) { __asan_memset(s, 0, n >> 3); if ((k = n & 7)) { s += n >> 3; - if (*s < 0) *s = k; - if (*s > 0) *s = MAX(*s, k); + if (*s < 0) + *s = k; + if (*s > 0) + *s = MAX(*s, k); } } @@ -438,7 +447,8 @@ static struct AsanFault __asan_checka(const signed char *s, long ndiv8) { uint64_t w; const signed char *e = s + ndiv8; for (; ((intptr_t)s & 7) && s < e; ++s) { - if (*s) return __asan_fault(s - 1, kAsanHeapOverrun); + if (*s) + return __asan_fault(s - 1, kAsanHeapOverrun); } for (; s + 8 <= e; s += 8) { if (UNLIKELY(!((intptr_t)s & (FRAMESIZE - 1))) && kisdangerous(s)) { @@ -450,7 +460,8 @@ static struct AsanFault __asan_checka(const signed char *s, long ndiv8) { } } for (; s < e; ++s) { - if (*s) return __asan_fault(s - 1, kAsanHeapOverrun); + if (*s) + return __asan_fault(s - 1, kAsanHeapOverrun); } return (struct AsanFault){0}; } @@ -586,9 +597,12 @@ bool __asan_is_valid_str(const char *p) { */ bool __asan_is_valid_strlist(char *const *p) { for (;; ++p) { - if (!__asan_is_valid(p, sizeof(char *))) return false; - if (!*p) return true; - if (!__asan_is_valid_str(*p)) return false; + if (!__asan_is_valid(p, sizeof(char *))) + return false; + if (!*p) + return true; + if (!__asan_is_valid_str(*p)) + return false; } } @@ -877,7 +891,8 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size, } *p++ = '\e', *p++ = '[', *p++ = '3', *p++ = '9', *p++ = 'm'; *p++ = '\n'; - for (i = 0; (intptr_t)(base + i) & 7; ++i) *p++ = ' '; + for (i = 0; (intptr_t)(base + i) & 7; ++i) + *p++ = ' '; for (; i + 8 <= 80; i += 8) { q = p + 8; *p++ = '|'; @@ -891,7 +906,8 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size, *p++ = ' '; } } - for (; i < 80; ++i) *p++ = ' '; + for (; i < 80; ++i) + *p++ = ' '; *p++ = '\n'; for (i = 0; i < 80; ++i) { p = __asan_utf8cpy(p, __asan_exists(base + i) @@ -909,9 +925,11 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size, y = m->p[i].y; p = __asan_format_interval(p, x << 16, (y << 16) + (FRAMESIZE - 1)); z = (intptr_t)addr >> 16; - if (x <= z && z <= y) p = __asan_stpcpy(p, " ←address"); + if (x <= z && z <= y) + p = __asan_stpcpy(p, " ←address"); z = (((intptr_t)addr >> 3) + 0x7fff8000) >> 16; - if (x <= z && z <= y) p = __asan_stpcpy(p, " ←shadow"); + if (x <= z && z <= y) + p = __asan_stpcpy(p, " ←shadow"); *p++ = '\n'; } __mmi_unlock(); @@ -937,13 +955,15 @@ static wontreturn void __asan_verify_failed(const void *p, size_t n, void __asan_verify(const void *p, size_t n) { struct AsanFault f; - if (!(f = __asan_check(p, n)).kind) return; + if (!(f = __asan_check(p, n)).kind) + return; __asan_verify_failed(p, n, f); } void __asan_verify_str(const char *p) { struct AsanFault f; - if (!(f = __asan_check_str(p)).kind) return; + if (!(f = __asan_check_str(p)).kind) + return; __asan_verify_failed(UNSHADOW(f.shadow), 8, f); } @@ -998,7 +1018,8 @@ static bool __asan_read48(uint64_t value, uint64_t *x) { static void __asan_rawtrace(struct AsanTrace *bt, const struct StackFrame *bp) { size_t i; for (i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) { - if (kisdangerous(bp)) break; + if (kisdangerous(bp)) + break; bt->p[i] = bp->addr; } for (; i < ARRAYLEN(bt->p); ++i) { @@ -1015,14 +1036,16 @@ static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) { gi = garbage ? garbage->i : 0; for (f1 = -1, i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) { if (f1 != (f2 = ((intptr_t)bp >> 16))) { - if (kisdangerous(bp)) break; + if (kisdangerous(bp)) + break; f1 = f2; } if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) { addr = bp->addr; #ifdef __x86_64__ if (addr == (uintptr_t)_weaken(__gc) && (uintptr_t)_weaken(__gc)) { - do --gi; + do + --gi; while ((addr = garbage->p[gi].ret) == (uintptr_t)_weaken(__gc)); } #endif @@ -1129,13 +1152,19 @@ int __asan_is_leaky(void *p) { intptr_t f, *l; struct AsanExtra *e; struct SymbolTable *st; - if (!_weaken(GetSymbolTable)) notpossible; - if (!(e = __asan_get_extra(p, &c))) return 0; - if (!__asan_read48(e->size, &n)) return 0; - if (!__asan_is_mapped((((intptr_t)p >> 3) + 0x7fff8000) >> 16)) return 0; - if (!(st = GetSymbolTable())) return 0; + if (!_weaken(GetSymbolTable)) + notpossible; + if (!(e = __asan_get_extra(p, &c))) + return 0; + if (!__asan_read48(e->size, &n)) + return 0; + if (!__asan_is_mapped((((intptr_t)p >> 3) + 0x7fff8000) >> 16)) + return 0; + if (!(st = GetSymbolTable())) + return 0; for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) { - if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1) continue; + if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1) + continue; f = st->addr_base + st->symbols[sym].x; for (l = _leaky_start; l < _leaky_end; ++l) { if (f == *l) { @@ -1167,7 +1196,8 @@ static void __asan_deallocate(char *p, long kind) { } void __asan_free(void *p) { - if (!p) return; + if (!p) + return; __asan_deallocate(p, kAsanHeapFree); } @@ -1236,7 +1266,8 @@ void *__asan_memalign(size_t align, size_t size) { void *__asan_calloc(size_t n, size_t m) { struct AsanTrace bt; __asan_trace(&bt, RBP); - if (ckd_mul(&n, n, m)) n = -1; + if (ckd_mul(&n, n, m)) + n = -1; return __asan_allocate(16, n, &bt, kAsanHeapUnderrun, kAsanHeapOverrun, 0x00); } @@ -1342,7 +1373,8 @@ void __asan_alloca_poison(char *addr, uintptr_t size) { void __asan_allocas_unpoison(uintptr_t x, uintptr_t y) { ASAN_LOG("__asan_allocas_unpoison(%p, %p)\n", x, y); - if (!x || x > y) return; + if (!x || x > y) + return; __asan_unpoison((char *)x, y - x); } @@ -1455,7 +1487,8 @@ static textstartup void __asan_shadow_existing_mappings(void) { static size_t __asan_strlen(const char *s) { size_t i = 0; - while (s[i]) ++i; + while (s[i]) + ++i; return i; } @@ -1465,7 +1498,8 @@ forceinline ssize_t __write_str(const char *s) { void __asan_init(int argc, char **argv, char **envp, unsigned long *auxv) { static bool once; - if (!_cmpxchg(&once, false, true)) return; + if (!_cmpxchg(&once, false, true)) + return; if (IsWindows() && NtGetVersion() < kNtVersionWindows10) { __write_str("error: asan binaries require windows10\r\n"); _Exit(0); /* So `make MODE=dbg test` passes w/ Windows7 */ diff --git a/libc/intrin/createdirectory.c b/libc/intrin/createdirectory.c index 2f3ab0273..e0e787859 100644 --- a/libc/intrin/createdirectory.c +++ b/libc/intrin/createdirectory.c @@ -34,7 +34,8 @@ textwindows bool32 CreateDirectory(const char16_t *lpPathName, const struct NtSecurityAttributes *lpSec) { bool32 ok; ok = __imp_CreateDirectoryW(lpPathName, lpSec); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("CreateDirectory(%#hs, %s) → %hhhd% m", lpPathName, DescribeNtSecurityAttributes(lpSec), ok); return ok; diff --git a/libc/intrin/createfile.c b/libc/intrin/createfile.c index d3ca94bc4..594329c64 100644 --- a/libc/intrin/createfile.c +++ b/libc/intrin/createfile.c @@ -66,8 +66,10 @@ TryAgain: if (hHandle == -1) { switch (__imp_GetLastError()) { case kNtErrorPipeBusy: - if (micros >= 1024) __imp_Sleep(micros / 1024); - if (micros < 1024 * 1024) micros <<= 1; + if (micros >= 1024) + __imp_Sleep(micros / 1024); + if (micros < 1024 * 1024) + micros <<= 1; goto TryAgain; case kNtErrorAccessDenied: // GetNtOpenFlags() always greedily requests execute permissions diff --git a/libc/intrin/createfilemapping.c b/libc/intrin/createfilemapping.c index 25713b707..147793ec7 100644 --- a/libc/intrin/createfilemapping.c +++ b/libc/intrin/createfilemapping.c @@ -42,7 +42,8 @@ textwindows int64_t CreateFileMapping( hHandle = __imp_CreateFileMappingW(opt_hFile, opt_lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, opt_lpName); - if (!hHandle) __winerr(); + if (!hHandle) + __winerr(); NTTRACE("CreateFileMapping(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile, DescribeNtSecurityAttributes(opt_lpFileMappingAttributes), DescribeNtPageFlags(flProtect), diff --git a/libc/intrin/createfilemappingnuma.c b/libc/intrin/createfilemappingnuma.c index d96235f84..a99653617 100644 --- a/libc/intrin/createfilemappingnuma.c +++ b/libc/intrin/createfilemappingnuma.c @@ -43,7 +43,8 @@ textwindows int64_t CreateFileMappingNuma( hHandle = __imp_CreateFileMappingNumaW( opt_hFile, opt_lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, opt_lpName, nndDesiredNumaNode); - if (!hHandle) __winerr(); + if (!hHandle) + __winerr(); NTTRACE("CreateFileMappingNuma(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile, DescribeNtSecurityAttributes(opt_lpFileMappingAttributes), DescribeNtPageFlags(flProtect), diff --git a/libc/intrin/createnamedpipe.c b/libc/intrin/createnamedpipe.c index 2133fe2f7..2bb67417a 100644 --- a/libc/intrin/createnamedpipe.c +++ b/libc/intrin/createnamedpipe.c @@ -49,11 +49,14 @@ TryAgain: nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOutMs, opt_lpSecurityAttributes); if (hServer == -1 && __imp_GetLastError() == kNtErrorPipeBusy) { - if (micros >= 1024) __imp_Sleep(micros / 1024); - if (micros < 1024 * 1024) micros <<= 1; + if (micros >= 1024) + __imp_Sleep(micros / 1024); + if (micros < 1024 * 1024) + micros <<= 1; goto TryAgain; } - if (hServer == -1) __winerr(); + if (hServer == -1) + __winerr(); NTTRACE("CreateNamedPipe(%#hs, %s, %s, %u, %'u, %'u, %'u, %s) → %ld% m", lpName, DescribeNtPipeOpenFlags(dwOpenMode), DescribeNtPipeModeFlags(dwPipeMode), nMaxInstances, nOutBufferSize, diff --git a/libc/intrin/createpipe.c b/libc/intrin/createpipe.c index 71f992ec6..7d6e9df1e 100644 --- a/libc/intrin/createpipe.c +++ b/libc/intrin/createpipe.c @@ -35,7 +35,8 @@ textwindows bool32 CreatePipe( bool32 ok; ok = __imp_CreatePipe(out_hReadPipe, out_hWritePipe, opt_lpPipeAttributes, nSize); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("CreatePipe([%ld], [%ld], %s, %'zu) → %hhhd% m", *out_hReadPipe, *out_hWritePipe, DescribeNtSecurityAttributes(opt_lpPipeAttributes), nSize, ok); diff --git a/libc/intrin/createprocess.c b/libc/intrin/createprocess.c index 73b2a0de4..4205b5bcd 100644 --- a/libc/intrin/createprocess.c +++ b/libc/intrin/createprocess.c @@ -44,7 +44,8 @@ CreateProcess(const char16_t *opt_lpApplicationName, char16_t *lpCommandLine, bInheritHandles, dwCreationFlags, opt_lpEnvironment, opt_lpCurrentDirectory, lpStartupInfo, opt_out_lpProcessInformation); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("CreateProcess(%#!hs, %#!hs, %s, %s, %hhhd, %u, %p, %#!hs, %p, %p) → " "%hhhd% m", opt_lpApplicationName, lpCommandLine, diff --git a/libc/intrin/createsymboliclink.c b/libc/intrin/createsymboliclink.c index 59b317a1e..663753b13 100644 --- a/libc/intrin/createsymboliclink.c +++ b/libc/intrin/createsymboliclink.c @@ -32,7 +32,8 @@ bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName, const char16_t *lpTargetPathName, uint32_t dwFlags) { bool32 ok; ok = __imp_CreateSymbolicLinkW(lpSymlinkFileName, lpTargetPathName, dwFlags); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("CreateSymbolicLink(%#hs, %#hs, %s) → %hhhd% m", lpSymlinkFileName, lpTargetPathName, DescribeNtSymlinkFlags(dwFlags), ok); return ok; diff --git a/libc/intrin/cxaatexit.c b/libc/intrin/cxaatexit.c index 706e4af52..a5b001162 100644 --- a/libc/intrin/cxaatexit.c +++ b/libc/intrin/cxaatexit.c @@ -47,7 +47,8 @@ int __cxa_atexit(void *fp, void *arg, void *pred) { struct CxaAtexitBlock *b, *b2; __cxa_lock(); b = __cxa_blocks.p; - if (!b) b = __cxa_blocks.p = &__cxa_blocks.root; + if (!b) + b = __cxa_blocks.p = &__cxa_blocks.root; if (!~b->mask) { if (_weaken(calloc) && (b2 = _weaken(calloc)(1, sizeof(struct CxaAtexitBlock)))) { diff --git a/libc/intrin/deletefile.c b/libc/intrin/deletefile.c index 1b8aca8a2..1fd3b54ed 100644 --- a/libc/intrin/deletefile.c +++ b/libc/intrin/deletefile.c @@ -30,7 +30,8 @@ __msabi extern typeof(DeleteFile) *const __imp_DeleteFileW; textwindows bool32 DeleteFile(const char16_t *lpPathName) { bool32 ok; ok = __imp_DeleteFileW(lpPathName); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("DeleteFile(%#hs) → %hhhd% m", lpPathName, ok); return ok; } diff --git a/libc/intrin/describearchprctlcode.c b/libc/intrin/describearchprctlcode.c index a5c026321..57ad37830 100644 --- a/libc/intrin/describearchprctlcode.c +++ b/libc/intrin/describearchprctlcode.c @@ -22,10 +22,14 @@ #include "libc/sysv/consts/arch.h" const char *(DescribeArchPrctlCode)(char buf[12], int x) { - if (x == ARCH_SET_FS) return "ARCH_SET_FS"; - if (x == ARCH_GET_FS) return "ARCH_GET_FS"; - if (x == ARCH_SET_GS) return "ARCH_SET_GS"; - if (x == ARCH_GET_GS) return "ARCH_GET_GS"; + if (x == ARCH_SET_FS) + return "ARCH_SET_FS"; + if (x == ARCH_GET_FS) + return "ARCH_GET_FS"; + if (x == ARCH_SET_GS) + return "ARCH_SET_GS"; + if (x == ARCH_GET_GS) + return "ARCH_GET_GS"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describecancelstate.c b/libc/intrin/describecancelstate.c index 4750a9810..b6ef58702 100644 --- a/libc/intrin/describecancelstate.c +++ b/libc/intrin/describecancelstate.c @@ -21,11 +21,16 @@ #include "libc/thread/thread.h" const char *(DescribeCancelState)(char buf[12], int err, int *state) { - if (err) return "n/a"; - if (!state) return "NULL"; - if (*state == PTHREAD_CANCEL_ENABLE) return "PTHREAD_CANCEL_ENABLE"; - if (*state == PTHREAD_CANCEL_DISABLE) return "PTHREAD_CANCEL_DISABLE"; - if (*state == PTHREAD_CANCEL_MASKED) return "PTHREAD_CANCEL_MASKED"; + if (err) + return "n/a"; + if (!state) + return "NULL"; + if (*state == PTHREAD_CANCEL_ENABLE) + return "PTHREAD_CANCEL_ENABLE"; + if (*state == PTHREAD_CANCEL_DISABLE) + return "PTHREAD_CANCEL_DISABLE"; + if (*state == PTHREAD_CANCEL_MASKED) + return "PTHREAD_CANCEL_MASKED"; FormatInt32(buf, *state); return buf; } diff --git a/libc/intrin/describedirfd.c b/libc/intrin/describedirfd.c index 36f0c6991..a769f1225 100644 --- a/libc/intrin/describedirfd.c +++ b/libc/intrin/describedirfd.c @@ -21,7 +21,8 @@ #include "libc/sysv/consts/at.h" const char *(DescribeDirfd)(char buf[12], int dirfd) { - if (dirfd == AT_FDCWD) return "AT_FDCWD"; + if (dirfd == AT_FDCWD) + return "AT_FDCWD"; FormatInt32(buf, dirfd); return buf; } diff --git a/libc/intrin/describefdset.c b/libc/intrin/describefdset.c index 751652c1e..338121b2e 100644 --- a/libc/intrin/describefdset.c +++ b/libc/intrin/describefdset.c @@ -30,7 +30,8 @@ const char *(DescribeFdSet)(char buf[N], ssize_t rc, int nfds, fd_set *fds) { int o = 0; - if (!fds) return "NULL"; + if (!fds) + return "NULL"; if ((!IsAsan() && kisdangerous(fds)) || (IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) { ksnprintf(buf, N, "%p", fds); diff --git a/libc/intrin/describeflags.c b/libc/intrin/describeflags.c index f023a8f6e..cb316b244 100644 --- a/libc/intrin/describeflags.c +++ b/libc/intrin/describeflags.c @@ -27,32 +27,41 @@ const char *DescribeFlags(char *p, size_t n, const struct DescribeFlags *d, if (d[j].flag && d[j].flag != -1 && (x & d[j].flag) == d[j].flag) { x &= ~d[j].flag; if (t) { - if (i + 1 < n) p[i++] = '|'; + if (i + 1 < n) + p[i++] = '|'; } else { t = true; } for (k = 0; prefix && prefix[k]; ++k) { - if (i + 1 < n) p[i++] = prefix[k]; + if (i + 1 < n) + p[i++] = prefix[k]; } for (k = 0; d[j].name[k]; ++k) { - if (i + 1 < n) p[i++] = d[j].name[k]; + if (i + 1 < n) + p[i++] = d[j].name[k]; } } } if (x || !t) { - if (t && i + 1 < n) p[i++] = '|'; - if (i + 1 < n) p[i++] = '0'; + if (t && i + 1 < n) + p[i++] = '|'; + if (i + 1 < n) + p[i++] = '0'; if (x) { - if (i + 1 < n) p[i++] = 'x'; + if (i + 1 < n) + p[i++] = 'x'; k = 0; do { - if (i + 1 < n) b[k++] = "0123456789abcdef"[x % 16]; + if (i + 1 < n) + b[k++] = "0123456789abcdef"[x % 16]; } while ((x /= 16)); while (k--) { - if (i + 1 < n) p[i++] = b[k]; + if (i + 1 < n) + p[i++] = b[k]; } } } - if (i < n) p[i] = 0; + if (i < n) + p[i] = 0; return p; } diff --git a/libc/intrin/describeflock.c b/libc/intrin/describeflock.c index 9beee488b..83aea89bf 100644 --- a/libc/intrin/describeflock.c +++ b/libc/intrin/describeflock.c @@ -31,7 +31,8 @@ const char *(DescribeFlock)(char buf[N], int cmd, const struct flock *l) { int o = 0; - if (!l) return "NULL"; + if (!l) + return "NULL"; if ((!IsAsan() && kisdangerous(l)) || (IsAsan() && !__asan_is_valid(l, sizeof(*l)))) { ksnprintf(buf, N, "%p", l); diff --git a/libc/intrin/describeflocktype.c b/libc/intrin/describeflocktype.c index 22cb9cc70..67c13a024 100644 --- a/libc/intrin/describeflocktype.c +++ b/libc/intrin/describeflocktype.c @@ -20,9 +20,12 @@ #include "libc/sysv/consts/f.h" const char *(DescribeFlockType)(char buf[12], int x) { - if (x == F_RDLCK) return "F_RDLCK"; - if (x == F_WRLCK) return "F_WRLCK"; - if (x == F_UNLCK) return "F_UNLCK"; + if (x == F_RDLCK) + return "F_RDLCK"; + if (x == F_WRLCK) + return "F_WRLCK"; + if (x == F_UNLCK) + return "F_UNLCK"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describegidlist.c b/libc/intrin/describegidlist.c index 5c876ccd0..e6487986a 100644 --- a/libc/intrin/describegidlist.c +++ b/libc/intrin/describegidlist.c @@ -28,9 +28,12 @@ const char *(DescribeGidList)(char buf[N], int rc, int size, const uint32_t list[]) { - if ((rc == -1) || (size < 0)) return "n/a"; - if (!size) return "{}"; - if (!list) return "NULL"; + if ((rc == -1) || (size < 0)) + return "n/a"; + if (!size) + return "{}"; + if (!list) + return "NULL"; if ((!IsAsan() && kisdangerous(list)) || (IsAsan() && !__asan_is_valid(list, size * sizeof(list[0])))) { ksnprintf(buf, N, "%p", list); @@ -43,8 +46,10 @@ const char *(DescribeGidList)(char buf[N], int rc, int size, i += ksnprintf(buf + i, MAX(0, n - i), "%u, ", list[c]); } if (c == size) { - if (buf[i - 1] == ' ') i--; - if (buf[i - 1] == ',') i--; + if (buf[i - 1] == ' ') + i--; + if (buf[i - 1] == ',') + i--; i += ksnprintf(buf + i, MAX(0, n - i), "}"); } return buf; diff --git a/libc/intrin/describehow.c b/libc/intrin/describehow.c index ac898c27e..a4c447025 100644 --- a/libc/intrin/describehow.c +++ b/libc/intrin/describehow.c @@ -21,9 +21,12 @@ #include "libc/sysv/consts/sig.h" const char *(DescribeHow)(char buf[12], int how) { - if (how == SIG_BLOCK) return "SIG_BLOCK"; - if (how == SIG_UNBLOCK) return "SIG_UNBLOCK"; - if (how == SIG_SETMASK) return "SIG_SETMASK"; + if (how == SIG_BLOCK) + return "SIG_BLOCK"; + if (how == SIG_UNBLOCK) + return "SIG_UNBLOCK"; + if (how == SIG_SETMASK) + return "SIG_SETMASK"; FormatInt32(buf, how); return buf; } diff --git a/libc/intrin/describeinoutint64.c b/libc/intrin/describeinoutint64.c index c0c775669..977c32a15 100644 --- a/libc/intrin/describeinoutint64.c +++ b/libc/intrin/describeinoutint64.c @@ -21,9 +21,11 @@ #include "libc/intrin/describeflags.internal.h" const char *(DescribeInOutInt64)(char buf[23], ssize_t rc, int64_t *x) { - if (!x) return "NULL"; + if (!x) + return "NULL"; char *p = buf; - if (rc != -1) *p++ = '['; + if (rc != -1) + *p++ = '['; if (rc == -1 && errno == EFAULT) { *p++ = '!'; *p++ = '!'; @@ -31,7 +33,8 @@ const char *(DescribeInOutInt64)(char buf[23], ssize_t rc, int64_t *x) { } else { p = FormatInt64(p, *x); } - if (rc != -1) *p++ = ']'; + if (rc != -1) + *p++ = ']'; *p = 0; return buf; } diff --git a/libc/intrin/describeiovec.c b/libc/intrin/describeiovec.c index 5c2cdc036..c687f0d2f 100644 --- a/libc/intrin/describeiovec.c +++ b/libc/intrin/describeiovec.c @@ -33,9 +33,12 @@ const char *(DescribeIovec)(char buf[N], ssize_t rc, const struct iovec *iov, const char *d; int i, j, o = 0; - if (!iov) return "NULL"; - if (rc == -1) return "n/a"; - if (rc == -2) rc = SSIZE_MAX; + if (!iov) + return "NULL"; + if (rc == -1) + return "n/a"; + if (rc == -2) + rc = SSIZE_MAX; if ((!IsAsan() && kisdangerous(iov)) || (IsAsan() && !__asan_is_valid(iov, sizeof(*iov) * iovlen))) { ksnprintf(buf, N, "%p", iov); diff --git a/libc/intrin/describeitimer.c b/libc/intrin/describeitimer.c index 852c92a5c..d1e83a28d 100644 --- a/libc/intrin/describeitimer.c +++ b/libc/intrin/describeitimer.c @@ -21,9 +21,12 @@ #include "libc/sysv/consts/itimer.h" const char *(DescribeItimer)(char buf[12], int which) { - if (which == ITIMER_REAL) return "ITIMER_REAL"; - if (which == ITIMER_VIRTUAL) return "ITIMER_VIRTUAL"; - if (which == ITIMER_PROF) return "ITIMER_PROF"; + if (which == ITIMER_REAL) + return "ITIMER_REAL"; + if (which == ITIMER_VIRTUAL) + return "ITIMER_VIRTUAL"; + if (which == ITIMER_PROF) + return "ITIMER_PROF"; FormatInt32(buf, which); return buf; } diff --git a/libc/intrin/describeitimerval.c b/libc/intrin/describeitimerval.c index 04a9014f9..4088b4cf4 100644 --- a/libc/intrin/describeitimerval.c +++ b/libc/intrin/describeitimerval.c @@ -28,8 +28,10 @@ const char *(DescribeItimerval)(char buf[N], int rc, const struct itimerval *it) { - if (!it) return "NULL"; - if (rc == -1) return "n/a"; + if (!it) + return "NULL"; + if (rc == -1) + return "n/a"; if ((!IsAsan() && kisdangerous(it)) || (IsAsan() && !__asan_is_valid(it, sizeof(*it)))) { ksnprintf(buf, N, "%p", it); diff --git a/libc/intrin/describemagnums.c b/libc/intrin/describemagnums.c index 8570aaa73..fe76de780 100644 --- a/libc/intrin/describemagnums.c +++ b/libc/intrin/describemagnums.c @@ -23,7 +23,8 @@ const char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, int x) { const char *s; - if (x == 127) return "CLOCK_INVALID"; + if (x == 127) + return "CLOCK_INVALID"; if ((s = GetMagnumStr(m, x))) { stpcpy(stpcpy(b, p), s); return b; diff --git a/libc/intrin/describentfileflagattr.c b/libc/intrin/describentfileflagattr.c index 94a7aa52e..36762db5a 100644 --- a/libc/intrin/describentfileflagattr.c +++ b/libc/intrin/describentfileflagattr.c @@ -51,7 +51,8 @@ static const struct DescribeFlags kFileFlags[] = { }; const char *(DescribeNtFileFlagAttr)(char buf[256], uint32_t x) { - if (x == -1u) return "-1u"; + if (x == -1u) + return "-1u"; return DescribeFlags(buf, 256, kFileFlags, ARRAYLEN(kFileFlags), "kNtFile", x); } diff --git a/libc/intrin/describentoverlapped.c b/libc/intrin/describentoverlapped.c index 71c588891..a4f3e1e07 100644 --- a/libc/intrin/describentoverlapped.c +++ b/libc/intrin/describentoverlapped.c @@ -23,7 +23,8 @@ const char *(DescribeNtOverlapped)(char b[128], const struct NtOverlapped *o) { int i = 0, n = 128; bool gotsome = false; - if (!o) return "NULL"; + if (!o) + return "NULL"; i += ksnprintf(b + i, MAX(0, n - i), "{"); if (o->hEvent) { diff --git a/libc/intrin/describeopenflags.c b/libc/intrin/describeopenflags.c index 735964084..b57fc9219 100644 --- a/libc/intrin/describeopenflags.c +++ b/libc/intrin/describeopenflags.c @@ -35,7 +35,8 @@ const char *(DescribeOpenFlags)(char buf[128], int x) { int i, n; const char *pipe; struct DescribeFlags d[N]; - if (x == -1) return "-1"; + if (x == -1) + return "-1"; p = buf; switch (x & O_ACCMODE) { case O_RDONLY: @@ -60,7 +61,8 @@ const char *(DescribeOpenFlags)(char buf[128], int x) { if (x) { p = stpcpy(p, pipe); for (n = 0; kOpenFlags[n].x != MAGNUM_TERMINATOR; ++n) { - if (n == N) notpossible; + if (n == N) + notpossible; } for (i = 0; i < n; ++i) { d[i].flag = MAGNUM_NUMBER(kOpenFlags, i); diff --git a/libc/intrin/describepollfds.c b/libc/intrin/describepollfds.c index f0c49b7f8..92be225c7 100644 --- a/libc/intrin/describepollfds.c +++ b/libc/intrin/describepollfds.c @@ -34,7 +34,8 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds, char b64[64]; int i, o = 0; - if (!fds) return "NULL"; + if (!fds) + return "NULL"; if ((!IsAsan() && kisdangerous(fds)) || (IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) { ksnprintf(buf, N, "%p", fds); @@ -44,7 +45,8 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds, append("{"); for (i = 0; i < nfds; ++i) { - if (i) append(", "); + if (i) + append(", "); append("{%d, %s", fds[i].fd, (DescribePollFlags)(b64, fds[i].events)); if (rc >= 0) { append(", [%s]", (DescribePollFlags)(b64, fds[i].revents)); diff --git a/libc/intrin/describeptrace.c b/libc/intrin/describeptrace.c index 847a49f09..7b9969fce 100644 --- a/libc/intrin/describeptrace.c +++ b/libc/intrin/describeptrace.c @@ -21,38 +21,70 @@ #include "libc/sysv/consts/ptrace.h" const char *(DescribePtrace)(char buf[12], int x) { - if (x == -1) return "-1"; - if (x == PTRACE_TRACEME) return "PTRACE_TRACEME"; - if (x == PTRACE_PEEKDATA) return "PTRACE_PEEKDATA"; - if (x == PTRACE_GETFPREGS) return "PTRACE_GETFPREGS"; - if (x == PTRACE_PEEKTEXT) return "PTRACE_PEEKTEXT"; - if (x == PTRACE_POKEDATA) return "PTRACE_POKEDATA"; - if (x == PTRACE_PEEKUSER) return "PTRACE_PEEKUSER"; - if (x == PTRACE_POKETEXT) return "PTRACE_POKETEXT"; - if (x == PTRACE_POKEUSER) return "PTRACE_POKEUSER"; - if (x == PTRACE_GETREGS) return "PTRACE_GETREGS"; - if (x == PTRACE_GETREGSET) return "PTRACE_GETREGSET"; - if (x == PTRACE_SETFPREGS) return "PTRACE_SETFPREGS"; - if (x == PTRACE_SETREGS) return "PTRACE_SETREGS"; - if (x == PTRACE_SETREGSET) return "PTRACE_SETREGSET"; - if (x == PTRACE_GETSIGINFO) return "PTRACE_GETSIGINFO"; - if (x == PTRACE_SETSIGINFO) return "PTRACE_SETSIGINFO"; - if (x == PTRACE_PEEKSIGINFO) return "PTRACE_PEEKSIGINFO"; - if (x == PTRACE_GETSIGMASK) return "PTRACE_GETSIGMASK"; - if (x == PTRACE_SETSIGMASK) return "PTRACE_SETSIGMASK"; - if (x == PTRACE_SETOPTIONS) return "PTRACE_SETOPTIONS"; - if (x == PTRACE_GETEVENTMSG) return "PTRACE_GETEVENTMSG"; - if (x == PTRACE_CONT) return "PTRACE_CONT"; - if (x == PTRACE_SINGLESTEP) return "PTRACE_SINGLESTEP"; - if (x == PTRACE_SYSCALL) return "PTRACE_SYSCALL"; - if (x == PTRACE_LISTEN) return "PTRACE_LISTEN"; - if (x == PTRACE_KILL) return "PTRACE_KILL"; - if (x == PTRACE_INTERRUPT) return "PTRACE_INTERRUPT"; - if (x == PTRACE_ATTACH) return "PTRACE_ATTACH"; - if (x == PTRACE_SEIZE) return "PTRACE_SEIZE"; - if (x == PTRACE_SECCOMP_GET_FILTER) return "PTRACE_SECCOMP_GET_FILTER"; - if (x == PTRACE_SECCOMP_GET_METADATA) return "PTRACE_SECCOMP_GET_METADATA"; - if (x == PTRACE_DETACH) return "PTRACE_DETACH"; + if (x == -1) + return "-1"; + if (x == PTRACE_TRACEME) + return "PTRACE_TRACEME"; + if (x == PTRACE_PEEKDATA) + return "PTRACE_PEEKDATA"; + if (x == PTRACE_GETFPREGS) + return "PTRACE_GETFPREGS"; + if (x == PTRACE_PEEKTEXT) + return "PTRACE_PEEKTEXT"; + if (x == PTRACE_POKEDATA) + return "PTRACE_POKEDATA"; + if (x == PTRACE_PEEKUSER) + return "PTRACE_PEEKUSER"; + if (x == PTRACE_POKETEXT) + return "PTRACE_POKETEXT"; + if (x == PTRACE_POKEUSER) + return "PTRACE_POKEUSER"; + if (x == PTRACE_GETREGS) + return "PTRACE_GETREGS"; + if (x == PTRACE_GETREGSET) + return "PTRACE_GETREGSET"; + if (x == PTRACE_SETFPREGS) + return "PTRACE_SETFPREGS"; + if (x == PTRACE_SETREGS) + return "PTRACE_SETREGS"; + if (x == PTRACE_SETREGSET) + return "PTRACE_SETREGSET"; + if (x == PTRACE_GETSIGINFO) + return "PTRACE_GETSIGINFO"; + if (x == PTRACE_SETSIGINFO) + return "PTRACE_SETSIGINFO"; + if (x == PTRACE_PEEKSIGINFO) + return "PTRACE_PEEKSIGINFO"; + if (x == PTRACE_GETSIGMASK) + return "PTRACE_GETSIGMASK"; + if (x == PTRACE_SETSIGMASK) + return "PTRACE_SETSIGMASK"; + if (x == PTRACE_SETOPTIONS) + return "PTRACE_SETOPTIONS"; + if (x == PTRACE_GETEVENTMSG) + return "PTRACE_GETEVENTMSG"; + if (x == PTRACE_CONT) + return "PTRACE_CONT"; + if (x == PTRACE_SINGLESTEP) + return "PTRACE_SINGLESTEP"; + if (x == PTRACE_SYSCALL) + return "PTRACE_SYSCALL"; + if (x == PTRACE_LISTEN) + return "PTRACE_LISTEN"; + if (x == PTRACE_KILL) + return "PTRACE_KILL"; + if (x == PTRACE_INTERRUPT) + return "PTRACE_INTERRUPT"; + if (x == PTRACE_ATTACH) + return "PTRACE_ATTACH"; + if (x == PTRACE_SEIZE) + return "PTRACE_SEIZE"; + if (x == PTRACE_SECCOMP_GET_FILTER) + return "PTRACE_SECCOMP_GET_FILTER"; + if (x == PTRACE_SECCOMP_GET_METADATA) + return "PTRACE_SECCOMP_GET_METADATA"; + if (x == PTRACE_DETACH) + return "PTRACE_DETACH"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describeptraceevent.c b/libc/intrin/describeptraceevent.c index 2c724d3e0..f8e8e49ed 100644 --- a/libc/intrin/describeptraceevent.c +++ b/libc/intrin/describeptraceevent.c @@ -21,14 +21,22 @@ #include "libc/sysv/consts/ptrace.h" const char *(DescribePtraceEvent)(char buf[32], int x) { - if (x == PTRACE_EVENT_FORK) return "PTRACE_EVENT_FORK"; - if (x == PTRACE_EVENT_VFORK) return "PTRACE_EVENT_VFORK"; - if (x == PTRACE_EVENT_CLONE) return "PTRACE_EVENT_CLONE"; - if (x == PTRACE_EVENT_EXEC) return "PTRACE_EVENT_EXEC"; - if (x == PTRACE_EVENT_VFORK_DONE) return "PTRACE_EVENT_VFORK_DONE"; - if (x == PTRACE_EVENT_EXIT) return "PTRACE_EVENT_EXIT"; - if (x == PTRACE_EVENT_SECCOMP) return "PTRACE_EVENT_SECCOMP"; - if (x == PTRACE_EVENT_STOP) return "PTRACE_EVENT_STOP"; + if (x == PTRACE_EVENT_FORK) + return "PTRACE_EVENT_FORK"; + if (x == PTRACE_EVENT_VFORK) + return "PTRACE_EVENT_VFORK"; + if (x == PTRACE_EVENT_CLONE) + return "PTRACE_EVENT_CLONE"; + if (x == PTRACE_EVENT_EXEC) + return "PTRACE_EVENT_EXEC"; + if (x == PTRACE_EVENT_VFORK_DONE) + return "PTRACE_EVENT_VFORK_DONE"; + if (x == PTRACE_EVENT_EXIT) + return "PTRACE_EVENT_EXIT"; + if (x == PTRACE_EVENT_SECCOMP) + return "PTRACE_EVENT_SECCOMP"; + if (x == PTRACE_EVENT_STOP) + return "PTRACE_EVENT_STOP"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describerlimit.c b/libc/intrin/describerlimit.c index 6e9568c81..ebc85feec 100644 --- a/libc/intrin/describerlimit.c +++ b/libc/intrin/describerlimit.c @@ -23,8 +23,10 @@ #include "libc/intrin/strace.internal.h" const char *DescribeRlimit(char buf[64], int rc, const struct rlimit *rlim) { - if (rc == -1) return "n/a"; - if (!rlim) return "NULL"; + if (rc == -1) + return "n/a"; + if (!rlim) + return "NULL"; if ((!IsAsan() && kisdangerous(rlim)) || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) { ksnprintf(buf, 64, "%p", rlim); diff --git a/libc/intrin/describerlimitname.c b/libc/intrin/describerlimitname.c index 7e329fb10..d7b578853 100644 --- a/libc/intrin/describerlimitname.c +++ b/libc/intrin/describerlimitname.c @@ -23,6 +23,7 @@ * Describes setrlimit() / getrlimit() argument. */ const char *(DescribeRlimitName)(char buf[20], int x) { - if (x == 127) return "n/a"; + if (x == 127) + return "n/a"; return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x); } diff --git a/libc/intrin/describeschedparam.c b/libc/intrin/describeschedparam.c index b68c74fa1..059d66088 100644 --- a/libc/intrin/describeschedparam.c +++ b/libc/intrin/describeschedparam.c @@ -26,7 +26,8 @@ */ const char *(DescribeSchedParam)(char buf[32], const struct sched_param *x) { char *p; - if (!x) return "0"; + if (!x) + return "0"; p = buf; *p++ = '{'; p = FormatInt32(p, x->sched_priority); diff --git a/libc/intrin/describesigaction.c b/libc/intrin/describesigaction.c index 01cddac03..4138457b4 100644 --- a/libc/intrin/describesigaction.c +++ b/libc/intrin/describesigaction.c @@ -28,9 +28,12 @@ #include "libc/sysv/consts/sa.h" static const char *DescribeSigHandler(char buf[64], void f(int)) { - if (f == SIG_ERR) return "SIG_ERR"; - if (f == SIG_DFL) return "SIG_DFL"; - if (f == SIG_IGN) return "SIG_IGN"; + if (f == SIG_ERR) + return "SIG_ERR"; + if (f == SIG_DFL) + return "SIG_DFL"; + if (f == SIG_IGN) + return "SIG_IGN"; ksnprintf(buf, 64, "%t", f); return buf; } @@ -60,8 +63,10 @@ const char *(DescribeSigaction)(char buf[N], int rc, int o = 0; char b64[64]; - if (rc == -1) return "n/a"; - if (!sa) return "NULL"; + if (rc == -1) + return "n/a"; + if (!sa) + return "NULL"; if ((!IsAsan() && kisdangerous(sa)) || (IsAsan() && !__asan_is_valid(sa, sizeof(*sa)))) { ksnprintf(buf, N, "%p", sa); diff --git a/libc/intrin/describesigaltstack.c b/libc/intrin/describesigaltstack.c index d137b2406..16d7f811e 100644 --- a/libc/intrin/describesigaltstack.c +++ b/libc/intrin/describesigaltstack.c @@ -24,8 +24,10 @@ const char *(DescribeSigaltstk)(char buf[128], int rc, const struct sigaltstack *ss) { - if (rc == -1) return "n/a"; - if (!ss) return "NULL"; + if (rc == -1) + return "n/a"; + if (!ss) + return "NULL"; if ((!IsAsan() && kisdangerous(ss)) || (IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) { ksnprintf(buf, 128, "%p", ss); diff --git a/libc/intrin/describesiginfo.c b/libc/intrin/describesiginfo.c index c16cdb3c3..9a3b4c1e0 100644 --- a/libc/intrin/describesiginfo.c +++ b/libc/intrin/describesiginfo.c @@ -33,8 +33,10 @@ const char *(DescribeSiginfo)(char buf[N], int rc, const siginfo_t *si) { int i = 0; - if (rc == -1) return "n/a"; - if (!si) return "NULL"; + if (rc == -1) + return "n/a"; + if (!si) + return "NULL"; if ((!IsAsan() && kisdangerous(si)) || (IsAsan() && !__asan_is_valid(si, sizeof(*si)))) { ksnprintf(buf, N, "%p", si); diff --git a/libc/intrin/describesigset.c b/libc/intrin/describesigset.c index 727217f8a..97822e50c 100644 --- a/libc/intrin/describesigset.c +++ b/libc/intrin/describesigset.c @@ -39,8 +39,10 @@ const char *(DescribeSigset)(char buf[N], int rc, const sigset_t *ss) { int sig, o = 0; sigset_t sigset; - if (rc == -1) return "n/a"; - if (!ss) return "NULL"; + if (rc == -1) + return "n/a"; + if (!ss) + return "NULL"; if ((!IsAsan() && kisdangerous(ss)) || (IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) { ksnprintf(buf, N, "%p", ss); diff --git a/libc/intrin/describesocketfamily.c b/libc/intrin/describesocketfamily.c index fa5f23ce6..7f1b32ade 100644 --- a/libc/intrin/describesocketfamily.c +++ b/libc/intrin/describesocketfamily.c @@ -21,9 +21,12 @@ #include "libc/sysv/consts/af.h" const char *(DescribeSocketFamily)(char buf[12], int family) { - if (family == AF_UNIX) return "AF_UNIX"; - if (family == AF_INET) return "AF_INET"; - if (family == AF_INET6) return "AF_INET6"; + if (family == AF_UNIX) + return "AF_UNIX"; + if (family == AF_INET) + return "AF_INET"; + if (family == AF_INET6) + return "AF_INET6"; FormatInt32(buf, family); return buf; } diff --git a/libc/intrin/describesocketprotocol.c b/libc/intrin/describesocketprotocol.c index ee4466302..933ce7b41 100644 --- a/libc/intrin/describesocketprotocol.c +++ b/libc/intrin/describesocketprotocol.c @@ -21,13 +21,20 @@ #include "libc/sysv/consts/ipproto.h" const char *(DescribeSocketProtocol)(char buf[12], int family) { - if (family == IPPROTO_IP) return "IPPROTO_IP"; - if (family == IPPROTO_ICMP) return "IPPROTO_ICMP"; - if (family == IPPROTO_TCP) return "IPPROTO_TCP"; - if (family == IPPROTO_UDP) return "IPPROTO_UDP"; - if (family == IPPROTO_RAW) return "IPPROTO_RAW"; - if (family == IPPROTO_IPV6) return "IPPROTO_IPv6"; - if (family == IPPROTO_ICMPV6) return "IPPROTO_ICMPV6"; + if (family == IPPROTO_IP) + return "IPPROTO_IP"; + if (family == IPPROTO_ICMP) + return "IPPROTO_ICMP"; + if (family == IPPROTO_TCP) + return "IPPROTO_TCP"; + if (family == IPPROTO_UDP) + return "IPPROTO_UDP"; + if (family == IPPROTO_RAW) + return "IPPROTO_RAW"; + if (family == IPPROTO_IPV6) + return "IPPROTO_IPv6"; + if (family == IPPROTO_ICMPV6) + return "IPPROTO_ICMPV6"; FormatInt32(buf, family); return buf; } diff --git a/libc/intrin/describesockettype.c b/libc/intrin/describesockettype.c index 34ba12d8a..69cf9d76e 100644 --- a/libc/intrin/describesockettype.c +++ b/libc/intrin/describesockettype.c @@ -39,7 +39,9 @@ const char *(DescribeSocketType)(char buf[64], int type) { } else { p = FormatInt32(p, x); } - if (type & SOCK_CLOEXEC) p = stpcpy(p, "|SOCK_CLOEXEC"); - if (type & SOCK_NONBLOCK) p = stpcpy(p, "|SOCK_NONBLOCK"); + if (type & SOCK_CLOEXEC) + p = stpcpy(p, "|SOCK_CLOEXEC"); + if (type & SOCK_NONBLOCK) + p = stpcpy(p, "|SOCK_NONBLOCK"); return buf; } diff --git a/libc/intrin/describesocklevel.c b/libc/intrin/describesocklevel.c index 536ce3015..dc1959ee1 100644 --- a/libc/intrin/describesocklevel.c +++ b/libc/intrin/describesocklevel.c @@ -24,14 +24,22 @@ * Describes setsockopt() level arguments. */ const char *(DescribeSockLevel)(char buf[12], int x) { - if (x == SOL_SOCKET) return "SOL_SOCKET"; - if (x == SOL_IP) return "SOL_IP"; - if (x == SOL_ICMP) return "SOL_ICMP"; - if (x == SOL_TCP) return "SOL_TCP"; - if (x == SOL_UDP) return "SOL_UDP"; - if (x == SOL_IPV6) return "SOL_IPV6"; - if (x == SOL_ICMPV6) return "SOL_ICMPV6"; - if (x == SOL_RAW) return "SOL_RAW"; + if (x == SOL_SOCKET) + return "SOL_SOCKET"; + if (x == SOL_IP) + return "SOL_IP"; + if (x == SOL_ICMP) + return "SOL_ICMP"; + if (x == SOL_TCP) + return "SOL_TCP"; + if (x == SOL_UDP) + return "SOL_UDP"; + if (x == SOL_IPV6) + return "SOL_IPV6"; + if (x == SOL_ICMPV6) + return "SOL_ICMPV6"; + if (x == SOL_RAW) + return "SOL_RAW"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describestat.c b/libc/intrin/describestat.c index 463373f3f..6c8d9dee4 100644 --- a/libc/intrin/describestat.c +++ b/libc/intrin/describestat.c @@ -29,8 +29,10 @@ const char *(DescribeStat)(char buf[N], int rc, const struct stat *st) { int o = 0; - if (rc == -1) return "n/a"; - if (!st) return "NULL"; + if (rc == -1) + return "n/a"; + if (!st) + return "NULL"; if ((!IsAsan() && kisdangerous(st)) || (IsAsan() && !__asan_is_valid(st, sizeof(*st)))) { ksnprintf(buf, N, "%p", st); diff --git a/libc/intrin/describestatfs.c b/libc/intrin/describestatfs.c index ea2ea12cb..0932b6c76 100644 --- a/libc/intrin/describestatfs.c +++ b/libc/intrin/describestatfs.c @@ -33,8 +33,10 @@ const char *(DescribeStatfs)(char buf[N], int rc, const struct statfs *f) { char ibuf[21]; int64_t flags; - if (rc == -1) return "n/a"; - if (!f) return "NULL"; + if (rc == -1) + return "n/a"; + if (!f) + return "NULL"; if ((!IsAsan() && kisdangerous(f)) || (IsAsan() && !__asan_is_valid(f, sizeof(*f)))) { ksnprintf(buf, N, "%p", f); diff --git a/libc/intrin/describestdiostate.c b/libc/intrin/describestdiostate.c index 81cbc8a8c..74a934cdc 100644 --- a/libc/intrin/describestdiostate.c +++ b/libc/intrin/describestdiostate.c @@ -22,9 +22,12 @@ #include "libc/str/str.h" const char *(DescribeStdioState)(char buf[12], int x) { - if (!x) return ""; - if (x == -1) return "EOF"; - if (x > 0) return _strerrno(x); + if (!x) + return ""; + if (x == -1) + return "EOF"; + if (x > 0) + return _strerrno(x); FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describestringlist.c b/libc/intrin/describestringlist.c index 75593f258..8f1594210 100644 --- a/libc/intrin/describestringlist.c +++ b/libc/intrin/describestringlist.c @@ -28,7 +28,8 @@ const char *(DescribeStringList)(char buf[N], char *const list[]) { int i, o = 0; - if (!list) return "NULL"; + if (!list) + return "NULL"; if (IsAsan() && !__asan_is_valid_strlist(list)) { ksnprintf(buf, N, "%p", list); return buf; @@ -37,7 +38,8 @@ const char *(DescribeStringList)(char buf[N], char *const list[]) { append("{"); i = 0; do { - if (i++) append(", "); + if (i++) + append(", "); append("%#s", *list); } while (*list++); append("}"); diff --git a/libc/intrin/describetermios.c b/libc/intrin/describetermios.c index 87d1ca2bf..8c0614f1b 100644 --- a/libc/intrin/describetermios.c +++ b/libc/intrin/describetermios.c @@ -35,7 +35,8 @@ const char *(DescribeTermios)(char buf[N], ssize_t rc, int o = 0; char b128[128]; - if (!tio) return "NULL"; + if (!tio) + return "NULL"; if ((!IsAsan() && kisdangerous(tio)) || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) { ksnprintf(buf, N, "%p", tio); diff --git a/libc/intrin/describetimespec.c b/libc/intrin/describetimespec.c index b3cf5db63..d5cc954ff 100644 --- a/libc/intrin/describetimespec.c +++ b/libc/intrin/describetimespec.c @@ -25,8 +25,10 @@ const char *(DescribeTimespec)(char buf[45], int rc, const struct timespec *ts) { - if (rc == -1) return "n/a"; - if (!ts) return "NULL"; + if (rc == -1) + return "n/a"; + if (!ts) + return "NULL"; if ((!IsAsan() && kisdangerous(ts)) || (IsAsan() && !__asan_is_valid(ts, sizeof(*ts)))) { ksnprintf(buf, 45, "%p", ts); diff --git a/libc/intrin/describetimeval.c b/libc/intrin/describetimeval.c index dc42e4f0f..4e504aaa8 100644 --- a/libc/intrin/describetimeval.c +++ b/libc/intrin/describetimeval.c @@ -23,8 +23,10 @@ #include "libc/intrin/kprintf.h" const char *(DescribeTimeval)(char buf[45], int rc, const struct timeval *tv) { - if (!tv) return "NULL"; - if (rc == -1) return "n/a"; + if (!tv) + return "NULL"; + if (rc == -1) + return "n/a"; if ((!IsAsan() && kisdangerous(tv)) || (IsAsan() && !__asan_is_valid(tv, sizeof(*tv)))) { ksnprintf(buf, 45, "%p", tv); diff --git a/libc/intrin/describewhence.c b/libc/intrin/describewhence.c index ceccb4a69..3de47df18 100644 --- a/libc/intrin/describewhence.c +++ b/libc/intrin/describewhence.c @@ -21,9 +21,12 @@ #include "libc/intrin/describeflags.internal.h" const char *(DescribeWhence)(char buf[12], int whence) { - if (whence == SEEK_SET) return "SEEK_SET"; - if (whence == SEEK_CUR) return "SEEK_CUR"; - if (whence == SEEK_END) return "SEEK_END"; + if (whence == SEEK_SET) + return "SEEK_SET"; + if (whence == SEEK_CUR) + return "SEEK_CUR"; + if (whence == SEEK_END) + return "SEEK_END"; FormatInt32(buf, whence); return buf; } diff --git a/libc/intrin/describewhichprio.c b/libc/intrin/describewhichprio.c index c49cee09c..3459dc17e 100644 --- a/libc/intrin/describewhichprio.c +++ b/libc/intrin/describewhichprio.c @@ -21,9 +21,12 @@ #include "libc/sysv/consts/prio.h" const char *(DescribeWhichPrio)(char buf[12], int x) { - if (x == PRIO_PROCESS) return "PRIO_PROCESS"; - if (x == PRIO_PGRP) return "PRIO_PGRP"; - if (x == PRIO_USER) return "PRIO_USER"; + if (x == PRIO_PROCESS) + return "PRIO_PROCESS"; + if (x == PRIO_PGRP) + return "PRIO_PGRP"; + if (x == PRIO_USER) + return "PRIO_USER"; FormatInt32(buf, x); return buf; } diff --git a/libc/intrin/describewinsize.c b/libc/intrin/describewinsize.c index b544065f4..61208a7b5 100644 --- a/libc/intrin/describewinsize.c +++ b/libc/intrin/describewinsize.c @@ -31,8 +31,10 @@ const char *(DescribeWinsize)(char buf[N], int rc, const struct winsize *ws) { int o = 0; - if (!ws) return "NULL"; - if (rc == -1) return "n/a"; + if (!ws) + return "NULL"; + if (rc == -1) + return "n/a"; if ((!IsAsan() && kisdangerous(ws)) || (IsAsan() && !__asan_is_valid(ws, sizeof(*ws)))) { ksnprintf(buf, N, "%p", ws); diff --git a/libc/intrin/deviceiocontrol.c b/libc/intrin/deviceiocontrol.c index ee1977950..bd164fe29 100644 --- a/libc/intrin/deviceiocontrol.c +++ b/libc/intrin/deviceiocontrol.c @@ -40,7 +40,8 @@ textwindows bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode, ok = __imp_DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("DeviceIoControl(%ld, %#x, %p, %'zu, %p, %'zu, %p, %s) → %hhhd% m", hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, DescribeNtOverlapped(lpOverlapped), diff --git a/libc/intrin/directmap-metal.c b/libc/intrin/directmap-metal.c index cc0279677..af0e1889c 100644 --- a/libc/intrin/directmap-metal.c +++ b/libc/intrin/directmap-metal.c @@ -53,15 +53,19 @@ struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot, int flags, if (!(flags & MAP_ANONYMOUS_linux)) { struct Fd *sfd; struct MetalFile *file; - if (off < 0 || fd < 0 || fd >= g_fds.n) return bad_mmap(); + if (off < 0 || fd < 0 || fd >= g_fds.n) + return bad_mmap(); sfd = &g_fds.p[fd]; - if (sfd->kind != kFdFile) return bad_mmap(); + if (sfd->kind != kFdFile) + return bad_mmap(); file = (struct MetalFile *)sfd->handle; /* TODO: allow mapping partial page at end of file, if file size not * multiple of page size */ - if (off > file->size || size > file->size - off) return bad_mmap(); + if (off > file->size || size > file->size - off) + return bad_mmap(); faddr = (uint64_t)file->base + off; - if (faddr % 4096 != 0) return bad_mmap(); + if (faddr % 4096 != 0) + return bad_mmap(); } if (!(flags & MAP_FIXED_linux)) { if (!addr) { @@ -83,20 +87,24 @@ struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot, int flags, if (pte) { if ((flags & MAP_ANONYMOUS_linux)) { page = __new_page(mm); - if (!page) return bad_mmap(); + if (!page) + return bad_mmap(); __clear_page(BANE + page); e = page | PAGE_RSRV | PAGE_U; if ((prot & PROT_WRITE)) e |= PAGE_V | PAGE_RW; else if ((prot & (PROT_READ | PROT_EXEC))) e |= PAGE_V; - if (!(prot & PROT_EXEC)) e |= PAGE_XD; + if (!(prot & PROT_EXEC)) + e |= PAGE_XD; } else { fdpte = __get_virtual(mm, pml4t, faddr + i, false); e = *fdpte | PAGE_RSRV | PAGE_U; page = e & PAGE_TA; - if (!(prot & PROT_WRITE)) e &= ~PAGE_RW; - if (!(prot & PROT_EXEC)) e |= PAGE_XD; + if (!(prot & PROT_WRITE)) + e &= ~PAGE_RW; + if (!(prot & PROT_EXEC)) + e |= PAGE_XD; } __ref_page(mm, pml4t, page); *pte = e; diff --git a/libc/intrin/divmodti4.c b/libc/intrin/divmodti4.c index 465555c27..f47dc1f13 100644 --- a/libc/intrin/divmodti4.c +++ b/libc/intrin/divmodti4.c @@ -36,7 +36,8 @@ ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) { q = __udivmodti4(x, y, &r); // unsigned divide q = (tu_int)(q ^ sq) - sq; // fix quotient sign r = (tu_int)(r ^ sr) - sr; // fix remainder sign - if (opt_out_rem) *opt_out_rem = r; + if (opt_out_rem) + *opt_out_rem = r; return q; } diff --git a/libc/intrin/exit.c b/libc/intrin/exit.c index 50f1a00d9..8d1a92f6c 100644 --- a/libc/intrin/exit.c +++ b/libc/intrin/exit.c @@ -109,7 +109,8 @@ wontreturn void _Exit(int exitcode) { "push\t$0\n\t" "cli\n\t" "lidt\t(%rsp)"); - for (;;) asm("ud2"); + for (;;) + asm("ud2"); #else __builtin_unreachable(); #endif diff --git a/libc/intrin/extend.c b/libc/intrin/extend.c index 0c0629899..d458b483f 100644 --- a/libc/intrin/extend.c +++ b/libc/intrin/extend.c @@ -85,19 +85,24 @@ static void *_mapframe(void *p, int f) { void *_extend(void *p, size_t n, void *e, int f, intptr_t h) { char *q; #ifndef NDEBUG - if ((uintptr_t)SHADOW(p) & (G - 1)) notpossible; - if ((uintptr_t)p + (G << kAsanScale) > h) notpossible; + if ((uintptr_t)SHADOW(p) & (G - 1)) + notpossible; + if ((uintptr_t)p + (G << kAsanScale) > h) + notpossible; #endif // TODO(jart): Make this spin less in non-ASAN mode. for (q = e; q < ((char *)p + n); q += 8) { if (!((uintptr_t)q & (G - 1))) { #ifndef NDEBUG - if (q + G > (char *)h) notpossible; + if (q + G > (char *)h) + notpossible; #endif - if (!_mapframe(q, f)) return 0; + if (!_mapframe(q, f)) + return 0; if (IsAsan()) { if (!((uintptr_t)SHADOW(q) & (G - 1))) { - if (!_mapframe(SHADOW(q), f)) return 0; + if (!_mapframe(SHADOW(q), f)) + return 0; __asan_poison(q, G << kAsanScale, kAsanProtected); } } diff --git a/libc/intrin/findclose.c b/libc/intrin/findclose.c index eda3f747d..eccb3dff0 100644 --- a/libc/intrin/findclose.c +++ b/libc/intrin/findclose.c @@ -30,7 +30,8 @@ __msabi extern typeof(FindClose) *const __imp_FindClose; textwindows bool32 FindClose(int64_t hFindFile) { bool32 ok; ok = __imp_FindClose(hFindFile); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("FindClose(%ld) → %hhhd% m", hFindFile, ok); return ok; } diff --git a/libc/intrin/findnextfile.c b/libc/intrin/findnextfile.c index 6769ab809..5bb42cc87 100644 --- a/libc/intrin/findnextfile.c +++ b/libc/intrin/findnextfile.c @@ -46,7 +46,8 @@ textwindows bool32 FindNextFile(int64_t hFindFile, DescribeNtFileFlagAttr(out_lpFindFileData->dwFileAttributes), DescribeNtFiletypeFlags(out_lpFindFileData->dwFileType), ok); } else { - if (GetLastError() != kNtErrorNoMoreFiles) __winerr(); + if (GetLastError() != kNtErrorNoMoreFiles) + __winerr(); NTTRACE("FindNextFile(%ld) → %hhhd% m", hFindFile, ok); } return ok; diff --git a/libc/intrin/flushviewoffile.c b/libc/intrin/flushviewoffile.c index 90e0bfd19..049a9c0e1 100644 --- a/libc/intrin/flushviewoffile.c +++ b/libc/intrin/flushviewoffile.c @@ -36,7 +36,8 @@ textwindows bool32 FlushViewOfFile(const void *lpBaseAddress, size_t dwNumberOfBytesToFlush) { bool32 ok; ok = __imp_FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("FlushViewOfFile(%p, %'zu) → %hhhd% m", lpBaseAddress, dwNumberOfBytesToFlush, ok); return ok; diff --git a/libc/intrin/fmax.c b/libc/intrin/fmax.c index 310b8de95..44b9f69f3 100644 --- a/libc/intrin/fmax.c +++ b/libc/intrin/fmax.c @@ -26,8 +26,10 @@ * signed zeroes. */ double fmax(double x, double y) { - if (isnan(x)) return y; - if (isnan(y)) return x; + if (isnan(x)) + return y; + if (isnan(y)) + return x; if (signbit(x) != signbit(y)) { return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */ } diff --git a/libc/intrin/fmaxf.c b/libc/intrin/fmaxf.c index 6949ea6b0..f77be8dfb 100644 --- a/libc/intrin/fmaxf.c +++ b/libc/intrin/fmaxf.c @@ -26,8 +26,10 @@ * signed zeroes. */ float fmaxf(float x, float y) { - if (isnan(x)) return y; - if (isnan(y)) return x; + if (isnan(x)) + return y; + if (isnan(y)) + return x; if (signbit(x) != signbit(y)) { return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */ } diff --git a/libc/intrin/fmaxl.c b/libc/intrin/fmaxl.c index dbd15b27d..607d8024b 100644 --- a/libc/intrin/fmaxl.c +++ b/libc/intrin/fmaxl.c @@ -27,8 +27,10 @@ * signed zeroes. */ long double fmaxl(long double x, long double y) { - if (isnan(x)) return y; - if (isnan(y)) return x; + if (isnan(x)) + return y; + if (isnan(y)) + return x; if (signbit(x) != signbit(y)) { return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */ } diff --git a/libc/intrin/formathex64.c b/libc/intrin/formathex64.c index 1324662d7..33ba78f8e 100644 --- a/libc/intrin/formathex64.c +++ b/libc/intrin/formathex64.c @@ -23,10 +23,12 @@ static inline int PickGoodWidth(unsigned x, char z) { if (z) { if (x < 16) { - if (x < 8) return 8; + if (x < 8) + return 8; return 16; } else { - if (x < 32) return 32; + if (x < 32) + return 32; return 64; } } else { diff --git a/libc/intrin/formatint32.c b/libc/intrin/formatint32.c index c5bc93b38..330de4818 100644 --- a/libc/intrin/formatint32.c +++ b/libc/intrin/formatint32.c @@ -50,6 +50,7 @@ dontinline char *FormatUint32(char p[hasatleast 12], uint32_t x) { * @return pointer to nul byte */ char *FormatInt32(char p[hasatleast 12], int32_t x) { - if (x < 0) *p++ = '-', x = -(uint32_t)x; + if (x < 0) + *p++ = '-', x = -(uint32_t)x; return FormatUint32(p, x); } diff --git a/libc/intrin/formatint64.c b/libc/intrin/formatint64.c index cc9d44849..7791b5406 100644 --- a/libc/intrin/formatint64.c +++ b/libc/intrin/formatint64.c @@ -50,6 +50,7 @@ dontinline char *FormatUint64(char p[static 21], uint64_t x) { * @return pointer to nul byte */ char *FormatInt64(char p[static 21], int64_t x) { - if (x < 0) *p++ = '-', x = -(uint64_t)x; + if (x < 0) + *p++ = '-', x = -(uint64_t)x; return FormatUint64(p, x); } diff --git a/libc/intrin/formatoctal32.c b/libc/intrin/formatoctal32.c index 8f4c6034b..967105a3d 100644 --- a/libc/intrin/formatoctal32.c +++ b/libc/intrin/formatoctal32.c @@ -34,7 +34,8 @@ char *FormatOctal32(char p[hasatleast 13], uint32_t x, bool32 z) { p[i++] = x % 8 + '0'; x = x / 8; } while (x > 0); - if (z) p[i++] = '0'; + if (z) + p[i++] = '0'; p[i] = '\0'; if (i) { for (a = 0, b = i - 1; a < b; ++a, --b) { diff --git a/libc/intrin/g_fds.c b/libc/intrin/g_fds.c index 3e12da55f..b9f54a491 100644 --- a/libc/intrin/g_fds.c +++ b/libc/intrin/g_fds.c @@ -71,7 +71,8 @@ static textwindows void SetupWinStd(struct Fds *fds, int i, uint32_t x) { int64_t h; uint32_t cm; h = GetStdHandle(x); - if (!h || h == -1) return; + if (!h || h == -1) + return; fds->p[i].kind = GetConsoleMode(h, &cm) ? kFdConsole : kFdFile; fds->p[i].handle = h; atomic_store_explicit(&fds->f, i + 1, memory_order_relaxed); @@ -124,15 +125,24 @@ textstartup void __init_fds(int argc, char **argv, char **envp) { unsetenv("_COSMO_FDS"); for (;;) { long fd, kind, flags, mode, handle, pointer, type, family, protocol; - if (!TokAtoi(&fdspec, &fd)) break; - if (!TokAtoi(&fdspec, &handle)) break; - if (!TokAtoi(&fdspec, &kind)) break; - if (!TokAtoi(&fdspec, &flags)) break; - if (!TokAtoi(&fdspec, &mode)) break; - if (!TokAtoi(&fdspec, &pointer)) break; - if (!TokAtoi(&fdspec, &type)) break; - if (!TokAtoi(&fdspec, &family)) break; - if (!TokAtoi(&fdspec, &protocol)) break; + if (!TokAtoi(&fdspec, &fd)) + break; + if (!TokAtoi(&fdspec, &handle)) + break; + if (!TokAtoi(&fdspec, &kind)) + break; + if (!TokAtoi(&fdspec, &flags)) + break; + if (!TokAtoi(&fdspec, &mode)) + break; + if (!TokAtoi(&fdspec, &pointer)) + break; + if (!TokAtoi(&fdspec, &type)) + break; + if (!TokAtoi(&fdspec, &family)) + break; + if (!TokAtoi(&fdspec, &protocol)) + break; __ensurefds_unlocked(fd); struct Fd *f = fds->p + fd; if (f->handle && f->handle != -1 && f->handle != handle) { diff --git a/libc/intrin/generateconsolectrlevent.c b/libc/intrin/generateconsolectrlevent.c index a84f1d918..a9b24dd0e 100644 --- a/libc/intrin/generateconsolectrlevent.c +++ b/libc/intrin/generateconsolectrlevent.c @@ -34,7 +34,8 @@ textwindows bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent, uint32_t dwProcessGroupId) { bool32 ok; ok = __imp_GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("GenerateConsoleCtrlEvent(%x, %d) → %hhhd% m", dwCtrlEvent, dwProcessGroupId, ok); return ok; diff --git a/libc/intrin/getenv.c b/libc/intrin/getenv.c index 3a8fe75d2..e272d3ed1 100644 --- a/libc/intrin/getenv.c +++ b/libc/intrin/getenv.c @@ -31,7 +31,8 @@ char *getenv(const char *s) { char **p; struct Env e; - if (!(p = environ)) return 0; + if (!(p = environ)) + return 0; e = __getenv(p, s); #if SYSDEBUG // if (!(s[0] == 'T' && s[1] == 'Z' && !s[2])) { diff --git a/libc/intrin/getexitcodeprocess.c b/libc/intrin/getexitcodeprocess.c index b1fb13b49..8f359803a 100644 --- a/libc/intrin/getexitcodeprocess.c +++ b/libc/intrin/getexitcodeprocess.c @@ -30,7 +30,8 @@ __msabi extern typeof(GetExitCodeProcess) *const __imp_GetExitCodeProcess; textwindows int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode) { int32_t rc; rc = __imp_GetExitCodeProcess(hProcess, lpExitCode); - if (!rc) __winerr(); + if (!rc) + __winerr(); NTTRACE("GetExitCodeProcess(%ld, [%u]) → %u% m", hProcess, *lpExitCode, rc); return rc; } diff --git a/libc/intrin/getmainstack.c b/libc/intrin/getmainstack.c index 1a51d5f36..d1cade8a3 100644 --- a/libc/intrin/getmainstack.c +++ b/libc/intrin/getmainstack.c @@ -71,7 +71,8 @@ static char *__get_last(char **list) { static int __get_length(const char *s) { int n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; } @@ -82,7 +83,8 @@ static uintptr_t __get_main_top(int pagesz) { top = (uintptr_t)s + __get_length(s); } else { unsigned long *xp = __auxv; - while (*xp) xp += 2; + while (*xp) + xp += 2; top = (uintptr_t)xp; } return ROUNDUP(top, pagesz); @@ -92,7 +94,8 @@ static size_t __get_stack_size(int pagesz, uintptr_t start, uintptr_t top) { size_t size, max = 8 * 1024 * 1024; struct rlimit rlim = {RLIM_INFINITY}; sys_getrlimit(RLIMIT_STACK, &rlim); - if ((size = rlim.rlim_cur) > max) size = max; + if ((size = rlim.rlim_cur) > max) + size = max; return MAX(ROUNDUP(size, pagesz), ROUNDUP(top - start, pagesz)); } diff --git a/libc/intrin/getsafesize.greg.c b/libc/intrin/getsafesize.greg.c index 0148889a7..91e93d8d5 100644 --- a/libc/intrin/getsafesize.greg.c +++ b/libc/intrin/getsafesize.greg.c @@ -33,7 +33,8 @@ * allocation would likely cause a stack overflow */ privileged long __get_safe_size(long want, long extraspace) { - if (!__tls_enabled) return want; + if (!__tls_enabled) + return want; struct PosixThread *pt; struct CosmoTib *tib = __get_tls_privileged(); if (!IsAutoFrame((uintptr_t)tib >> 16) && @@ -52,6 +53,7 @@ privileged long __get_safe_size(long want, long extraspace) { return want; } long size = sp - bottom - extraspace; - if (size > want) size = want; + if (size > want) + size = want; return size; } diff --git a/libc/intrin/isdebuggerpresent.c b/libc/intrin/isdebuggerpresent.c index e682cc298..60fa89826 100644 --- a/libc/intrin/isdebuggerpresent.c +++ b/libc/intrin/isdebuggerpresent.c @@ -49,11 +49,16 @@ bool32 IsDebuggerPresent(bool32 force) { ssize_t got; int e, fd, res; char *p, buf[1024]; - if (!force && IsGenuineBlink()) return 0; - if (!force && environ && __getenv(environ, "HEISENDEBUG").s) return 0; - if (IsWindows()) return IsBeingDebugged(); - if (__isworker) return false; - if (!PLEDGED(RPATH)) return false; + if (!force && IsGenuineBlink()) + return 0; + if (!force && environ && __getenv(environ, "HEISENDEBUG").s) + return 0; + if (IsWindows()) + return IsBeingDebugged(); + if (__isworker) + return false; + if (!PLEDGED(RPATH)) + return false; res = 0; e = errno; BLOCK_CANCELATION; diff --git a/libc/intrin/iswsl.c b/libc/intrin/iswsl.c index f3d60431a..9bc77ac60 100644 --- a/libc/intrin/iswsl.c +++ b/libc/intrin/iswsl.c @@ -35,8 +35,10 @@ */ bool __iswsl1(void) { static char res; - if (res) return res & 1; - if (!IsLinux()) return res = 2, false; + if (res) + return res & 1; + if (!IsLinux()) + return res = 2, false; int e = errno; unassert(__sys_mmap((void *)1, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | ANONYMOUS | GROWSDOWN, -1, 0, diff --git a/libc/intrin/kprintf.greg.c b/libc/intrin/kprintf.greg.c index cb4c87659..420835f59 100644 --- a/libc/intrin/kprintf.greg.c +++ b/libc/intrin/kprintf.greg.c @@ -121,7 +121,8 @@ extern struct SymbolTable *__symtab; __funline char *kadvance(char *p, char *e, long n) { intptr_t t = (intptr_t)p; - if (ckd_add(&t, t, n)) t = (intptr_t)e; + if (ckd_add(&t, t, n)) + t = (intptr_t)e; return (char *)t; } @@ -154,8 +155,10 @@ __funline bool kisimagepointer(const void *p) { } __funline bool kischarmisaligned(const char *p, signed char t) { - if (t == -1) return (intptr_t)p & 1; - if (t >= 1) return !!((intptr_t)p & 3); + if (t == -1) + return (intptr_t)p & 1; + if (t >= 1) + return !!((intptr_t)p & 3); return false; } @@ -168,8 +171,10 @@ __funline bool kismemtrackhosed(void) { privileged static bool kismapped(int x) { // xxx: we can't lock because no reentrant locks yet size_t m, r, l = 0; - if (!_weaken(_mmi)) return true; - if (kismemtrackhosed()) return false; + if (!_weaken(_mmi)) + return true; + if (kismemtrackhosed()) + return false; r = _weaken(_mmi)->i; while (l < r) { m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2) @@ -188,13 +193,18 @@ privileged static bool kismapped(int x) { privileged bool32 kisdangerous(const void *p) { int frame; - if (kisimagepointer(p)) return false; - if (kiskernelpointer(p)) return false; - if (IsOldStack(p)) return false; + if (kisimagepointer(p)) + return false; + if (kiskernelpointer(p)) + return false; + if (IsOldStack(p)) + return false; if (IsLegalPointer(p)) { frame = (uintptr_t)p >> 16; - if (IsStackFrame(frame)) return false; - if (kismapped(frame)) return false; + if (IsStackFrame(frame)) + return false; + if (kismapped(frame)) + return false; } if (GetStackAddr() + GetGuardSize() <= (uintptr_t)p && (uintptr_t)p < GetStackAddr() + GetStackSize()) { @@ -228,7 +238,8 @@ privileged static long klogfcntl(long fd, long cmd, long arg) { : CFLAG_CONSTRAINT(cf), "+a"(ax), "+D"(fd), "+S"(cmd), "+d"(arg) : /* inputs already specified */ : "rcx", "r8", "r9", "r10", "r11", "memory"); - if (cf) ax = -ax; + if (cf) + ax = -ax; return ax; #elif defined(__aarch64__) register long x0 asm("x0") = fd; @@ -264,7 +275,8 @@ privileged static long klogopen(const char *path) { "+d"(flags), "+r"(r10) : /* inputs already specified */ : "rcx", "r8", "r9", "r11", "memory"); - if (cf) ax = -ax; + if (cf) + ax = -ax; return ax; #elif defined(__aarch64__) register long x0 asm("x0") = dirfd; @@ -376,7 +388,8 @@ privileged void _klog_serial(const char *b, size_t n) { for (;;) { dx = 0x3F8 + UART_LSR; asm("inb\t%1,%0" : "=a"(al) : "dN"(dx)); - if (al & UART_TTYTXR) break; + if (al & UART_TTYTXR) + break; asm("pause"); } dx = 0x3F8; @@ -448,19 +461,24 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, unsigned long long x; unsigned i, j, m, rem, sign, hash, cols, prec; char c, *p, *e, pdot, zero, flip, dang, base, quot, uppr, ansi, z[128]; - if (kistextpointer(b) || kisdangerous(b)) n = 0; - if (!kistextpointer(fmt)) fmt = "!!WONTFMT"; + if (kistextpointer(b) || kisdangerous(b)) + n = 0; + if (!kistextpointer(fmt)) + fmt = "!!WONTFMT"; p = b; f = fmt; e = p + n; // assume if n was negative e < p will be the case for (;;) { for (;;) { - if (!(c = *f++) || c == '%') break; + if (!(c = *f++) || c == '%') + break; EmitFormatByte: - if (p < e) *p = c; + if (p < e) + *p = c; ++p; } - if (!c) break; + if (!c) + break; pdot = 0; flip = 0; dang = 0; @@ -632,21 +650,26 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, sign = '-'; } FormatUnsigned: - if (x && hash) sign = hash; + if (x && hash) + sign = hash; for (i = j = 0;;) { x = __divmod10(x, &rem); z[i++ & 127] = '0' + rem; - if (pdot ? i >= prec : !x) break; + if (pdot ? i >= prec : !x) + break; if (quot && ++j == 3) { z[i++ & 127] = quot; j = 0; } } EmitNumber: - if (flip || pdot) zero = 0; + if (flip || pdot) + zero = 0; while (zero && sign) { - if (p < e) *p = sign; - if (cols) --cols; + if (p < e) + *p = sign; + if (cols) + --cols; sign >>= 8; ++p; } @@ -662,7 +685,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, } } while (sign) { - if (p < e) *p = sign; + if (p < e) + *p = sign; sign >>= 8; ++p; } @@ -686,14 +710,17 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, case 'b': base = 1; - if (hash) hash = '0' | 'b' << 8; + if (hash) + hash = '0' | 'b' << 8; BinaryNumber: KGETINT(x, va, type, false); FormatNumber: i = 0; m = (1 << base) - 1; - if (hash && x) sign = hash; - do z[i++ & 127] = abet[x & m]; + if (hash && x) + sign = hash; + do + z[i++ & 127] = abet[x & m]; while ((x >>= base) || (pdot && i < prec)); goto EmitNumber; @@ -702,7 +729,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, /* fallthrough */ case 'x': base = 4; - if (hash) hash = '0' | 'x' << 8; + if (hash) + hash = '0' | 'x' << 8; goto BinaryNumber; case 'o': @@ -711,7 +739,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, case 'p': x = va_arg(va, intptr_t); - if (!x && pdot) pdot = 0; + if (!x && pdot) + pdot = 0; if ((long)x == -1) { pdot = 0; goto FormatDecimal; @@ -730,14 +759,18 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, x = 0; s = (const char *)&x; t = va_arg(va, int); - if (!type) t &= 255; + if (!type) + t &= 255; if (hash) { quot = 1; hash = '\''; p = kemitquote(p, e, type, hash); - if (cols && type) --cols; // u/L - if (cols) --cols; // start quote - if (cols) --cols; // end quote + if (cols && type) + --cols; // u/L + if (cols) + --cols; // start quote + if (cols) + --cols; // end quote } goto EmitChar; @@ -771,7 +804,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, x = va_arg(va, intptr_t); if (_weaken(__symtab) && *_weaken(__symtab) && (idx = _weaken(__get_symbol)(0, x)) != -1) { - if (p + 1 <= e) *p++ = '&'; + if (p + 1 <= e) + *p++ = '&'; s = (*_weaken(__symtab))->name_base + (*_weaken(__symtab))->names[idx]; goto FormatString; @@ -783,7 +817,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, case 'n': // nonstandard %n specifier - if (p < e) *p = '\n'; + if (p < e) + *p = '\n'; ++p; break; @@ -806,7 +841,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, type = 0; } else if (!dang && (kisdangerous(s) || kischarmisaligned(s, type))) { if (sign == ' ') { - if (p < e) *p = ' '; + if (p < e) + *p = ' '; ++p; } x = (intptr_t)s; @@ -816,22 +852,29 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, } else if (hash) { quot = 1; hash = '"'; - if (cols && type) --cols; // u/L - if (cols) --cols; // start quote - if (cols) --cols; // end quote + if (cols && type) + --cols; // u/L + if (cols) + --cols; // start quote + if (cols) + --cols; // end quote p = kemitquote(p, e, type, hash); } if (sign == ' ' && (!pdot || prec) && s && *s) { - if (p < e) *p = ' '; + if (p < e) + *p = ' '; ++p; } for (i = j = 0; !pdot || j < prec; ++j) { if (UNLIKELY(!((intptr_t)s & 4095))) { - if (!dang && kisdangerous(s)) break; + if (!dang && kisdangerous(s)) + break; } if (!type) { - if (!(t = *s++ & 255)) break; - if ((t & 0300) == 0200) goto ActuallyEmitByte; + if (!(t = *s++ & 255)) + break; + if ((t & 0300) == 0200) + goto ActuallyEmitByte; ++i; EmitByte: if (uppr && 'a' <= t && t <= 'z') { @@ -851,7 +894,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, (t != 0x7F && (t >= 0x20 || (t == '\n' || t == '\t' || t == '\r' || t == '\e')))) { ActuallyEmitByte: - if (p < e) *p = t; + if (p < e) + *p = t; p += 1; continue; } else if (quot) { @@ -889,7 +933,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, if (IsHighSurrogate(t)) { if (!pdot || j + 1 < prec) { if (UNLIKELY(!((intptr_t)s & 4095))) { - if (!dang && kisdangerous(s)) break; + if (!dang && kisdangerous(s)) + break; } u = *(const char16_t *)s; if (IsLowSurrogate(u)) { @@ -907,10 +952,12 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, t = *(const wchar_t *)s; s += sizeof(wchar_t); } - if (!t) break; + if (!t) + break; ++i; EmitChar: - if (t <= 0x7f) goto EmitByte; + if (t <= 0x7f) + goto EmitByte; if (uppr) { if (_weaken(towupper)) { t = _weaken(towupper)(t); @@ -948,7 +995,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, } } if (hash) { - if (p < e) *p = hash; + if (p < e) + *p = hash; ++p; } while (cols > i) { diff --git a/libc/intrin/lockfileex.c b/libc/intrin/lockfileex.c index 1a41729b5..e156ebe54 100644 --- a/libc/intrin/lockfileex.c +++ b/libc/intrin/lockfileex.c @@ -44,7 +44,8 @@ bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved, } ok = __imp_LockFileEx(hFile, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, lpOverlapped); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("LockFileEx(%ld, %s, %#x, %'zu, [%s]) → %hhhd% m", hFile, DescribeNtLockFileFlags(dwFlags), dwReserved, (uint64_t)nNumberOfBytesToLockHigh << 32 | nNumberOfBytesToLockLow, diff --git a/libc/intrin/mapviewoffileex.c b/libc/intrin/mapviewoffileex.c index 9ea8d093a..3841269bf 100644 --- a/libc/intrin/mapviewoffileex.c +++ b/libc/intrin/mapviewoffileex.c @@ -44,7 +44,8 @@ textwindows void *MapViewOfFileEx(int64_t hFileMappingObject, pStartingAddress = __imp_MapViewOfFileEx( hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap, opt_lpDesiredBaseAddress); - if (!pStartingAddress) __winerr(); + if (!pStartingAddress) + __winerr(); NTTRACE("MapViewOfFileEx(%ld, %s, %'ld, %'zu, %p) → %p% m", hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess), (uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow, diff --git a/libc/intrin/mapviewoffileexnuma.c b/libc/intrin/mapviewoffileexnuma.c index 5f1b32aca..2ee4e40de 100644 --- a/libc/intrin/mapviewoffileexnuma.c +++ b/libc/intrin/mapviewoffileexnuma.c @@ -46,7 +46,8 @@ textwindows void *MapViewOfFileExNuma(int64_t hFileMappingObject, pStartingAddress = __imp_MapViewOfFileExNuma( hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, nndDesiredNumaNode); - if (!pStartingAddress) __winerr(); + if (!pStartingAddress) + __winerr(); NTTRACE("MapViewOfFileExNuma(%ld, %s, %'ld, %'zu, %p) → %p% m", hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess), (uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow, diff --git a/libc/intrin/memcmp.c b/libc/intrin/memcmp.c index 8c1430c4e..ad8387166 100644 --- a/libc/intrin/memcmp.c +++ b/libc/intrin/memcmp.c @@ -143,8 +143,10 @@ int memcmp(const void *a, const void *b, size_t n) { uint64_t w, x, y; #endif const unsigned char *p, *q; - if ((p = a) == (q = b) || !n) return 0; - if ((c = *p - *q)) return c; + if ((p = a) == (q = b) || !n) + return 0; + if ((c = *p - *q)) + return c; #if defined(__x86_64__) && !defined(__chibicc__) if (!IsTiny()) { if (n <= 16) { diff --git a/libc/intrin/memmove.c b/libc/intrin/memmove.c index 493210aac..b67842c50 100644 --- a/libc/intrin/memmove.c +++ b/libc/intrin/memmove.c @@ -153,7 +153,8 @@ static __vex void *__memmove(void *dst, const void *src, size_t n) { *(xmm_t *)(d + n - 16) = Y; return d; default: - if (d == s) return d; + if (d == s) + return d; #if defined(__x86_64__) && !defined(__chibicc__) if (n < kHalfCache3 || !kHalfCache3) { diff --git a/libc/intrin/memtrack.greg.c b/libc/intrin/memtrack.greg.c index 368ab608a..3027e51d9 100644 --- a/libc/intrin/memtrack.greg.c +++ b/libc/intrin/memtrack.greg.c @@ -71,10 +71,12 @@ static bool __extend_memory(struct MemoryIntervals *mm) { if (1 || IsAsan()) { shad = (char *)(((intptr_t)base >> 3) + 0x7fff8000); dm = sys_mmap(shad, gran >> 3, prot, flags, -1, 0); - if (!dm.addr) return false; + if (!dm.addr) + return false; } dm = sys_mmap(base, gran, prot, flags, -1, 0); - if (!dm.addr) return false; + if (!dm.addr) + return false; __shove_memory(dm.addr, mm->p, mm->i); mm->p = dm.addr; mm->n = gran / sizeof(*mm->p); @@ -84,10 +86,12 @@ static bool __extend_memory(struct MemoryIntervals *mm) { if (IsAsan()) { shad = (char *)(((intptr_t)base >> 3) + 0x7fff8000); dm = sys_mmap(shad, gran >> 3, prot, flags, -1, 0); - if (!dm.addr) return false; + if (!dm.addr) + return false; } dm = sys_mmap(base, gran, prot, flags, -1, 0); - if (!dm.addr) return false; + if (!dm.addr) + return false; mm->n = (size + gran) / sizeof(*mm->p); } return true; @@ -97,13 +101,15 @@ static int __mint_memory(struct MemoryIntervals *mm, int i) { unassert(i >= 0); unassert(i <= mm->i); unassert(mm->n >= 0); - if (mm->i == mm->n && !__extend_memory(mm)) return enomem(); + if (mm->i == mm->n && !__extend_memory(mm)) + return enomem(); __shove_memory(mm->p + i + 1, mm->p + i, mm->i++ - i); return 0; } static int __punch_memory(struct MemoryIntervals *mm, int x, int y, int i) { - if (__mint_memory(mm, i) == -1) return -1; + if (__mint_memory(mm, i) == -1) + return -1; mm->p[i + 0].size -= (size_t)(mm->p[i + 0].y - (x - 1)) * FRAMESIZE; mm->p[i + 0].y = x - 1; mm->p[i + 1].size -= (size_t)((y + 1) - mm->p[i + 1].x) * FRAMESIZE; @@ -115,15 +121,19 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y, void wf(struct MemoryIntervals *, int, int)) { unsigned l, r; unassert(y >= x); - if (!mm->i) return 0; + if (!mm->i) + return 0; // binary search for the lefthand side l = __find_memory(mm, x); - if (l == mm->i) return 0; - if (y < mm->p[l].x) return 0; + if (l == mm->i) + return 0; + if (y < mm->p[l].x) + return 0; // binary search for the righthand side r = __find_memory(mm, y); - if (r == mm->i || (r > l && y < mm->p[r].x)) --r; + if (r == mm->i || (r > l && y < mm->p[r].x)) + --r; unassert(r >= l); unassert(x <= mm->p[r].y); @@ -147,7 +157,8 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y, // if (x > mm->p[l].x && x <= mm->p[l].y) { unassert(y >= mm->p[l].y); - if (IsWindows()) return einval(); + if (IsWindows()) + return einval(); mm->p[l].size -= (size_t)(mm->p[l].y - (x - 1)) * FRAMESIZE; mm->p[l].y = x - 1; unassert(mm->p[l].x <= mm->p[l].y); @@ -162,7 +173,8 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y, // if (y >= mm->p[r].x && y < mm->p[r].y) { unassert(x <= mm->p[r].x); - if (IsWindows()) return einval(); + if (IsWindows()) + return einval(); mm->p[r].size -= (size_t)((y + 1) - mm->p[r].x) * FRAMESIZE; mm->p[r].x = y + 1; unassert(mm->p[r].x <= mm->p[r].y); @@ -214,7 +226,8 @@ int __track_memory(struct MemoryIntervals *mm, int x, int y, long h, int prot, // otherwise, create a new entry and memmove the items else { - if (__mint_memory(mm, i) == -1) return -1; + if (__mint_memory(mm, i) == -1) + return -1; mm->p[i].x = x; mm->p[i].y = y; mm->p[i].h = h; diff --git a/libc/intrin/mman.greg.c b/libc/intrin/mman.greg.c index 6c886df53..cb9274a1b 100644 --- a/libc/intrin/mman.greg.c +++ b/libc/intrin/mman.greg.c @@ -79,7 +79,8 @@ texthead uint64_t __new_page(struct mman *mm) { return 0; } while (mm->pdp >= mm->e820[mm->pdpi].addr + mm->e820[mm->pdpi].size) { - if (++mm->pdpi == mm->e820n) return 0; + if (++mm->pdpi == mm->e820n) + return 0; mm->pdp = MAX(mm->pdp, mm->e820[mm->pdpi].addr); } p = mm->pdp; @@ -98,10 +99,13 @@ textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t, int64_t vaddr, unsigned char h; for (h = 39;; h -= 9) { e = t + ((vaddr >> h) & 511); - if (h == 12) return e; + if (h == 12) + return e; if (!(*e & (PAGE_V | PAGE_RSRV))) { - if (!maketables) return NULL; - if (!(p = __new_page(mm))) return NULL; + if (!maketables) + return NULL; + if (!(p = __new_page(mm))) + return NULL; __clear_page(BANE + p); *e = p | PAGE_V | PAGE_RW; } @@ -215,7 +219,8 @@ void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) { if ((e & PAGE_REFC) != PAGE_REFC) { e -= PAGE_1REF; *m = e; - if ((e & PAGE_REFC) == 0) __reclaim_page(mm, p); + if ((e & PAGE_REFC) == 0) + __reclaim_page(mm, p); } } } @@ -229,7 +234,8 @@ static textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) { for (i = 0; i < mm->e820n; ++i) { uint64_t ps = mm->e820[i].addr, size = mm->e820[i].size; /* ape/ape.S has already mapped the first 2 MiB of physical memory. */ - if (ps < 0x200000 && ps + size <= 0x200000) continue; + if (ps < 0x200000 && ps + size <= 0x200000) + continue; __invert_memory_area(mm, pml4t, ps, size, PAGE_RW | PAGE_XD); } } @@ -275,13 +281,15 @@ static textreal uint64_t __map_phdr(struct mman *mm, uint64_t *pml4t, uint64_t b, uint64_t m, struct Elf64_Phdr *p) { uint64_t i, f, v; - if (p->p_type != PT_LOAD) return m; + if (p->p_type != PT_LOAD) + return m; f = PAGE_RSRV | PAGE_U; if (p->p_flags & PF_W) f |= PAGE_V | PAGE_RW; else if (p->p_flags & (PF_R | PF_X)) f |= PAGE_V; - if (!(p->p_flags & PF_X)) f |= PAGE_XD; + if (!(p->p_flags & PF_X)) + f |= PAGE_XD; for (i = 0; i < p->p_memsz; i += 4096) { if (i < p->p_filesz) { v = b + p->p_offset + i; @@ -336,14 +344,16 @@ textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start, uint64_t p = mm->frp, q = IMAGE_BASE_REAL, i, n = mm->e820n, b, e; for (i = 0; i < n; ++i) { b = mm->e820[i].addr; - if (b >= IMAGE_BASE_PHYSICAL) break; + if (b >= IMAGE_BASE_PHYSICAL) + break; e = MIN(IMAGE_BASE_PHYSICAL, b + mm->e820[i].size); q = MAX(IMAGE_BASE_REAL, b); while (q < e) { struct ReclaimedPage *rp; if (q == skip_start) { q = skip_end; - if (q >= e) break; + if (q >= e) + break; } rp = (struct ReclaimedPage *)(BANE + q); rp->next = p; diff --git a/libc/intrin/movefileex.c b/libc/intrin/movefileex.c index 29d6b84cc..66e32fe02 100644 --- a/libc/intrin/movefileex.c +++ b/libc/intrin/movefileex.c @@ -33,7 +33,8 @@ textwindows bool32 MoveFileEx(const char16_t *lpExistingFileName, const char16_t *lpNewFileName, int dwFlags) { bool32 ok; ok = __imp_MoveFileExW(lpExistingFileName, lpNewFileName, dwFlags); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("MoveFileEx(%#hs, %#hs, %s) → %hhhd% m", lpExistingFileName, lpNewFileName, DescribeNtMovFileInpFlags(dwFlags), ok); return ok; diff --git a/libc/intrin/mulvti3.c b/libc/intrin/mulvti3.c index cf0e43eef..fe7f84b71 100644 --- a/libc/intrin/mulvti3.c +++ b/libc/intrin/mulvti3.c @@ -30,6 +30,7 @@ int128_t __mulvti3(int128_t x, int128_t y) { int o; int128_t z; z = __muloti4(x, y, &o); - if (o) __on_arithmetic_overflow(); + if (o) + __on_arithmetic_overflow(); return z; } diff --git a/libc/intrin/ntcontext2linux.c b/libc/intrin/ntcontext2linux.c index c5e68a8cb..a57caf33b 100644 --- a/libc/intrin/ntcontext2linux.c +++ b/libc/intrin/ntcontext2linux.c @@ -23,7 +23,8 @@ #ifdef __x86_64__ textwindows void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) { - if (!cr) return; + if (!cr) + return; ctx->uc_mcontext.eflags = cr->EFlags; ctx->uc_mcontext.rax = cr->Rax; ctx->uc_mcontext.rbx = cr->Rbx; @@ -50,7 +51,8 @@ textwindows void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) { } textwindows void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) { - if (!cr) return; + if (!cr) + return; cr->EFlags = ctx->uc_mcontext.eflags; cr->Rax = ctx->uc_mcontext.rax; cr->Rbx = ctx->uc_mcontext.rbx; diff --git a/libc/intrin/openprocess.c b/libc/intrin/openprocess.c index 58a5254b9..338da91bf 100644 --- a/libc/intrin/openprocess.c +++ b/libc/intrin/openprocess.c @@ -38,7 +38,8 @@ textwindows int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle, uint32_t dwProcessId) { int64_t hHandle; hHandle = __imp_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); - if (!hHandle) __winerr(); + if (!hHandle) + __winerr(); NTTRACE("OpenProcess(%s, %hhhd, %u) → %ld% m", DescribeNtProcAccessFlags(dwDesiredAccess), bInheritHandle, dwProcessId, hHandle); diff --git a/libc/intrin/packsswb.c b/libc/intrin/packsswb.c index 1924569ba..da3fa67b9 100644 --- a/libc/intrin/packsswb.c +++ b/libc/intrin/packsswb.c @@ -32,7 +32,9 @@ void(packsswb)(int8_t a[16], const int16_t b[8], const int16_t c[8]) { unsigned i; int8_t r[16]; - for (i = 0; i < 8; ++i) r[i + 0] = MIN(INT8_MAX, MAX(INT8_MIN, b[i])); - for (i = 0; i < 8; ++i) r[i + 8] = MIN(INT8_MAX, MAX(INT8_MIN, c[i])); + for (i = 0; i < 8; ++i) + r[i + 0] = MIN(INT8_MAX, MAX(INT8_MIN, b[i])); + for (i = 0; i < 8; ++i) + r[i + 8] = MIN(INT8_MAX, MAX(INT8_MIN, c[i])); __builtin_memcpy(a, r, 16); } diff --git a/libc/intrin/packuswb.c b/libc/intrin/packuswb.c index 1a1586727..66d9c766f 100644 --- a/libc/intrin/packuswb.c +++ b/libc/intrin/packuswb.c @@ -32,7 +32,9 @@ void(packuswb)(uint8_t a[16], const int16_t b[8], const int16_t c[8]) { unsigned i; uint8_t r[16]; - for (i = 0; i < 8; ++i) r[i + 0] = MIN(UINT8_MAX, MAX(UINT8_MIN, b[i])); - for (i = 0; i < 8; ++i) r[i + 8] = MIN(UINT8_MAX, MAX(UINT8_MIN, c[i])); + for (i = 0; i < 8; ++i) + r[i + 0] = MIN(UINT8_MAX, MAX(UINT8_MIN, b[i])); + for (i = 0; i < 8; ++i) + r[i + 8] = MIN(UINT8_MAX, MAX(UINT8_MIN, c[i])); __builtin_memcpy(a, r, 16); } diff --git a/libc/intrin/pcmpgtb.c b/libc/intrin/pcmpgtb.c index 9ad51b59b..f1c895d72 100644 --- a/libc/intrin/pcmpgtb.c +++ b/libc/intrin/pcmpgtb.c @@ -32,6 +32,7 @@ void(pcmpgtb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { unsigned i; int8_t r[16]; - for (i = 0; i < 16; ++i) r[i] = -(b[i] > c[i]); + for (i = 0; i < 16; ++i) + r[i] = -(b[i] > c[i]); __builtin_memcpy(a, r, 16); } diff --git a/libc/intrin/pcmpgtw.c b/libc/intrin/pcmpgtw.c index 02d1f90c1..7bf94ef49 100644 --- a/libc/intrin/pcmpgtw.c +++ b/libc/intrin/pcmpgtw.c @@ -30,6 +30,7 @@ void(pcmpgtw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { unsigned i; int16_t r[8]; - for (i = 0; i < 8; ++i) r[i] = -(b[i] > c[i]); + for (i = 0; i < 8; ++i) + r[i] = -(b[i] > c[i]); __builtin_memcpy(a, r, 16); } diff --git a/libc/intrin/pmovmskb.c b/libc/intrin/pmovmskb.c index 4432d088d..0ff024d1d 100644 --- a/libc/intrin/pmovmskb.c +++ b/libc/intrin/pmovmskb.c @@ -27,7 +27,8 @@ uint32_t(pmovmskb)(const uint8_t p[16]) { uint32_t i, m; for (m = i = 0; i < 16; ++i) { - if (p[i] & 0x80) m |= 1 << i; + if (p[i] & 0x80) + m |= 1 << i; } return m; } diff --git a/libc/intrin/pmulhrsw.c b/libc/intrin/pmulhrsw.c index 00a97656f..4326542e0 100644 --- a/libc/intrin/pmulhrsw.c +++ b/libc/intrin/pmulhrsw.c @@ -30,6 +30,7 @@ void(pmulhrsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { unsigned i; int16_t r[8]; - for (i = 0; i < 8; ++i) r[i] = (((b[i] * c[i]) >> 14) + 1) >> 1; + for (i = 0; i < 8; ++i) + r[i] = (((b[i] * c[i]) >> 14) + 1) >> 1; __builtin_memcpy(a, r, 16); } diff --git a/libc/intrin/printmemoryintervals.c b/libc/intrin/printmemoryintervals.c index 2cab88cf2..8961705ad 100644 --- a/libc/intrin/printmemoryintervals.c +++ b/libc/intrin/printmemoryintervals.c @@ -43,8 +43,10 @@ void PrintMemoryIntervals(int fd, const struct MemoryIntervals *mm) { kprintf("%08x-%08x %s %'*ldx %s", mm->p[i].x, mm->p[i].y, (DescribeMapping)(mappingbuf, mm->p[i].prot, mm->p[i].flags), w, frames, (DescribeFrame)(framebuf, mm->p[i].x)); - if (mm->p[i].iscow) kprintf(" cow"); - if (mm->p[i].readonlyfile) kprintf(" readonlyfile"); + if (mm->p[i].iscow) + kprintf(" cow"); + if (mm->p[i].readonlyfile) + kprintf(" readonlyfile"); sizefmt(sb, mm->p[i].size, 1024); kprintf(" %sB", sb); if (i + 1 < mm->i) { diff --git a/libc/intrin/psraw.c b/libc/intrin/psraw.c index 576cc34e3..0ea62c129 100644 --- a/libc/intrin/psraw.c +++ b/libc/intrin/psraw.c @@ -27,7 +27,8 @@ */ void(psraw)(int16_t a[8], const int16_t b[8], unsigned char k) { unsigned i; - if (k > 15) k = 15; + if (k > 15) + k = 15; for (i = 0; i < 8; ++i) { a[i] = b[i] >> k; } diff --git a/libc/intrin/pthread_syshand.c b/libc/intrin/pthread_syshand.c index 9557a0c2b..856ce3323 100644 --- a/libc/intrin/pthread_syshand.c +++ b/libc/intrin/pthread_syshand.c @@ -27,7 +27,8 @@ intptr_t _pthread_syshand(struct PosixThread *pt) { unassert(IsWindows() || IsXnuSilicon()); for (;;) { syshand = atomic_load_explicit(&pt->tib->tib_syshand, memory_order_acquire); - if (syshand) return syshand; + if (syshand) + return syshand; pthread_pause_np(); } } diff --git a/libc/intrin/rand64.c b/libc/intrin/rand64.c index 90732e64f..f631d109f 100644 --- a/libc/intrin/rand64.c +++ b/libc/intrin/rand64.c @@ -46,7 +46,8 @@ static struct { uint64_t _rand64(void) { void *p; uint128_t s; - if (__threaded) pthread_spin_lock(&g_rand64.lock); + if (__threaded) + pthread_spin_lock(&g_rand64.lock); if (__pid == g_rand64.thepid) { s = g_rand64.thepool; // normal path } else { diff --git a/libc/intrin/reservefd.c b/libc/intrin/reservefd.c index 447f7ff2e..1be7e4b4f 100644 --- a/libc/intrin/reservefd.c +++ b/libc/intrin/reservefd.c @@ -36,7 +36,8 @@ */ int __ensurefds_unlocked(int fd) { size_t n; - if (fd < g_fds.n) return fd; + if (fd < g_fds.n) + return fd; n = fd + 1; g_fds.e = _extend(g_fds.p, n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE, kMemtrackFdsStart + kMemtrackFdsSize); diff --git a/libc/intrin/setcurrentdirectory.c b/libc/intrin/setcurrentdirectory.c index 9e8ed397e..ae8b70c43 100644 --- a/libc/intrin/setcurrentdirectory.c +++ b/libc/intrin/setcurrentdirectory.c @@ -31,7 +31,8 @@ __msabi extern typeof(SetCurrentDirectory) *const __imp_SetCurrentDirectoryW; textwindows bool32 SetCurrentDirectory(const char16_t *lpPathName) { bool32 ok; ok = __imp_SetCurrentDirectoryW(lpPathName); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("SetCurrentDirectory(%#hs) → %hhhd% m", lpPathName, ok); return ok; } diff --git a/libc/intrin/sigcountset.c b/libc/intrin/sigcountset.c index f300c9361..77cc4baf8 100644 --- a/libc/intrin/sigcountset.c +++ b/libc/intrin/sigcountset.c @@ -30,6 +30,7 @@ */ int sigcountset(const sigset_t *set) { uint64_t x = *set; - if (IsOpenbsd() || IsXnu()) x &= 0xffffffff; + if (IsOpenbsd() || IsXnu()) + x &= 0xffffffff; return popcnt(x); } diff --git a/libc/intrin/sigfillset.c b/libc/intrin/sigfillset.c index aa7d24912..506b72c8f 100644 --- a/libc/intrin/sigfillset.c +++ b/libc/intrin/sigfillset.c @@ -29,11 +29,13 @@ */ int sigfillset(sigset_t *set) { *set = -1; - *set &= ~(1ull << (SIGTHR - 1)); // only libc should mask - *set &= ~(1ull << (SIGABRT - 1)); // it's annoying to mask - *set &= ~(1ull << (SIGKILL - 1)); // it's impossible to mask - *set &= ~(1ull << (SIGSTOP - 1)); // it's impossible to mask - if (IsOpenbsd()) *set &= 0xffffffff; // it doesn't really exist - if (IsXnu()) *set &= 0xffffffff; // it doesn't really exist + *set &= ~(1ull << (SIGTHR - 1)); // only libc should mask + *set &= ~(1ull << (SIGABRT - 1)); // it's annoying to mask + *set &= ~(1ull << (SIGKILL - 1)); // it's impossible to mask + *set &= ~(1ull << (SIGSTOP - 1)); // it's impossible to mask + if (IsOpenbsd()) + *set &= 0xffffffff; // it doesn't really exist + if (IsXnu()) + *set &= 0xffffffff; // it doesn't really exist return 0; } diff --git a/libc/intrin/sizefmt.c b/libc/intrin/sizefmt.c index 680163ff9..a3cb8ea6b 100644 --- a/libc/intrin/sizefmt.c +++ b/libc/intrin/sizefmt.c @@ -47,7 +47,8 @@ char *sizefmt(char *p, uint64_t x, uint64_t b) { } } p = FormatUint64(p, x); - if (suffix) *p++ = suffix; + if (suffix) + *p++ = suffix; *p = 0; return p; } diff --git a/libc/intrin/stracef.greg.c b/libc/intrin/stracef.greg.c index abe36383c..3bbfe1166 100644 --- a/libc/intrin/stracef.greg.c +++ b/libc/intrin/stracef.greg.c @@ -24,7 +24,8 @@ dontinstrument void __stracef(const char *fmt, ...) { va_list v; - if (strace_enabled(0) <= 0) return; + if (strace_enabled(0) <= 0) + return; va_start(v, fmt); kvprintf(fmt, v); va_end(v); diff --git a/libc/intrin/strchr.c b/libc/intrin/strchr.c index 4d05ffb05..77c6ab0d5 100644 --- a/libc/intrin/strchr.c +++ b/libc/intrin/strchr.c @@ -24,8 +24,10 @@ static inline const char *strchr_pure(const char *s, int c) { for (;; ++s) { - if ((*s & 255) == (c & 255)) return s; - if (!*s) return 0; + if ((*s & 255) == (c & 255)) + return s; + if (!*s) + return 0; } } @@ -50,7 +52,8 @@ static __vex const char *strchr_sse(const char *s, unsigned char c) { } m = __builtin_ctzl(m); s = (const char *)p + m; - if (c && !*s) s = 0; + if (c && !*s) + s = 0; return s; } #endif @@ -106,8 +109,10 @@ char *strchr(const char *s, int c) { #else const char *r; for (c &= 255; (uintptr_t)s & 7; ++s) { - if ((*s & 255) == c) return (char *)s; - if (!*s) return NULL; + if ((*s & 255) == c) + return (char *)s; + if (!*s) + return NULL; } return (char *)strchr_x64(s, c); #endif diff --git a/libc/intrin/strchrnul.c b/libc/intrin/strchrnul.c index b61cebde7..2339e066c 100644 --- a/libc/intrin/strchrnul.c +++ b/libc/intrin/strchrnul.c @@ -24,8 +24,10 @@ static inline const char *strchrnul_pure(const char *s, int c) { for (;; ++s) { - if ((*s & 255) == (c & 255)) return s; - if (!*s) return s; + if ((*s & 255) == (c & 255)) + return s; + if (!*s) + return s; } } @@ -105,8 +107,10 @@ __vex char *strchrnul(const char *s, int c) { #else char *r; for (c &= 255; (uintptr_t)s & 7; ++s) { - if ((*s & 0xff) == c) return s; - if (!*s) return s; + if ((*s & 0xff) == c) + return s; + if (!*s) + return s; } r = strchrnul_x64(s, c); assert((*r & 255) == c || !*r); diff --git a/libc/intrin/strcmp.c b/libc/intrin/strcmp.c index e34dc7563..0b4d4e73f 100644 --- a/libc/intrin/strcmp.c +++ b/libc/intrin/strcmp.c @@ -32,8 +32,10 @@ int strcmp(const char *a, const char *b) { int c; size_t i = 0; uint64_t v, w; - if (a == b) return 0; - if ((c = (*a & 255) - (*b & 255))) return c; + if (a == b) + return 0; + if ((c = (*a & 255) - (*b & 255))) + return c; if (!IsTiny() && ((uintptr_t)a & 7) == ((uintptr_t)b & 7)) { for (; (uintptr_t)(a + i) & 7; ++i) { if (a[i] != b[i] || !b[i]) { @@ -50,7 +52,8 @@ int strcmp(const char *a, const char *b) { } } } else { - while (a[i] == b[i] && b[i]) ++i; + while (a[i] == b[i] && b[i]) + ++i; } return (a[i] & 255) - (b[i] & 255); } diff --git a/libc/intrin/strlen.c b/libc/intrin/strlen.c index 72a32c33d..aabf2bfe4 100644 --- a/libc/intrin/strlen.c +++ b/libc/intrin/strlen.c @@ -27,7 +27,8 @@ static __vex size_t __strlen(const char *s) { unsigned m, k = (uintptr_t)s & 15; const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16); m = __builtin_ia32_pmovmskb128(*p == z) >> k << k; - while (!m) m = __builtin_ia32_pmovmskb128(*++p == z); + while (!m) + m = __builtin_ia32_pmovmskb128(*++p == z); return (const char *)p + __builtin_ctzl(m) - s; #else #define ONES ((word) - 1 / 255) diff --git a/libc/intrin/strncmp.c b/libc/intrin/strncmp.c index 9e44466e6..5688e6ca9 100644 --- a/libc/intrin/strncmp.c +++ b/libc/intrin/strncmp.c @@ -29,8 +29,10 @@ */ int strncmp(const char *a, const char *b, size_t n) { size_t i = 0; - if (!n-- || a == b) return 0; - while (i < n && a[i] == b[i] && b[i]) ++i; + if (!n-- || a == b) + return 0; + while (i < n && a[i] == b[i] && b[i]) + ++i; return (a[i] & 0xff) - (b[i] & 0xff); } diff --git a/libc/intrin/strnlen.c b/libc/intrin/strnlen.c index 0fa5b52c1..f6510f933 100644 --- a/libc/intrin/strnlen.c +++ b/libc/intrin/strnlen.c @@ -44,11 +44,13 @@ static size_t strnlen_x64(const char *s, size_t n, size_t i) { size_t strnlen(const char *s, size_t n) { size_t i; for (i = 0; (uintptr_t)(s + i) & 7; ++i) { - if (i == n || !s[i]) return i; + if (i == n || !s[i]) + return i; } i = strnlen_x64(s, n, i); for (;; ++i) { - if (i == n || !s[i]) break; + if (i == n || !s[i]) + break; } unassert(i == n || (i < n && !s[i])); return i; diff --git a/libc/intrin/strsignal_r.c b/libc/intrin/strsignal_r.c index bd3a6d8f9..325838bf8 100644 --- a/libc/intrin/strsignal_r.c +++ b/libc/intrin/strsignal_r.c @@ -57,8 +57,10 @@ privileged const char *strsignal_r(int sig, char buf[21]) { } else { p = buf; } - if (sig >= 100) *p++ = '0' + (unsigned char)sig / 100 % 10; - if (sig >= 10) *p++ = '0' + (unsigned char)sig / 10 % 10; + if (sig >= 100) + *p++ = '0' + (unsigned char)sig / 100 % 10; + if (sig >= 10) + *p++ = '0' + (unsigned char)sig / 10 % 10; *p++ = '0' + (unsigned char)sig % 10; *p = 0; return buf; diff --git a/libc/intrin/tpenc.c b/libc/intrin/tpenc.c index 571209dd6..3d131dbbe 100644 --- a/libc/intrin/tpenc.c +++ b/libc/intrin/tpenc.c @@ -33,7 +33,8 @@ static const uint16_t kTpEnc[32 - 7] = { uint64_t tpenc(uint32_t c) { int e, n; uint64_t w; - if (0 <= c && c <= 127) return c; + if (0 <= c && c <= 127) + return c; e = kTpEnc[bsr(c) - 7]; n = e & 0xff; w = 0; diff --git a/libc/intrin/ubsan.c b/libc/intrin/ubsan.c index 5b3051ac5..35d9799e5 100644 --- a/libc/intrin/ubsan.c +++ b/libc/intrin/ubsan.c @@ -177,7 +177,8 @@ static char *__ubsan_itpcpy(char *p, struct UbsanTypeDescriptor *t, static size_t __ubsan_strlen(const char *s) { size_t i = 0; - while (s[i]) ++i; + while (s[i]) + ++i; return i; } @@ -208,7 +209,8 @@ static uintptr_t __ubsan_extend(struct UbsanTypeDescriptor *t, uintptr_t x) { } static wontreturn void __ubsan_unreachable(void) { - for (;;) abort(); + for (;;) + abort(); } static void __ubsan_exit(void) { @@ -314,7 +316,8 @@ static __ubsan_die_f *__ubsan_type_mismatch_handler( struct UbsanTypeMismatchInfo *info, uintptr_t pointer) { const char *kind; char buf[512], *p = buf; - if (!pointer) return __ubsan_abort(&info->location, "null pointer access"); + if (!pointer) + return __ubsan_abort(&info->location, "null pointer access"); kind = __ubsan_dubnul(kUbsanTypeCheckKinds, info->type_check_kind); if (info->alignment && (pointer & (info->alignment - 1))) { p = __ubsan_stpcpy(p, "unaligned "); diff --git a/libc/intrin/udivmodti4.c b/libc/intrin/udivmodti4.c index 8dfc565c4..fb996a0b7 100644 --- a/libc/intrin/udivmodti4.c +++ b/libc/intrin/udivmodti4.c @@ -52,7 +52,8 @@ forceinline du_int udiv128by64to64default(du_int u1, du_int u0, du_int v, while (q1 >= b || q1 * vn0 > b * rhat + un1) { q1 = q1 - 1; rhat = rhat + vn1; - if (rhat >= b) break; + if (rhat >= b) + break; } un21 = un64 * b + un1 - q1 * v; // Compute the second quotient digit. @@ -62,7 +63,8 @@ forceinline du_int udiv128by64to64default(du_int u1, du_int u0, du_int v, while (q0 >= b || q0 * vn0 > b * rhat + un0) { q0 = q0 - 1; rhat = rhat + vn1; - if (rhat >= b) break; + if (rhat >= b) + break; } *r = (un21 * b + un0 - q0 * v) >> s; return q1 * b + q0; @@ -92,7 +94,8 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem) { dividend.all = a; divisor.all = b; if (divisor.all > dividend.all) { - if (rem) *rem = dividend.all; + if (rem) + *rem = dividend.all; return 0; } // When the divisor fits in 64 bits, we can use an optimized path. @@ -111,7 +114,8 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem) { quotient.s.low = udiv128by64to64(dividend.s.high, dividend.s.low, divisor.s.low, &remainder.s.low); } - if (rem) *rem = remainder.all; + if (rem) + *rem = remainder.all; return quotient.all; } // 0 <= shift <= 63. @@ -132,7 +136,8 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem) { dividend.all -= divisor.all & s; divisor.all >>= 1; } - if (rem) *rem = dividend.all; + if (rem) + *rem = dividend.all; return quotient.all; } diff --git a/libc/intrin/unlockfileex.c b/libc/intrin/unlockfileex.c index 64aab4cee..46cc29248 100644 --- a/libc/intrin/unlockfileex.c +++ b/libc/intrin/unlockfileex.c @@ -39,7 +39,8 @@ bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved, bool32 ok; ok = __imp_UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE( "UnlockFileEx(%ld, %#x, %'zu, [%s]) → %hhhd% m", hFile, dwReserved, (uint64_t)nNumberOfBytesToUnlockHigh << 32 | nNumberOfBytesToUnlockLow, diff --git a/libc/intrin/unmapviewoffile.c b/libc/intrin/unmapviewoffile.c index 2479ad0b8..853893895 100644 --- a/libc/intrin/unmapviewoffile.c +++ b/libc/intrin/unmapviewoffile.c @@ -29,7 +29,8 @@ __msabi extern typeof(UnmapViewOfFile) *const __imp_UnmapViewOfFile; textwindows bool32 UnmapViewOfFile(const void *lpBaseAddress) { bool32 ok; ok = __imp_UnmapViewOfFile(lpBaseAddress); - if (!ok) __winerr(); + if (!ok) + __winerr(); NTTRACE("UnmapViewOfFile(%p) → %hhhd% m", lpBaseAddress, ok); return ok; } diff --git a/libc/intrin/unsetenv.c b/libc/intrin/unsetenv.c index 372c4358f..d96e1e4f4 100644 --- a/libc/intrin/unsetenv.c +++ b/libc/intrin/unsetenv.c @@ -33,7 +33,8 @@ int unsetenv(const char *s) { char **p; struct Env e; - if (!s || !*s || strchr(s, '=')) return einval(); + if (!s || !*s || strchr(s, '=')) + return einval(); if ((p = environ)) { e = __getenv(p, s); while (p[e.i]) { diff --git a/libc/intrin/virtualprotect.c b/libc/intrin/virtualprotect.c index 54e753065..55c97470c 100644 --- a/libc/intrin/virtualprotect.c +++ b/libc/intrin/virtualprotect.c @@ -33,7 +33,8 @@ textwindows bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t *lpflOldProtect) { bool32 bOk; bOk = __imp_VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect); - if (!bOk) __winerr(); + if (!bOk) + __winerr(); NTTRACE("VirtualProtect(%p, %'zu, %s, [%s]) → %hhhd% m", lpAddress, dwSize, DescribeNtPageFlags(flNewProtect), DescribeNtPageFlags(*lpflOldProtect), bOk); diff --git a/libc/intrin/wsagetoverlappedresult.c b/libc/intrin/wsagetoverlappedresult.c index 807c871ff..a9096ec8a 100644 --- a/libc/intrin/wsagetoverlappedresult.c +++ b/libc/intrin/wsagetoverlappedresult.c @@ -50,7 +50,8 @@ bool32 WSAGetOverlappedResult(uint64_t s, bool32 ok; ok = __imp_WSAGetOverlappedResult(s, lpOverlapped, out_lpcbTransfer, fWait, out_lpdwFlags); - if (!ok) __winsockerr(); + if (!ok) + __winsockerr(); NTTRACE("WSAGetOverlappedResult(%ld, %s, [%s], %hhhd, [%#x]) → %hhhd% lm", s, DescribeNtOverlapped(lpOverlapped), DescribeTransfer(alloca(16), ok, out_lpcbTransfer), fWait, diff --git a/libc/intrin/x86.c b/libc/intrin/x86.c index 7912d9de8..4328f9c82 100644 --- a/libc/intrin/x86.c +++ b/libc/intrin/x86.c @@ -630,22 +630,37 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, #define hasFeature(F) ((Features[F / 32] >> (F % 32)) & 1) #define setFeature(F) Features[F / 32] |= 1U << (F % 32) - if ((EDX >> 15) & 1) setFeature(FEATURE_CMOV); - if ((EDX >> 23) & 1) setFeature(FEATURE_MMX); - if ((EDX >> 25) & 1) setFeature(FEATURE_SSE); - if ((EDX >> 26) & 1) setFeature(FEATURE_SSE2); + if ((EDX >> 15) & 1) + setFeature(FEATURE_CMOV); + if ((EDX >> 23) & 1) + setFeature(FEATURE_MMX); + if ((EDX >> 25) & 1) + setFeature(FEATURE_SSE); + if ((EDX >> 26) & 1) + setFeature(FEATURE_SSE2); - if ((ECX >> 0) & 1) setFeature(FEATURE_SSE3); - if ((ECX >> 1) & 1) setFeature(FEATURE_PCLMUL); - if ((ECX >> 9) & 1) setFeature(FEATURE_SSSE3); - if ((ECX >> 12) & 1) setFeature(FEATURE_FMA); - if ((ECX >> 13) & 1) setFeature(FEATURE_CMPXCHG16B); - if ((ECX >> 19) & 1) setFeature(FEATURE_SSE4_1); - if ((ECX >> 20) & 1) setFeature(FEATURE_SSE4_2); - if ((ECX >> 22) & 1) setFeature(FEATURE_MOVBE); - if ((ECX >> 23) & 1) setFeature(FEATURE_POPCNT); - if ((ECX >> 25) & 1) setFeature(FEATURE_AES); - if ((ECX >> 29) & 1) setFeature(FEATURE_F16C); + if ((ECX >> 0) & 1) + setFeature(FEATURE_SSE3); + if ((ECX >> 1) & 1) + setFeature(FEATURE_PCLMUL); + if ((ECX >> 9) & 1) + setFeature(FEATURE_SSSE3); + if ((ECX >> 12) & 1) + setFeature(FEATURE_FMA); + if ((ECX >> 13) & 1) + setFeature(FEATURE_CMPXCHG16B); + if ((ECX >> 19) & 1) + setFeature(FEATURE_SSE4_1); + if ((ECX >> 20) & 1) + setFeature(FEATURE_SSE4_2); + if ((ECX >> 22) & 1) + setFeature(FEATURE_MOVBE); + if ((ECX >> 23) & 1) + setFeature(FEATURE_POPCNT); + if ((ECX >> 25) & 1) + setFeature(FEATURE_AES); + if ((ECX >> 29) & 1) + setFeature(FEATURE_F16C); // If CPUID indicates support for XSAVE, XRESTORE and AVX, and XGETBV // indicates that the AVX registers will be saved and restored on context @@ -663,36 +678,59 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, bool HasAVX512Save = HasAVX && ((EAX & 0xe0) == 0xe0); #endif - if (HasAVX) setFeature(FEATURE_AVX); + if (HasAVX) + setFeature(FEATURE_AVX); bool HasLeaf7 = MaxLeaf >= 0x7 && !getX86CpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX); if (HasLeaf7) { - if ((EBX >> 3) & 1) setFeature(FEATURE_BMI); - if (((EBX >> 5) & 1) && HasAVX) setFeature(FEATURE_AVX2); - if ((EBX >> 8) & 1) setFeature(FEATURE_BMI2); + if ((EBX >> 3) & 1) + setFeature(FEATURE_BMI); + if (((EBX >> 5) & 1) && HasAVX) + setFeature(FEATURE_AVX2); + if ((EBX >> 8) & 1) + setFeature(FEATURE_BMI2); if (HasAVX512Save) { - if ((EBX >> 16) & 1) setFeature(FEATURE_AVX512F); - if ((EBX >> 17) & 1) setFeature(FEATURE_AVX512DQ); - if ((EBX >> 21) & 1) setFeature(FEATURE_AVX512IFMA); - if ((EBX >> 26) & 1) setFeature(FEATURE_AVX512PF); - if ((EBX >> 27) & 1) setFeature(FEATURE_AVX512ER); - if ((EBX >> 28) & 1) setFeature(FEATURE_AVX512CD); - if ((EBX >> 30) & 1) setFeature(FEATURE_AVX512BW); - if ((EBX >> 31) & 1) setFeature(FEATURE_AVX512VL); - if ((ECX >> 1) & 1) setFeature(FEATURE_AVX512VBMI); - if ((ECX >> 6) & 1) setFeature(FEATURE_AVX512VBMI2); - if ((ECX >> 11) & 1) setFeature(FEATURE_AVX512VNNI); - if ((ECX >> 12) & 1) setFeature(FEATURE_AVX512BITALG); - if ((ECX >> 14) & 1) setFeature(FEATURE_AVX512VPOPCNTDQ); - if ((EDX >> 2) & 1) setFeature(FEATURE_AVX5124VNNIW); - if ((EDX >> 3) & 1) setFeature(FEATURE_AVX5124FMAPS); - if ((EDX >> 8) & 1) setFeature(FEATURE_AVX512VP2INTERSECT); - if ((EDX >> 23) & 1) setFeature(FEATURE_AVX512FP16); + if ((EBX >> 16) & 1) + setFeature(FEATURE_AVX512F); + if ((EBX >> 17) & 1) + setFeature(FEATURE_AVX512DQ); + if ((EBX >> 21) & 1) + setFeature(FEATURE_AVX512IFMA); + if ((EBX >> 26) & 1) + setFeature(FEATURE_AVX512PF); + if ((EBX >> 27) & 1) + setFeature(FEATURE_AVX512ER); + if ((EBX >> 28) & 1) + setFeature(FEATURE_AVX512CD); + if ((EBX >> 30) & 1) + setFeature(FEATURE_AVX512BW); + if ((EBX >> 31) & 1) + setFeature(FEATURE_AVX512VL); + if ((ECX >> 1) & 1) + setFeature(FEATURE_AVX512VBMI); + if ((ECX >> 6) & 1) + setFeature(FEATURE_AVX512VBMI2); + if ((ECX >> 11) & 1) + setFeature(FEATURE_AVX512VNNI); + if ((ECX >> 12) & 1) + setFeature(FEATURE_AVX512BITALG); + if ((ECX >> 14) & 1) + setFeature(FEATURE_AVX512VPOPCNTDQ); + if ((EDX >> 2) & 1) + setFeature(FEATURE_AVX5124VNNIW); + if ((EDX >> 3) & 1) + setFeature(FEATURE_AVX5124FMAPS); + if ((EDX >> 8) & 1) + setFeature(FEATURE_AVX512VP2INTERSECT); + if ((EDX >> 23) & 1) + setFeature(FEATURE_AVX512FP16); } - if ((ECX >> 8) & 1) setFeature(FEATURE_GFNI); - if (((ECX >> 10) & 1) && HasAVX) setFeature(FEATURE_VPCLMULQDQ); + if ((ECX >> 8) & 1) + setFeature(FEATURE_GFNI); + if (((ECX >> 10) & 1) && HasAVX) + setFeature(FEATURE_VPCLMULQDQ); } // EAX from subleaf 0 is the maximum subleaf supported. Some CPUs don't @@ -709,12 +747,18 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 && !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); if (HasExtLeaf1) { - if (ECX & 1) setFeature(FEATURE_LAHF_LM); - if ((ECX >> 5) & 1) setFeature(FEATURE_LZCNT); - if (((ECX >> 6) & 1)) setFeature(FEATURE_SSE4_A); - if (((ECX >> 11) & 1)) setFeature(FEATURE_XOP); - if (((ECX >> 16) & 1)) setFeature(FEATURE_FMA4); - if (((EDX >> 29) & 1)) setFeature(FEATURE_LM); + if (ECX & 1) + setFeature(FEATURE_LAHF_LM); + if ((ECX >> 5) & 1) + setFeature(FEATURE_LZCNT); + if (((ECX >> 6) & 1)) + setFeature(FEATURE_SSE4_A); + if (((ECX >> 11) & 1)) + setFeature(FEATURE_XOP); + if (((ECX >> 16) & 1)) + setFeature(FEATURE_FMA4); + if (((EDX >> 29) & 1)) + setFeature(FEATURE_LM); } if (hasFeature(FEATURE_LM) && hasFeature(FEATURE_SSE2)) { @@ -763,7 +807,8 @@ __attribute__((__constructor__(1))) textstartup int __cpu_indicator_init(void) { _Static_assert(sizeof(__cpu_features2) / sizeof(__cpu_features2[0]) == 3, ""); // This function needs to run just once. - if (__cpu_model.__cpu_vendor) return 0; + if (__cpu_model.__cpu_vendor) + return 0; if (!isCpuIdSupported() || getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1) { diff --git a/libc/irq/acpi-xsdt.c b/libc/irq/acpi-xsdt.c index 14c6acecf..eb91724f2 100644 --- a/libc/irq/acpi-xsdt.c +++ b/libc/irq/acpi-xsdt.c @@ -61,7 +61,8 @@ textstartup static void *_AcpiOsAllocatePages(size_t n) { struct DirectMap dm = sys_mmap_metal(NULL, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); void *addr = dm.addr; - if (addr == (void *)-1) addr = NULL; + if (addr == (void *)-1) + addr = NULL; return addr; } @@ -69,17 +70,20 @@ textstartup void *_AcpiOsAllocate(size_t n) { static _Atomic(char *) slack = NULL; char *addr = NULL; size_t align = __BIGGEST_ALIGNMENT__, use; - if (n >= 4096) return _AcpiOsAllocatePages(n); + if (n >= 4096) + return _AcpiOsAllocatePages(n); n = ROUNDUP(n, align); for (;;) { addr = atomic_exchange(&slack, NULL); if (!addr) { addr = _AcpiOsAllocatePages(4096); - if (!addr) return NULL; + if (!addr) + return NULL; } use = (uintptr_t)addr % 4096 + n; if (use <= 4096) { - if (use < 4096) atomic_store(&slack, addr + n); + if (use < 4096) + atomic_store(&slack, addr + n); return addr; } } @@ -87,14 +91,16 @@ textstartup void *_AcpiOsAllocate(size_t n) { textstartup static uint8_t _AcpiTbChecksum(const uint8_t *p, size_t n) { uint8_t c = 0; - while (n-- != 0) c += *p++; + while (n-- != 0) + c += *p++; return c; } textstartup static AcpiStatus _AcpiTbVerifyChecksum(const uint8_t *p, size_t n) { uint8_t sum = _AcpiTbChecksum(p, n); - if (!sum) return kAcpiOk; + if (!sum) + return kAcpiOk; KWARNF("bad ACPI table cksum %#x != 0 @ %p,+%#zx", (unsigned)sum, p, n); return kAcpiExBadChecksum; } @@ -103,8 +109,10 @@ textstartup static AcpiStatus _AcpiRsdpVerifyChecksums(const uint8_t *p) { const AcpiTableRsdp *q = (const AcpiTableRsdp *)p; size_t length = offsetof(AcpiTableRsdp, Length); AcpiStatus sta = _AcpiTbVerifyChecksum(p, length); - if (!_AcpiSuccess(sta)) return sta; - if (q->Revision <= 1) return kAcpiOk; + if (!_AcpiSuccess(sta)) + return sta; + if (q->Revision <= 1) + return kAcpiOk; length = q->Length; if (length < offsetof(AcpiTableRsdp, Reserved)) { KWARNF("malformed ACPI 2+ RSDP, length %#zx < %#zx", length, @@ -120,9 +128,11 @@ textstartup static AcpiStatus _AcpiRsdpVerifyChecksums(const uint8_t *p) { textstartup static bool _AcpiTbIsValidRsdp(const uint8_t *p) { const AcpiTableRsdp *q = (const AcpiTableRsdp *)p; - if (READ64LE(q->Signature) != READ64LE("RSD PTR ")) return false; + if (READ64LE(q->Signature) != READ64LE("RSD PTR ")) + return false; KINFOF("\"RSD PTR \" @ %p, ACPI rev %u", q, (unsigned)q->Revision); - if (!_AcpiSuccess(_AcpiRsdpVerifyChecksums(p))) return false; + if (!_AcpiSuccess(_AcpiRsdpVerifyChecksums(p))) + return false; return true; } @@ -133,7 +143,8 @@ textstartup static const AcpiTableRsdp *_AcpiFindRsdp(void) { uint64_t rsdp_phy = mm->pc_acpi_rsdp; uint16_t ebda_para; const uint8_t *area; - if (rsdp_phy) return _AcpiOsMapRoMemory(rsdp_phy, sizeof(AcpiTableRsdp)); + if (rsdp_phy) + return _AcpiOsMapRoMemory(rsdp_phy, sizeof(AcpiTableRsdp)); /* * "OSPM finds the Root System Description Pointer (RSDP) structure by * searching physical memory ranges on 16-byte boundaries for a valid @@ -231,8 +242,10 @@ textstartup AcpiStatus _AcpiGetTableImpl(uint32_t sig, uint32_t inst, size_t n = _AcpiXsdtNumEntries; while (n-- != 0) { AcpiTableHeader *h = *p++; - if (READ32LE(h->Signature) != sig) continue; - if (inst-- != 0) continue; + if (READ32LE(h->Signature) != sig) + continue; + if (inst-- != 0) + continue; *phdr = h; return kAcpiOk; } diff --git a/libc/log/attachdebugger.c b/libc/log/attachdebugger.c index e28fd0961..337f6c4e8 100644 --- a/libc/log/attachdebugger.c +++ b/libc/log/attachdebugger.c @@ -72,7 +72,8 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) { layout = "layout asm"; if ((elf = FindDebugBinary())) { se = "-se"; - if (fileexists(__FILE__)) layout = "layout src"; + if (fileexists(__FILE__)) + layout = "layout src"; } else { se = "-q"; elf = "-q"; diff --git a/libc/log/backtrace2.c b/libc/log/backtrace2.c index 97823309d..5c2f7c015 100644 --- a/libc/log/backtrace2.c +++ b/libc/log/backtrace2.c @@ -135,7 +135,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { sys_close(pipefds[1]); for (;;) { got = sys_read(pipefds[0], buf, kBacktraceBufSize); - if (!got) break; + if (!got) + break; if (got == -1 && errno == EINTR) { errno = 0; continue; @@ -150,7 +151,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { if ((p2 = memmem(p1, got, " (discriminator ", strlen(" (discriminator ") - 1)) && (p3 = memchr(p2, '\n', got - (p2 - p1)))) { - if (p3 > p2 && p3[-1] == '\r') --p3; + if (p3 > p2 && p3[-1] == '\r') + --p3; klog(p1, p2 - p1); got -= p3 - p1; p1 += p3 - p1; @@ -162,7 +164,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { } sys_close(pipefds[0]); while (sys_wait4(pid, &ws, 0, 0) == -1) { - if (errno == EINTR) continue; + if (errno == EINTR) + continue; return -1; } if (WIFEXITED(ws) && !WEXITSTATUS(ws)) { @@ -191,7 +194,8 @@ void ShowBacktrace(int fd, const struct StackFrame *bp) { /* asan runtime depends on this function */ ftrace_enabled(-1); strace_enabled(-1); - if (!bp) bp = __builtin_frame_address(0); + if (!bp) + bp = __builtin_frame_address(0); PrintBacktrace(fd, bp); strace_enabled(+1); ftrace_enabled(+1); diff --git a/libc/log/backtrace3.c b/libc/log/backtrace3.c index 1c0a4e5ea..6857d1d6f 100644 --- a/libc/log/backtrace3.c +++ b/libc/log/backtrace3.c @@ -51,7 +51,8 @@ dontinstrument dontasan int PrintBacktraceUsingSymbols( struct Garbages *garbage; const struct StackFrame *frame; (void)gi; - if (!bp) bp = __builtin_frame_address(0); + if (!bp) + bp = __builtin_frame_address(0); garbage = __tls_enabled ? __get_tls()->tib_garbages : 0; gi = garbage ? garbage->i : 0; for (i = 0, frame = bp; frame; frame = frame->next) { diff --git a/libc/log/checkaligned.c b/libc/log/checkaligned.c index 4dbbef7f2..f2750ed2a 100644 --- a/libc/log/checkaligned.c +++ b/libc/log/checkaligned.c @@ -26,7 +26,8 @@ void __check_fail_aligned(unsigned bytes, uint64_t ptr, const char *file, int line, const char *fmt, ...) { fflush(stderr); - if (!IsTiny()) _memsummary(fileno(stderr)); + if (!IsTiny()) + _memsummary(fileno(stderr)); kprintf("%s:%d: error: pointer not %d-byte aligned: %p\n", file, line, bytes, ptr); __die(); diff --git a/libc/log/checkfail_ndebug.c b/libc/log/checkfail_ndebug.c index a55fc29e4..a005b4198 100644 --- a/libc/log/checkfail_ndebug.c +++ b/libc/log/checkfail_ndebug.c @@ -48,7 +48,8 @@ static relegated wontreturn void __check_fail_ndebug(uint64_t want, // kvprintf(fmt, va); } kprintf("\n"); - if (_weaken(__die)) _weaken(__die)(); + if (_weaken(__die)) + _weaken(__die)(); _Exit(68); } diff --git a/libc/log/commandvenv.c b/libc/log/commandvenv.c index 6c25f8c9f..e028d89db 100644 --- a/libc/log/commandvenv.c +++ b/libc/log/commandvenv.c @@ -49,9 +49,11 @@ const char *commandvenv(const char *var, const char *cmd) { const char *exepath; static char pathbuf[PATH_MAX]; - if (*cmd == '/' || *cmd == '\\') return cmd; + if (*cmd == '/' || *cmd == '\\') + return cmd; if ((exepath = getenv(var))) { - if (isempty(exepath)) return NULL; + if (isempty(exepath)) + return NULL; if (access(exepath, X_OK) != -1) { return exepath; } else { diff --git a/libc/log/countbranch_report.c b/libc/log/countbranch_report.c index 7616c4e7a..a152dbc07 100644 --- a/libc/log/countbranch_report.c +++ b/libc/log/countbranch_report.c @@ -51,17 +51,22 @@ static int CompareCounters(const void *a, const void *b) { double x, y; x = RankCounter(a); y = RankCounter(b); - if (x > y) return +1; - if (x < y) return -1; - if (GetTotal(a) < GetTotal(b)) return +1; - if (GetTotal(a) > GetTotal(b)) return -1; + if (x > y) + return +1; + if (x < y) + return -1; + if (GetTotal(a) < GetTotal(b)) + return +1; + if (GetTotal(a) > GetTotal(b)) + return -1; return 0; } static size_t CountCounters(void) { size_t n; struct countbranch *p; - for (n = 0, p = countbranch_data; p->total >= 0; ++p) ++n; + for (n = 0, p = countbranch_data; p->total >= 0; ++p) + ++n; return n; } diff --git a/libc/log/countexpr_report.c b/libc/log/countexpr_report.c index 3d1c50025..75be60857 100644 --- a/libc/log/countexpr_report.c +++ b/libc/log/countexpr_report.c @@ -42,7 +42,8 @@ static long GetLongSum(const long *h, size_t n) { } static size_t GetRowCount(const long *h, size_t n) { - while (n && !h[n - 1]) --n; + while (n && !h[n - 1]) + --n; return n; } @@ -55,7 +56,8 @@ static void PrintHistogram(const long *h, size_t n, long t) { p = (h[i] * 10000 + (t >> 1)) / t; unassert(0 <= p && p <= 10000); if (p) { - for (j = 0; j < p / 100; ++j) s[j] = '#'; + for (j = 0; j < p / 100; ++j) + s[j] = '#'; s[j] = 0; logos = i ? 1ul << (i - 1) : 0; kprintf("%'12lu %'16ld %3d.%02d%% %s\n", logos, h[i], p / 100, p % 100, diff --git a/libc/log/gdbexec.c b/libc/log/gdbexec.c index f8d47f14e..0d63a9682 100644 --- a/libc/log/gdbexec.c +++ b/libc/log/gdbexec.c @@ -32,7 +32,8 @@ relegated int(gdbexec)(const char *cmd) { struct StackFrame *bp; const char *se, *elf, *gdb; char pidstr[11], breakcmd[40]; - if (!(gdb = GetGdbPath())) return -1; + if (!(gdb = GetGdbPath())) + return -1; snprintf(pidstr, sizeof(pidstr), "%u", getpid()); if ((elf = FindDebugBinary())) { se = "-se"; diff --git a/libc/log/getcallername.c b/libc/log/getcallername.c index fe1b3456f..7a4a719af 100644 --- a/libc/log/getcallername.c +++ b/libc/log/getcallername.c @@ -24,7 +24,9 @@ * Returns name of function that called caller function. */ const char *GetCallerName(const struct StackFrame *bp) { - if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next; - if (bp) return GetSymbolByAddr(bp->addr); + if (!bp && (bp = __builtin_frame_address(0))) + bp = bp->next; + if (bp) + return GetSymbolByAddr(bp->addr); return 0; } diff --git a/libc/log/leaks.c b/libc/log/leaks.c index eadff7292..02a2305d5 100644 --- a/libc/log/leaks.c +++ b/libc/log/leaks.c @@ -85,7 +85,8 @@ static dontasan bool HasLeaks(void) { */ dontasan void CheckForMemoryLeaks(void) { struct mallinfo mi; - if (!IsAsan()) return; // we need traces to exclude leaky + if (!IsAsan()) + return; // we need traces to exclude leaky if (!GetSymbolTable()) { kprintf("CheckForMemoryLeaks() needs the symbol table\n"); return; diff --git a/libc/log/memlog.c b/libc/log/memlog.c index c12bc1aa6..b6ea93df8 100644 --- a/libc/log/memlog.c +++ b/libc/log/memlog.c @@ -88,13 +88,17 @@ static long __memlog_size(void *p) { static void __memlog_backtrace(struct StackFrame *frame, intptr_t *a, intptr_t *b, intptr_t *c, intptr_t *d) { *a = *b = *c = *d = 0; - if (!frame) return; + if (!frame) + return; *a = frame->addr; - if (!(frame = frame->next)) return; + if (!(frame = frame->next)) + return; *b = frame->addr; - if (!(frame = frame->next)) return; + if (!(frame = frame->next)) + return; *c = frame->addr; - if (!(frame = frame->next)) return; + if (!(frame = frame->next)) + return; *d = frame->addr; } @@ -163,7 +167,8 @@ static void __memlog_log(struct StackFrame *frame, const char *op, void *res, static void __memlog_free(void *p) { long i, n; - if (!p) return; + if (!p) + return; __memlog_lock(); if ((i = __memlog_find(p)) != -1) { n = __memlog.allocs.p[i].size; diff --git a/libc/log/oncrash_amd64.c b/libc/log/oncrash_amd64.c index 06e155a15..dccb03682 100644 --- a/libc/log/oncrash_amd64.c +++ b/libc/log/oncrash_amd64.c @@ -120,7 +120,8 @@ relegated static dontinline char *DescribeCpuFlags(char *p, int flags, } static char *HexCpy(char p[hasatleast 17], uint64_t x, uint8_t k) { - while (k > 0) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; + while (k > 0) + *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15]; *p = '\0'; return p; } @@ -130,8 +131,10 @@ relegated static char *ShowGeneralRegisters(char *p, ucontext_t *ctx) { const char *s; *p++ = '\n'; for (i = 0, j = 0; i < ARRAYLEN(kGregNames); ++i) { - if (j > 0) *p++ = ' '; - if (!(s = kGregNames[(unsigned)kGregOrder[i]])[2]) *p++ = ' '; + if (j > 0) + *p++ = ' '; + if (!(s = kGregNames[(unsigned)kGregOrder[i]])[2]) + *p++ = ' '; p = stpcpy(p, s), *p++ = ' '; p = HexCpy(p, ctx->uc_mcontext.gregs[(unsigned)kGregOrder[i]], 64); if (++j == 3) { diff --git a/libc/log/oncrash_arm64.c b/libc/log/oncrash_arm64.c index eafc483fe..ba0ba4019 100644 --- a/libc/log/oncrash_arm64.c +++ b/libc/log/oncrash_arm64.c @@ -80,7 +80,8 @@ static relegated void Append(struct Buffer *b, const char *fmt, ...) { } static relegated const char *ColorRegister(int r) { - if (__nocolor) return ""; + if (__nocolor) + return ""; switch (r) { case 0: // arg / res case 1: // arg / res @@ -125,9 +126,12 @@ static relegated bool AppendFileLine(struct Buffer *b, const char *addr2line, ssize_t rc; char *p, *q, buf[128]; int j, k, ws, pid, pfd[2]; - if (!debugbin || !*debugbin) return false; - if (!addr2line || !*addr2line) return false; - if (sys_pipe(pfd)) return false; + if (!debugbin || !*debugbin) + return false; + if (!addr2line || !*addr2line) + return false; + if (sys_pipe(pfd)) + return false; ksnprintf(buf, sizeof(buf), "%lx", addr); if ((pid = vfork()) == -1) { sys_close(pfd[1]); @@ -261,7 +265,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si, Append(b, " "); for (j = 0; j < 4; ++j) { int r = 8 * j + i; - if (j) Append(b, " "); + if (j) + Append(b, " "); Append(b, "%s%016lx%s x%d%s", ColorRegister(r), ctx->uc_mcontext.regs[r], reset, r, r == 8 || r == 9 ? " " : ""); } @@ -272,12 +277,14 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si, vc = (struct fpsimd_context *)ctx->uc_mcontext.__reserved; if (vc->head.magic == FPSIMD_MAGIC) { int n = 16; - while (n && !vc->vregs[n - 1] && !vc->vregs[n - 2]) n -= 2; + while (n && !vc->vregs[n - 1] && !vc->vregs[n - 2]) + n -= 2; for (i = 0; i * 2 < n; ++i) { Append(b, " "); for (j = 0; j < 2; ++j) { int r = j + 2 * i; - if (j) Append(b, " "); + if (j) + Append(b, " "); Append(b, "%016lx ..%s %016lx v%d%s", (long)(vc->vregs[r] >> 64), !j ? "" : ".", (long)vc->vregs[r], r, r < 10 ? " " : ""); } @@ -297,7 +304,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si, Append(b, " "); if (!AppendFileLine(b, addr2line, debugbin, pc)) { Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz)); - if (addend) Append(b, "%+d", addend); + if (addend) + Append(b, "%+d", addend); } } Append(b, "\n"); @@ -318,7 +326,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si, Append(b, " "); if (!AppendFileLine(b, addr2line, debugbin, pc)) { Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz)); - if (addend) Append(b, "%+d", addend); + if (addend) + Append(b, "%+d", addend); } } Append(b, "\n"); @@ -357,7 +366,8 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si, Append(b, " %016lx fp %lx lr ", fp, pc); if (!AppendFileLine(b, addr2line, debugbin, pc) && st) { Append(b, "%s", GetSymbolName(st, symbol, &mem, &memsz)); - if (addend) Append(b, "%+d", addend); + if (addend) + Append(b, "%+d", addend); } Append(b, "\n"); } diff --git a/libc/log/printwindowsmemory.c b/libc/log/printwindowsmemory.c index 18116fc75..9ec34dd57 100644 --- a/libc/log/printwindowsmemory.c +++ b/libc/log/printwindowsmemory.c @@ -62,7 +62,8 @@ void PrintWindowsMemory(const char *high, size_t size) { for (p = 0;; p = (char *)mi.BaseAddress + mi.RegionSize) { const char *start, *stop; bzero(&mi, sizeof(mi)); - if (!VirtualQuery(p, &mi, sizeof(mi))) break; + if (!VirtualQuery(p, &mi, sizeof(mi))) + break; sizefmt(b[0], mi.RegionSize, 1024); if (MAX(high, (char *)mi.BaseAddress) < MIN(high + size, (char *)mi.BaseAddress + mi.RegionSize)) { diff --git a/libc/log/vflogf.c b/libc/log/vflogf.c index c75bae727..9dedc9283 100644 --- a/libc/log/vflogf.c +++ b/libc/log/vflogf.c @@ -50,7 +50,8 @@ static struct timespec vflogf_ts; static void vflogf_onfail(FILE *f) { errno_t err; struct stat st; - if (IsTiny()) return; + if (IsTiny()) + return; err = ferror_unlocked(f); if (fileno_unlocked(f) != -1 && (err == ENOSPC || err == EDQUOT || err == EFBIG) && @@ -90,8 +91,10 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, const char *prog; const char *sign; struct timespec t2; - if (!f) f = __log_file; - if (!f) return; + if (!f) + f = __log_file; + if (!f) + return; flockfile(f); strace_enabled(-1); BLOCK_SIGNALS; @@ -113,7 +116,8 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, strcpy(iso8601(buf32, &tm), sign); prog = basename(firstnonnull(program_invocation_name, "unknown")); bufmode = f->bufmode; - if (bufmode == _IOLBF) f->bufmode = _IOFBF; + if (bufmode == _IOLBF) + f->bufmode = _IOFBF; if ((fprintf_unlocked)(f, "%r%c%s%06ld:%s:%d:%.*s:%d] ", "FEWIVDNT"[level & 7], buf32, dots / 1000, file, line, diff --git a/libc/log/watch.c b/libc/log/watch.c index b7048f608..a3d4105ef 100644 --- a/libc/log/watch.c +++ b/libc/log/watch.c @@ -41,8 +41,10 @@ static dontinstrument inline void Copy(char *p, char *q, size_t n) { } static dontinstrument inline int Cmp(char *p, char *q, size_t n) { - if (n == 8) return READ64LE(p) != READ64LE(q); - if (n == 4) return READ32LE(p) != READ32LE(q); + if (n == 8) + return READ64LE(p) != READ64LE(q); + if (n == 4) + return READ32LE(p) != READ32LE(q); for (; n; ++p, ++q, --n) { if (*p != *q) { return 1; @@ -52,7 +54,8 @@ static dontinstrument inline int Cmp(char *p, char *q, size_t n) { } dontinstrument void __watcher(void) { - if (__watch_busy) return; + if (__watch_busy) + return; __watch_busy = true; if (Cmp(__watch_last, __watch_addr, __watch_size)) { kprintf("watchpoint %p changed:\n" @@ -74,11 +77,15 @@ dontinstrument void __watcher(void) { */ int __watch(void *addr, size_t size) { static bool once; - if (__watch_busy) ebusy(); - if (size > sizeof(__watch_last)) return einval(); + if (__watch_busy) + ebusy(); + if (size > sizeof(__watch_last)) + return einval(); if (!once) { - if (!GetSymbolTable()) return -1; - if (__hook(__watch_hook, GetSymbolTable()) == -1) return -1; + if (!GetSymbolTable()) + return -1; + if (__hook(__watch_hook, GetSymbolTable()) == -1) + return -1; once = true; } __watch_addr = addr; diff --git a/libc/mem/critbit0_allprefixed.c b/libc/mem/critbit0_allprefixed.c index b032e4a09..e8cc832ee 100644 --- a/libc/mem/critbit0_allprefixed.c +++ b/libc/mem/critbit0_allprefixed.c @@ -27,7 +27,8 @@ static intptr_t allprefixed_traverse(unsigned char *top, struct CritbitNode *q = (void *)(top - 1); for (int direction = 0; direction < 2; ++direction) { intptr_t rc = allprefixed_traverse(q->child[direction], callback, arg); - if (rc) return rc; + if (rc) + return rc; } return 0; } @@ -48,14 +49,17 @@ intptr_t critbit0_allprefixed(struct critbit0 *t, const char *prefix, const size_t ulen = strlen(prefix); unsigned char *p = t->root; unsigned char *top = p; - if (!p) return 0; + if (!p) + return 0; while (1 & (intptr_t)p) { struct CritbitNode *q = (void *)(p - 1); unsigned char c = 0; - if (q->byte < ulen) c = ubytes[q->byte]; + if (q->byte < ulen) + c = ubytes[q->byte]; const int direction = (1 + (q->otherbits | c)) >> 8; p = q->child[direction]; - if (q->byte < ulen) top = p; + if (q->byte < ulen) + top = p; } for (size_t i = 0; i < ulen; ++i) { if (p[i] != ubytes[i]) { diff --git a/libc/mem/critbit0_contains.c b/libc/mem/critbit0_contains.c index 152561e14..e750d4252 100644 --- a/libc/mem/critbit0_contains.c +++ b/libc/mem/critbit0_contains.c @@ -30,11 +30,13 @@ bool critbit0_contains(struct critbit0 *t, const char *u) { const unsigned char *ubytes = (void *)u; const size_t ulen = strlen(u); unsigned char *p = t->root; - if (!p) return 0; + if (!p) + return 0; while (1 & (intptr_t)p) { struct CritbitNode *q = (void *)(p - 1); unsigned char c = 0; - if (q->byte < ulen) c = ubytes[q->byte]; + if (q->byte < ulen) + c = ubytes[q->byte]; const int direction = (1 + (q->otherbits | c)) >> 8; p = q->child[direction]; } diff --git a/libc/mem/critbit0_delete.c b/libc/mem/critbit0_delete.c index 3925c7fbb..ef3dd2c90 100644 --- a/libc/mem/critbit0_delete.c +++ b/libc/mem/critbit0_delete.c @@ -36,17 +36,20 @@ bool critbit0_delete(struct critbit0 *t, const char *u) { void **whereq = 0; struct CritbitNode *q = 0; int direction = 0; - if (!p) return false; + if (!p) + return false; while (1 & (intptr_t)p) { whereq = wherep; q = (void *)(p - 1); unsigned char c = 0; - if (q->byte < ulen) c = ubytes[q->byte]; + if (q->byte < ulen) + c = ubytes[q->byte]; direction = (1 + (q->otherbits | c)) >> 8; wherep = q->child + direction; p = *wherep; } - if (0 != strcmp(u, (const char *)p)) return false; + if (0 != strcmp(u, (const char *)p)) + return false; free(p), p = NULL; if (!whereq) { t->root = NULL; diff --git a/libc/mem/critbit0_emplace.c b/libc/mem/critbit0_emplace.c index 3b235262b..63b076e56 100644 --- a/libc/mem/critbit0_emplace.c +++ b/libc/mem/critbit0_emplace.c @@ -53,7 +53,8 @@ int critbit0_emplace(struct critbit0 *t, const void *u, size_t ulen) { while (1 & (intptr_t)p) { struct CritbitNode *q = (void *)(p - 1); unsigned char c = 0; - if (q->byte < ulen) c = ubytes[q->byte]; + if (q->byte < ulen) + c = ubytes[q->byte]; const int direction = (1 + (q->otherbits | c)) >> 8; p = q->child[direction]; } @@ -86,12 +87,16 @@ DifferentByteFound: void **wherep = &t->root; for (;;) { unsigned char *wp = *wherep; - if (!(1 & (intptr_t)wp)) break; + if (!(1 & (intptr_t)wp)) + break; struct CritbitNode *q = (void *)(wp - 1); - if (q->byte > newbyte) break; - if (q->byte == newbyte && q->otherbits > newotherbits) break; + if (q->byte > newbyte) + break; + if (q->byte == newbyte && q->otherbits > newotherbits) + break; unsigned char c2 = 0; - if (q->byte < ulen) c2 = ubytes[q->byte]; + if (q->byte < ulen) + c2 = ubytes[q->byte]; const int direction = (1 + (q->otherbits | c2)) >> 8; wherep = q->child + direction; } diff --git a/libc/mem/critbit0_get.c b/libc/mem/critbit0_get.c index 7a3b5a141..93f461471 100644 --- a/libc/mem/critbit0_get.c +++ b/libc/mem/critbit0_get.c @@ -31,11 +31,13 @@ char *critbit0_get(struct critbit0 *t, const char *u) { const unsigned char *ubytes = (void *)u; const size_t ulen = strlen(u); unsigned char *p = t->root; - if (!p) return 0; + if (!p) + return 0; while (1 & (intptr_t)p) { struct CritbitNode *q = (void *)(p - 1); unsigned char c = 0; - if (q->byte < ulen) c = ubytes[q->byte]; + if (q->byte < ulen) + c = ubytes[q->byte]; const int direction = (1 + (q->otherbits | c)) >> 8; p = q->child[direction]; } diff --git a/libc/mem/gc.c b/libc/mem/gc.c index 07957ba57..1ef55198c 100644 --- a/libc/mem/gc.c +++ b/libc/mem/gc.c @@ -65,10 +65,12 @@ static void DeferFunction(struct StackFrame *frame, void *fn, void *arg) { t = __get_tls(); g = t->tib_garbages; if (UNLIKELY(!g)) { - if (!(g = malloc(sizeof(struct Garbages)))) notpossible; + if (!(g = malloc(sizeof(struct Garbages)))) + notpossible; g->i = 0; g->n = 4; - if (!(g->p = malloc(g->n * sizeof(struct Garbage)))) notpossible; + if (!(g->p = malloc(g->n * sizeof(struct Garbage)))) + notpossible; t->tib_garbages = g; } else if (UNLIKELY(g->i == g->n)) { p2 = g->p; diff --git a/libc/mem/putenv.c b/libc/mem/putenv.c index 00a9553b7..d135a3f9a 100644 --- a/libc/mem/putenv.c +++ b/libc/mem/putenv.c @@ -30,14 +30,16 @@ static size_t capacity; static size_t __lenenv(char **env) { char **p = env; - while (*p) ++p; + while (*p) + ++p; return p - env; } static char **__growenv(char **a) { size_t n, c; char **b, **p; - if (!a) a = environ; + if (!a) + a = environ; n = a ? __lenenv(a) : 0; c = MAX(8ul, n) << 1; if ((b = malloc(c * sizeof(char *)))) { diff --git a/libc/mem/setenv.c b/libc/mem/setenv.c index ff198e945..64c7620ab 100644 --- a/libc/mem/setenv.c +++ b/libc/mem/setenv.c @@ -37,7 +37,8 @@ int setenv(const char *name, const char *value, int overwrite) { int rc; char *s; size_t n, m; - if (!name || !*name || !value || strchr(name, '=')) return einval(); + if (!name || !*name || !value || strchr(name, '=')) + return einval(); if ((s = malloc((n = strlen(name)) + 1 + (m = strlen(value)) + 1))) { memcpy(mempcpy(mempcpy(s, name, n), "=", 1), value, m + 1); rc = __putenv(s, overwrite); diff --git a/libc/mem/strndup.c b/libc/mem/strndup.c index b1ddc3383..45d0dee03 100644 --- a/libc/mem/strndup.c +++ b/libc/mem/strndup.c @@ -31,7 +31,8 @@ char *strndup(const char *s, size_t n) { char *s2; size_t len = strnlen(s, n); if ((s2 = malloc(len + 1))) { - if (len) memcpy(s2, s, len); + if (len) + memcpy(s2, s, len); s2[len] = '\0'; return s2; } diff --git a/libc/proc/cocmd.c b/libc/proc/cocmd.c index fe0297460..59aba86cc 100644 --- a/libc/proc/cocmd.c +++ b/libc/proc/cocmd.c @@ -130,7 +130,8 @@ static void PutEnv(char **p, char *kv) { struct Env e; e = __getenv(p, kv); p[e.i] = kv; - if (!e.s) p[e.i + 1] = 0; + if (!e.s) + p[e.i + 1] = 0; } static void UnsetEnv(char **p, const char *k) { @@ -330,7 +331,8 @@ static int CatDump(const char *path, int fd, bool dontclose) { } return 1; } - if (!rc) break; + if (!rc) + break; rc = write(1, buf, rc); if (rc == -1) { perror("write"); @@ -392,18 +394,21 @@ static int Read(void) { unsigned char c; int i, j, rc = 1; for (i = 1; i < n; ++i) { - if (args[i][0] != '-') break; + if (args[i][0] != '-') + break; if (args[i][1] == 'p' && !args[i][2] && i + 1 < n) { Write(1, args[++i]); } } - if (i >= n) return 1; + if (i >= n) + return 1; for (j = 0; args[i][j]; ++j) { Append(args[i][j]); } Append('='); while (read(0, &c, 1) > 0) { - if (c == '\n') break; + if (c == '\n') + break; Append(c); rc = 0; } @@ -469,7 +474,8 @@ static int Kill(void) { int sig, rc = 0, i = 1; if (i < n && args[i][0] == '-') { sig = GetSignalByName(args[i++] + 1); - if (!sig) return -1; // fallback to system kill command + if (!sig) + return -1; // fallback to system kill command } else { sig = SIGTERM; } @@ -510,20 +516,30 @@ static int Usleep(void) { static int Test(void) { int w, m = n; struct stat st; - if (m && READ16LE(args[m - 1]) == READ16LE("]")) --m; + if (m && READ16LE(args[m - 1]) == READ16LE("]")) + --m; if (m == 4) { w = READ32LE(args[2]) & 0x00ffffff; - if ((w & 65535) == READ16LE("=")) return !!strcmp(args[1], args[3]); - if (w == READ24("==")) return !!strcmp(args[1], args[3]); - if (w == READ24("!=")) return !strcmp(args[1], args[3]); + if ((w & 65535) == READ16LE("=")) + return !!strcmp(args[1], args[3]); + if (w == READ24("==")) + return !!strcmp(args[1], args[3]); + if (w == READ24("!=")) + return !strcmp(args[1], args[3]); } else if (m == 3) { w = READ32LE(args[1]) & 0x00ffffff; - if (w == READ24("-n")) return !(strlen(args[2]) > 0); - if (w == READ24("-z")) return !(strlen(args[2]) == 0); - if (w == READ24("-e")) return !!stat(args[2], &st); - if (w == READ24("-f")) return !(!stat(args[2], &st) && S_ISREG(st.st_mode)); - if (w == READ24("-d")) return !(!stat(args[2], &st) && S_ISDIR(st.st_mode)); - if (w == READ24("-h")) return !(!stat(args[2], &st) && S_ISLNK(st.st_mode)); + if (w == READ24("-n")) + return !(strlen(args[2]) > 0); + if (w == READ24("-z")) + return !(strlen(args[2]) == 0); + if (w == READ24("-e")) + return !!stat(args[2], &st); + if (w == READ24("-f")) + return !(!stat(args[2], &st) && S_ISREG(st.st_mode)); + if (w == READ24("-d")) + return !(!stat(args[2], &st) && S_ISDIR(st.st_mode)); + if (w == READ24("-h")) + return !(!stat(args[2], &st) && S_ISLNK(st.st_mode)); } return -1; // fall back to system test command } @@ -558,7 +574,8 @@ static int Rm(void) { if ((!force && (lstat(args[i], &st) || (!S_ISLNK(st.st_mode) && access(args[i], W_OK)))) || unlink(args[i])) { - if (force && errno == ENOENT) continue; + if (force && errno == ENOENT) + continue; perror(args[i]); return 1; } @@ -675,31 +692,56 @@ static wontreturn void Exec(void) { } static int TryBuiltin(bool wantexec) { - if (!n) return exitstatus; - if (!strcmp(args[0], "exit")) Exit(); - if (!strcmp(args[0], "exec")) Exec(); - if (!strcmp(args[0], "cd")) return Cd(); - if (!strcmp(args[0], "rm")) return Rm(); - if (!strcmp(args[0], "[")) return Test(); - if (!strcmp(args[0], "cat")) return Cat(); - if (!strcmp(args[0], "env")) return Env(); - if (!strcmp(args[0], "pwd")) return Pwd(); - if (!strcmp(args[0], "wait")) return Wait(); - if (!strcmp(args[0], "echo")) return Echo(); - if (!strcmp(args[0], "read")) return Read(); - if (!strcmp(args[0], "true")) return True(); - if (!strcmp(args[0], "test")) return Test(); - if (!strcmp(args[0], "kill")) return Kill(); - if (!strcmp(args[0], "pause")) return Pause(); - if (!strcmp(args[0], "flock")) return Flock(); - if (!strcmp(args[0], "chmod")) return Chmod(); - if (!strcmp(args[0], "touch")) return Touch(); - if (!strcmp(args[0], "rmdir")) return Rmdir(); - if (!strcmp(args[0], "mkdir")) return Mkdir(); - if (!strcmp(args[0], "false")) return False(); - if (!strcmp(args[0], "mktemp")) return Mktemp(); - if (!strcmp(args[0], "usleep")) return Usleep(); - if (!strcmp(args[0], "toupper")) return Toupper(); + if (!n) + return exitstatus; + if (!strcmp(args[0], "exit")) + Exit(); + if (!strcmp(args[0], "exec")) + Exec(); + if (!strcmp(args[0], "cd")) + return Cd(); + if (!strcmp(args[0], "rm")) + return Rm(); + if (!strcmp(args[0], "[")) + return Test(); + if (!strcmp(args[0], "cat")) + return Cat(); + if (!strcmp(args[0], "env")) + return Env(); + if (!strcmp(args[0], "pwd")) + return Pwd(); + if (!strcmp(args[0], "wait")) + return Wait(); + if (!strcmp(args[0], "echo")) + return Echo(); + if (!strcmp(args[0], "read")) + return Read(); + if (!strcmp(args[0], "true")) + return True(); + if (!strcmp(args[0], "test")) + return Test(); + if (!strcmp(args[0], "kill")) + return Kill(); + if (!strcmp(args[0], "pause")) + return Pause(); + if (!strcmp(args[0], "flock")) + return Flock(); + if (!strcmp(args[0], "chmod")) + return Chmod(); + if (!strcmp(args[0], "touch")) + return Touch(); + if (!strcmp(args[0], "rmdir")) + return Rmdir(); + if (!strcmp(args[0], "mkdir")) + return Mkdir(); + if (!strcmp(args[0], "false")) + return False(); + if (!strcmp(args[0], "mktemp")) + return Mktemp(); + if (!strcmp(args[0], "usleep")) + return Usleep(); + if (!strcmp(args[0], "toupper")) + return Toupper(); if (_weaken(_tr) && !strcmp(args[0], "tr")) { return Fake(_weaken(_tr), wantexec); } @@ -736,13 +778,17 @@ static void Pipe(void) { if (!pid) { unassert(dup2(pfds[1], 1) == 1); // we can't rely on cloexec because builtins - if (pfds[0] != 1) unassert(!close(pfds[0])); - if (pfds[1] != 1) unassert(!close(pfds[1])); + if (pfds[0] != 1) + unassert(!close(pfds[0])); + if (pfds[1] != 1) + unassert(!close(pfds[1])); _Exit(ShellExec()); } unassert(dup2(pfds[0], 0) == 0); - if (pfds[0] != 0) unassert(!close(pfds[0])); - if (pfds[1] != 0) unassert(!close(pfds[1])); + if (pfds[0] != 0) + unassert(!close(pfds[0])); + if (pfds[1] != 0) + unassert(!close(pfds[1])); n = 0; } @@ -837,7 +883,8 @@ static char *Tokenize(void) { switch (t) { case STATE_WHITESPACE: - if (!*p) return 0; + if (!*p) + return 0; if (*p == ' ' || *p == '\t' || *p == '\n' || (p[0] == '\\' && p[1] == '\n')) { continue; @@ -859,10 +906,12 @@ static char *Tokenize(void) { t = STATE_VAR; var[(vari = 0)] = 0; } else if (*p == '\\') { - if (!p[1]) UnsupportedSyntax(*p); + if (!p[1]) + UnsupportedSyntax(*p); Append(*++p); } else if (*p == '=') { - if (!n && q > r) assign = r; + if (!n && q > r) + assign = r; Append(*p); } else if (*p == '|') { if (q > r) { @@ -914,11 +963,13 @@ static char *Tokenize(void) { case STATE_VAR: // XXX: we need to find a simple elegant way to break up // unquoted variable expansions into multiple args. - if (CopyVar()) t = STATE_CMD, --p; + if (CopyVar()) + t = STATE_CMD, --p; break; case STATE_SINGLE: - if (!*p) goto UnterminatedString; + if (!*p) + goto UnterminatedString; if (*p == '\'') { t = STATE_CMD; } else { @@ -931,12 +982,15 @@ static char *Tokenize(void) { _Exit(6); case STATE_QUOTED_VAR: - if (!*p) goto UnterminatedString; - if (CopyVar()) t = STATE_QUOTED, --p; + if (!*p) + goto UnterminatedString; + if (CopyVar()) + t = STATE_QUOTED, --p; break; case STATE_QUOTED: - if (!*p) goto UnterminatedString; + if (!*p) + goto UnterminatedString; if (*p == '"') { t = STATE_CMD; } else if (p[0] == '$') { @@ -1044,7 +1098,8 @@ int _cocmd(int argc, char **argv, char **envp) { n = 0; r = q = argbuf; while ((arg = Tokenize())) { - if (arg == TOMBSTONE) continue; + if (arg == TOMBSTONE) + continue; if (n + 1 < ARRAYLEN(args)) { if (isdigit(arg[0]) && arg[1] == '>' && arg[2] == '&' && isdigit(arg[3])) { diff --git a/libc/proc/describefds.c b/libc/proc/describefds.c index 990ccc68a..71d36c17f 100644 --- a/libc/proc/describefds.c +++ b/libc/proc/describefds.c @@ -42,13 +42,20 @@ struct StringBuilder { // returns true if fd can't be inherited by anything textwindows bool __is_cloexec(const struct Fd *f) { - if (f->kind == kFdEmpty) return true; - if (f->kind == kFdReserved) return true; - if (f->kind == kFdZip) return true; - if (f->kind == kFdEpoll) return true; - if (f->flags & O_CLOEXEC) return true; - if (f->handle == -1) return true; - if (!f->handle) return true; + if (f->kind == kFdEmpty) + return true; + if (f->kind == kFdReserved) + return true; + if (f->kind == kFdZip) + return true; + if (f->kind == kFdEpoll) + return true; + if (f->flags & O_CLOEXEC) + return true; + if (f->handle == -1) + return true; + if (!f->handle) + return true; return false; } @@ -81,14 +88,16 @@ textwindows char *__describe_fds(const struct Fd *fds, size_t fdslen, uint32_t handlecount = 0; // setup memory for environment variable - if (!(sb.p = strdup(FDS_VAR))) return 0; + if (!(sb.p = strdup(FDS_VAR))) + return 0; sb.i = sizeof(FDS_VAR) - 1; sb.n = sizeof(FDS_VAR); // setup memory for explicitly inherited handle list for (int fd = 0; fd < fdslen; ++fd) { const struct Fd *f = fds + fd; - if (__is_cloexec(f)) continue; + if (__is_cloexec(f)) + continue; ++handlecount; } if (!(handles = calloc(handlecount, sizeof(*handles)))) { @@ -101,7 +110,8 @@ textwindows char *__describe_fds(const struct Fd *fds, size_t fdslen, // serialize file descriptors for (int fd = 0; fd < fdslen; ++fd) { const struct Fd *f = fds + fd; - if (__is_cloexec(f)) continue; + if (__is_cloexec(f)) + continue; // make inheritable version of handle exist in creator process if (!DuplicateHandle(GetCurrentProcess(), f->handle, hCreatorProcess, diff --git a/libc/proc/execl.c b/libc/proc/execl.c index b085fb0b6..3aba82c02 100644 --- a/libc/proc/execl.c +++ b/libc/proc/execl.c @@ -40,19 +40,22 @@ int execl(const char *exe, const char *arg, ... /*, NULL*/) { va_list va, vb; va_copy(vb, va); va_start(va, arg); - for (i = 0; va_arg(va, const char *); ++i) donothing; + for (i = 0; va_arg(va, const char *); ++i) + donothing; va_end(va); #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = (i + 2) * sizeof(char *); - if (__get_safe_size(nbytes, 4096) < nbytes) return enomem(); + if (__get_safe_size(nbytes, 4096) < nbytes) + return enomem(); char **argv = alloca(nbytes); CheckLargeStackAllocation(argv, nbytes); #pragma GCC pop_options va_start(vb, arg); argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, char *))) break; + if (!(argv[i] = va_arg(vb, char *))) + break; } va_end(vb); return execv(exe, argv); diff --git a/libc/proc/execle.c b/libc/proc/execle.c index 804ad8c29..d197864f9 100644 --- a/libc/proc/execle.c +++ b/libc/proc/execle.c @@ -43,20 +43,23 @@ int execle(const char *exe, const char *arg, char **argv, **envp; va_copy(vb, va); va_start(va, arg); - for (i = 0; va_arg(va, const char *); ++i) donothing; + for (i = 0; va_arg(va, const char *); ++i) + donothing; envp = va_arg(va, char **); va_end(va); #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = (i + 2) * sizeof(char *); - if (__get_safe_size(nbytes, 4096) < nbytes) return enomem(); + if (__get_safe_size(nbytes, 4096) < nbytes) + return enomem(); argv = alloca(nbytes); CheckLargeStackAllocation(argv, nbytes); #pragma GCC pop_options va_start(vb, arg); argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, char *))) break; + if (!(argv[i] = va_arg(vb, char *))) + break; } va_end(vb); return execve(exe, argv, envp); diff --git a/libc/proc/execlp.c b/libc/proc/execlp.c index 5d94555a6..d90b4afbd 100644 --- a/libc/proc/execlp.c +++ b/libc/proc/execlp.c @@ -47,19 +47,22 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) { // turn varargs into array va_copy(vb, va); va_start(va, arg); - for (i = 0; va_arg(va, const char *); ++i) (void)0; + for (i = 0; va_arg(va, const char *); ++i) + (void)0; va_end(va); #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = (i + 2) * sizeof(char *); - if (__get_safe_size(nbytes, 4096) < nbytes) return enomem(); + if (__get_safe_size(nbytes, 4096) < nbytes) + return enomem(); argv = alloca(nbytes); CheckLargeStackAllocation(argv, nbytes); #pragma GCC pop_options va_start(vb, arg); argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, char *))) break; + if (!(argv[i] = va_arg(vb, char *))) + break; } va_end(vb); diff --git a/libc/proc/execve-sysv.c b/libc/proc/execve-sysv.c index 618b5c295..93c22f8c0 100644 --- a/libc/proc/execve-sysv.c +++ b/libc/proc/execve-sysv.c @@ -109,12 +109,14 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) { // allocate memory int argc; - for (argc = 0; argv[argc];) ++argc; + for (argc = 0; argv[argc];) + ++argc; #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = (argc + 4) * sizeof(char *); int ntotal = nbytes + PATH_MAX; - if (__get_safe_size(ntotal, 4096) < ntotal) return enomem(); + if (__get_safe_size(ntotal, 4096) < ntotal) + return enomem(); char **shargs = alloca(nbytes); CheckLargeStackAllocation(shargs, nbytes); #pragma GCC pop_options diff --git a/libc/proc/execvpe.c b/libc/proc/execvpe.c index f87a595fe..d748e47f8 100644 --- a/libc/proc/execvpe.c +++ b/libc/proc/execvpe.c @@ -64,11 +64,13 @@ int execvpe(const char *prog, char *const argv[], char *const *envp) { // change argv[0] to resolved path if it's ambiguous // otherwise the program won't have much luck finding itself if (argv[0] && *prog != '/' && *exe == '/' && !strcmp(prog, argv[0])) { - for (i = 0; argv[i++];) (void)0; + for (i = 0; argv[i++];) + (void)0; #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = i * sizeof(*argv); - if (__get_safe_size(nbytes, 4096) < nbytes) return enomem(); + if (__get_safe_size(nbytes, 4096) < nbytes) + return enomem(); argv2 = alloca(nbytes); CheckLargeStackAllocation(argv2, nbytes); #pragma GCC pop_options diff --git a/libc/proc/fexecve.c b/libc/proc/fexecve.c index 052027508..085d0c98a 100644 --- a/libc/proc/fexecve.c +++ b/libc/proc/fexecve.c @@ -232,7 +232,8 @@ int fexecve(int fd, char *const argv[], char *const envp[]) { break; } size_t numenvs; - for (numenvs = 0; envp[numenvs];) ++numenvs; + for (numenvs = 0; envp[numenvs];) + ++numenvs; // const size_t desenvs = min(500, max(numenvs + 1, 2)); static _Thread_local char *envs[500]; memcpy(envs, envp, numenvs * sizeof(char *)); diff --git a/libc/proc/fork-nt.c b/libc/proc/fork-nt.c index dac6300cb..4ef781c2c 100644 --- a/libc/proc/fork-nt.c +++ b/libc/proc/fork-nt.c @@ -69,7 +69,8 @@ static textwindows wontreturn void AbortFork(const char *func) { static textwindows char16_t *ParseInt(char16_t *p, int64_t *x) { *x = 0; - while (*p == ' ') p++; + while (*p == ' ') + p++; while ('0' <= *p && *p <= '9') { *x *= 10; *x += *p++ - '0'; @@ -97,7 +98,8 @@ static dontinline textwindows bool ForkIo2(int64_t h, void *buf, size_t n, struct NtOverlapped *), const char *sf, bool ischild) { ssize_t rc = ForkIo(h, buf, n, fn); - if (ischild) __tls_enabled_set(false); // prevent tls crash in kprintf + if (ischild) + __tls_enabled_set(false); // prevent tls crash in kprintf NTTRACE("%s(%ld, %p, %'zu) → %'zd% m", sf, h, buf, n, rc); return rc != -1; } @@ -106,7 +108,8 @@ static dontinline textwindows bool WriteAll(int64_t h, void *buf, size_t n) { bool ok; ok = ForkIo2(h, buf, n, (void *)WriteFile, "WriteFile", false); #ifndef NDEBUG - if (ok) ok = ForkIo2(h, &n, sizeof(n), (void *)WriteFile, "WriteFile", false); + if (ok) + ok = ForkIo2(h, &n, sizeof(n), (void *)WriteFile, "WriteFile", false); #endif #if SYSDEBUG if (!ok) { @@ -195,7 +198,8 @@ textwindows void WinMainForked(void) { // check to see if the process was actually forked // this variable should have the pipe handle numba varlen = GetEnvironmentVariable(u"_FORK", fvar, ARRAYLEN(fvar)); - if (!varlen || varlen >= ARRAYLEN(fvar)) return; + if (!varlen || varlen >= ARRAYLEN(fvar)) + return; NTTRACE("WinMainForked()"); SetEnvironmentVariable(u"_FORK", NULL); #if SYSDEBUG @@ -302,7 +306,8 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) { tib = __get_tls(); ftrace_enabled(-1); strace_enabled(-1); - if (!(proc = __proc_new())) return -1; + if (!(proc = __proc_new())) + return -1; if (!setjmp(jb)) { reader = CreateNamedPipe(__create_pipe_name(pipename), kNtPipeAccessInbound, kNtPipeTypeByte | kNtPipeReadmodeByte, 1, PIPE_BUF, @@ -323,14 +328,16 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) { // forked process since the flag was removed by __intercept_flag if (strace_enabled(0) > 0) { int n; - for (n = 0; args[n];) ++n; + for (n = 0; args[n];) + ++n; #pragma GCC push_options #pragma GCC diagnostic ignored "-Walloca-larger-than=" int nbytes = (n + 2) * sizeof(char *); char **args2 = alloca(nbytes); CheckLargeStackAllocation(args2, nbytes); #pragma GCC pop_options - for (i = 0; i < n; ++i) args2[i] = args[i]; + for (i = 0; i < n; ++i) + args2[i] = args[i]; args2[i++] = "--strace"; args2[i] = 0; args = args2; @@ -360,10 +367,13 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) { ok = WriteAll(writer, p, _mmi.p[i].size); } } - if (ok) ok = WriteAll(writer, __data_start, __data_end - __data_start); - if (ok) ok = WriteAll(writer, __bss_start, __bss_end - __bss_start); + if (ok) + ok = WriteAll(writer, __data_start, __data_end - __data_start); + if (ok) + ok = WriteAll(writer, __bss_start, __bss_end - __bss_start); if (ok) { - if (!CloseHandle(writer)) ok = false; + if (!CloseHandle(writer)) + ok = false; writer = -1; } if (ok) { @@ -377,8 +387,10 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) { } } } - if (reader != -1) CloseHandle(reader); - if (writer != -1) CloseHandle(writer); + if (reader != -1) + CloseHandle(reader); + if (writer != -1) + CloseHandle(writer); if (rc == -1 && errno != ENOMEM) { eagain(); // posix fork() only specifies two errors } diff --git a/libc/proc/fork.c b/libc/proc/fork.c index 196d5490c..6c4706963 100644 --- a/libc/proc/fork.c +++ b/libc/proc/fork.c @@ -45,7 +45,8 @@ int _fork(uint32_t dwCreationFlags) { int ax, dx, tid, parent; parent = __pid; BLOCK_SIGNALS; - if (IsWindows()) __proc_lock(); + if (IsWindows()) + __proc_lock(); if (__threaded && _weaken(_pthread_onfork_prepare)) { _weaken(_pthread_onfork_prepare)(); } @@ -107,7 +108,8 @@ int _fork(uint32_t dwCreationFlags) { if (__threaded && _weaken(_pthread_onfork_parent)) { _weaken(_pthread_onfork_parent)(); } - if (IsWindows()) __proc_unlock(); + if (IsWindows()) + __proc_unlock(); STRACE("fork() → %d% m", ax); } ALLOW_SIGNALS; diff --git a/libc/proc/kill-nt.c b/libc/proc/kill-nt.c index 8911014d3..0a60bf350 100644 --- a/libc/proc/kill-nt.c +++ b/libc/proc/kill-nt.c @@ -84,8 +84,10 @@ textwindows int sys_kill_nt(int pid, int sig) { // perform actual kill // process will report WIFSIGNALED with WTERMSIG(sig) bool32 ok = TerminateProcess(handle, sig); - if (closeme) CloseHandle(closeme); - if (ok) return 0; + if (closeme) + CloseHandle(closeme); + if (ok) + return 0; // handle error OnError: diff --git a/libc/proc/killpg.c b/libc/proc/killpg.c index 30ec2c3c2..7e8531497 100644 --- a/libc/proc/killpg.c +++ b/libc/proc/killpg.c @@ -24,7 +24,9 @@ * Sends signal to process group. */ int killpg(int pgrp, int sig) { - if (!(0 < sig && sig < NSIG)) return einval(); - if (pgrp == 1 || pgrp < 0) return esrch(); + if (!(0 < sig && sig < NSIG)) + return einval(); + if (pgrp == 1 || pgrp < 0) + return esrch(); return kill(IsWindows() ? pgrp : -pgrp, sig); } diff --git a/libc/proc/nice.c b/libc/proc/nice.c index c667f52df..783ed4936 100644 --- a/libc/proc/nice.c +++ b/libc/proc/nice.c @@ -39,10 +39,12 @@ int nice(int delta) { p = delta; } else { delta = clamp(delta); - if ((p = getpriority(PRIO_PROCESS, 0)) == -1) return -1; + if ((p = getpriority(PRIO_PROCESS, 0)) == -1) + return -1; p += delta; } p = clamp(p); - if (setpriority(PRIO_PROCESS, 0, p) == -1) return -1; + if (setpriority(PRIO_PROCESS, 0, p) == -1) + return -1; return p; } diff --git a/libc/proc/posix_spawn.c b/libc/proc/posix_spawn.c index 8390c5c52..a99ef8dc0 100644 --- a/libc/proc/posix_spawn.c +++ b/libc/proc/posix_spawn.c @@ -110,17 +110,21 @@ struct SpawnFds { static atomic_bool has_vfork; // i.e. not qemu/wsl/xnu/openbsd static textwindows int64_t spawnfds_handle(struct SpawnFds *fds, int fd) { - if (__is_cloexec(fds->p + fd)) return -1; + if (__is_cloexec(fds->p + fd)) + return -1; return fds->p[fd].handle; } static textwindows errno_t spawnfds_ensure(struct SpawnFds *fds, int fd) { int n2; struct Fd *p2; - if (fd < 0) return EBADF; - if (fd < fds->n) return 0; + if (fd < 0) + return EBADF; + if (fd < fds->n) + return 0; n2 = fd + 1; - if (!(p2 = realloc(fds->p, n2 * sizeof(*fds->p)))) return ENOMEM; + if (!(p2 = realloc(fds->p, n2 * sizeof(*fds->p)))) + return ENOMEM; bzero(p2 + fds->n, (n2 - fds->n) * sizeof(*fds->p)); fds->p = p2; fds->n = n2; @@ -141,7 +145,8 @@ static textwindows void spawnfds_destroy(struct SpawnFds *fds) { static textwindows int spawnfds_closelater(struct SpawnFds *fds, int64_t handle) { struct Closer *closer; - if (!(closer = malloc(sizeof(struct Closer)))) return ENOMEM; + if (!(closer = malloc(sizeof(struct Closer)))) + return ENOMEM; closer->handle = handle; dll_init(&closer->elem); dll_make_last(&fds->closers, &closer->elem); @@ -170,7 +175,8 @@ static textwindows errno_t spawnfds_dup2(struct SpawnFds *fds, int fildes, } else { return EBADF; } - if ((err = spawnfds_ensure(fds, newfildes))) return err; + if ((err = spawnfds_ensure(fds, newfildes))) + return err; struct Fd *neu = fds->p + newfildes; memcpy(neu, old, sizeof(struct Fd)); neu->flags &= ~O_CLOEXEC; @@ -189,7 +195,8 @@ static textwindows errno_t spawnfds_open(struct SpawnFds *fds, int64_t dirhand, errno_t err; char16_t path16[PATH_MAX]; uint32_t perm, share, disp, attr; - if ((err = spawnfds_ensure(fds, fildes))) return err; + if ((err = spawnfds_ensure(fds, fildes))) + return err; if (__mkntpathath(dirhand, path, 0, path16) != -1 && GetNtOpenFlags(oflag, mode, &perm, &share, &disp, &attr) != -1 && (h = CreateFile(path16, perm, share, &kNtIsInheritable, disp, attr, 0))) { @@ -277,8 +284,10 @@ static textwindows errno_t posix_spawn_nt_impl( // fork file descriptor table for (int fd = g_fds.n; fd--;) { - if (__is_cloexec(g_fds.p + fd)) continue; - if ((err = spawnfds_ensure(&fds, fd))) goto ReturnErr; + if (__is_cloexec(g_fds.p + fd)) + continue; + if ((err = spawnfds_ensure(&fds, fd))) + goto ReturnErr; fds.p[fd] = g_fds.p[fd]; } @@ -369,7 +378,8 @@ static textwindows errno_t posix_spawn_nt_impl( // launch process int rc = -1; struct NtProcessInformation procinfo; - if (!envp) envp = environ; + if (!envp) + envp = environ; if ((fdspec = __describe_fds(fds.p, fds.n, &startinfo, hCreatorProcess, &lpExplicitHandles, &dwExplicitHandleCount))) { rc = ntspawn(dirhand, path, argv, envp, (char *[]){fdspec, maskvar, 0}, @@ -385,7 +395,8 @@ static textwindows errno_t posix_spawn_nt_impl( CloseHandle(procinfo.hThread); proc->pid = procinfo.dwProcessId; proc->handle = procinfo.hProcess; - if (pid) *pid = proc->pid; + if (pid) + *pid = proc->pid; __proc_lock(); __proc_add(proc); __proc_unlock(); @@ -395,8 +406,10 @@ static textwindows errno_t posix_spawn_nt_impl( } static const char *DescribePid(char buf[12], int err, int *pid) { - if (err) return "n/a"; - if (!pid) return "NULL"; + if (err) + return "n/a"; + if (!pid) + return "NULL"; FormatInt32(buf, *pid); return buf; } @@ -496,7 +509,8 @@ errno_t posix_spawn(int *pid, const char *path, bool lost_cloexec = 0; struct sigaction dfl = {0}; short flags = attrp && *attrp ? (*attrp)->flags : 0; - if (use_pipe) close(pfds[0]); + if (use_pipe) + close(pfds[0]); for (int sig = 1; sig < _NSIG; sig++) { if (__sighandrvas[sig] != (long)SIG_DFL && (__sighandrvas[sig] != (long)SIG_IGN || @@ -606,7 +620,8 @@ errno_t posix_spawn(int *pid, const char *path, childmask = oldmask; } sigprocmask(SIG_SETMASK, &childmask, 0); - if (!envp) envp = environ; + if (!envp) + envp = environ; execve(path, argv, envp); ChildFailed: res = errno; @@ -631,7 +646,8 @@ errno_t posix_spawn(int *pid, const char *path, read(pfds[0], &res, sizeof(res)); } if (!res) { - if (pid) *pid = child; + if (pid) + *pid = child; } else { wait4(child, 0, 0, 0); } diff --git a/libc/proc/posix_spawn_add_file_action.c b/libc/proc/posix_spawn_add_file_action.c index 3b6aace1f..0a0df67d1 100644 --- a/libc/proc/posix_spawn_add_file_action.c +++ b/libc/proc/posix_spawn_add_file_action.c @@ -24,9 +24,11 @@ int __posix_spawn_add_file_action(posix_spawn_file_actions_t *l, struct _posix_faction a) { struct _posix_faction *ap; - if (!(ap = malloc(sizeof(*ap)))) return ENOMEM; + if (!(ap = malloc(sizeof(*ap)))) + return ENOMEM; *ap = a; - while (*l) l = &(*l)->next; + while (*l) + l = &(*l)->next; *l = ap; return 0; } diff --git a/libc/proc/posix_spawn_file_actions_addchdir_np.c b/libc/proc/posix_spawn_file_actions_addchdir_np.c index 4ab0dc4a3..61e6614f9 100644 --- a/libc/proc/posix_spawn_file_actions_addchdir_np.c +++ b/libc/proc/posix_spawn_file_actions_addchdir_np.c @@ -32,7 +32,8 @@ int posix_spawn_file_actions_addchdir_np( posix_spawn_file_actions_t *file_actions, const char *path) { char *path2; - if (!(path2 = strdup(path))) return ENOMEM; + if (!(path2 = strdup(path))) + return ENOMEM; return __posix_spawn_add_file_action(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_CHDIR, diff --git a/libc/proc/posix_spawn_file_actions_addclose.c b/libc/proc/posix_spawn_file_actions_addclose.c index 1d9e41495..5a96b1fa1 100644 --- a/libc/proc/posix_spawn_file_actions_addclose.c +++ b/libc/proc/posix_spawn_file_actions_addclose.c @@ -31,7 +31,8 @@ */ int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions, int fildes) { - if (fildes < 0) return EBADF; + if (fildes < 0) + return EBADF; return __posix_spawn_add_file_action(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_CLOSE, diff --git a/libc/proc/posix_spawn_file_actions_adddup2.c b/libc/proc/posix_spawn_file_actions_adddup2.c index ae3ec441f..ebe971450 100644 --- a/libc/proc/posix_spawn_file_actions_adddup2.c +++ b/libc/proc/posix_spawn_file_actions_adddup2.c @@ -31,7 +31,8 @@ */ int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions, int fildes, int newfildes) { - if (fildes < 0 || newfildes < 0) return EBADF; + if (fildes < 0 || newfildes < 0) + return EBADF; return __posix_spawn_add_file_action(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_DUP2, diff --git a/libc/proc/posix_spawn_file_actions_addfchdir_np.c b/libc/proc/posix_spawn_file_actions_addfchdir_np.c index 7404da09a..2cf57e6f0 100644 --- a/libc/proc/posix_spawn_file_actions_addfchdir_np.c +++ b/libc/proc/posix_spawn_file_actions_addfchdir_np.c @@ -30,7 +30,8 @@ */ int posix_spawn_file_actions_addfchdir_np( posix_spawn_file_actions_t *file_actions, int fildes) { - if (fildes < 0) return EBADF; + if (fildes < 0) + return EBADF; return __posix_spawn_add_file_action(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_FCHDIR, diff --git a/libc/proc/posix_spawn_file_actions_addopen.c b/libc/proc/posix_spawn_file_actions_addopen.c index 413fdbafa..b45e7b21c 100644 --- a/libc/proc/posix_spawn_file_actions_addopen.c +++ b/libc/proc/posix_spawn_file_actions_addopen.c @@ -36,8 +36,10 @@ int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *file_actions, int fildes, const char *path, int oflag, unsigned mode) { char *path2; - if (fildes < 0) return EBADF; - if (!(path2 = strdup(path))) return ENOMEM; + if (fildes < 0) + return EBADF; + if (!(path2 = strdup(path))) + return ENOMEM; return __posix_spawn_add_file_action(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_OPEN, diff --git a/libc/proc/posix_spawnp.c b/libc/proc/posix_spawnp.c index caabd0366..ce3ca54c9 100644 --- a/libc/proc/posix_spawnp.c +++ b/libc/proc/posix_spawnp.c @@ -33,6 +33,7 @@ int posix_spawnp(int *pid, const char *path, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) { char pathbuf[PATH_MAX]; - if (!(path = commandv(path, pathbuf, sizeof(pathbuf)))) return errno; + if (!(path = commandv(path, pathbuf, sizeof(pathbuf)))) + return errno; return posix_spawn(pid, path, file_actions, attrp, argv, envp); } diff --git a/libc/proc/proc.c b/libc/proc/proc.c index 600bf206c..33aa5f15c 100644 --- a/libc/proc/proc.c +++ b/libc/proc/proc.c @@ -84,7 +84,8 @@ textwindows int __proc_harvest(struct Proc *pr, bool iswait4) { uint32_t status; struct rusage ru; GetExitCodeProcess(pr->handle, &status); - if (status == kNtStillActive) return 0; + if (status == kNtStillActive) + return 0; __proc_stats(pr->handle, &ru); rusage_add(&pr->ru, &ru); rusage_add(&__proc.ruchlds, &ru); @@ -176,8 +177,10 @@ static textwindows dontinstrument uint32_t __proc_worker(void *arg) { // release our waiter status for (int j = 0; j < n; ++j) { - if (handles[j] == __proc.onbirth) continue; - if (j == i) continue; + if (handles[j] == __proc.onbirth) + continue; + if (j == i) + continue; if (!--objects[j]->waiters && objects[j]->status == PROC_UNDEAD) { __proc_free(objects[j]); } diff --git a/libc/proc/setpriority-nt.c b/libc/proc/setpriority-nt.c index 30ee7a806..fc3f2fb09 100644 --- a/libc/proc/setpriority-nt.c +++ b/libc/proc/setpriority-nt.c @@ -53,7 +53,8 @@ textwindows int sys_setpriority_nt(int which, unsigned pid, int nice) { tier = kNtIdlePriorityClass; } - if (SetPriorityClass(handle, tier)) return 0; + if (SetPriorityClass(handle, tier)) + return 0; STRACE("SetPriorityClass() failed with %d", GetLastError()); switch (GetLastError()) { case kNtErrorInvalidHandle: diff --git a/libc/proc/system.c b/libc/proc/system.c index 75ea1061f..fddb4a0dd 100644 --- a/libc/proc/system.c +++ b/libc/proc/system.c @@ -64,7 +64,8 @@ int system(const char *cmdline) { int pid, wstatus; sigset_t chldmask, savemask; - if (!cmdline) return 1; + if (!cmdline) + return 1; sigemptyset(&chldmask); sigaddset(&chldmask, SIGINT); sigaddset(&chldmask, SIGQUIT); diff --git a/libc/proc/times.c b/libc/proc/times.c index 50f8d2fd1..640586c2a 100644 --- a/libc/proc/times.c +++ b/libc/proc/times.c @@ -38,10 +38,12 @@ static dontinline long times2(struct tms *out_times, struct rusage *ru) { struct timeval tv; struct NtFileTime CreationTime, ExitTime, KernelTime, UserTime; if (!IsWindows()) { - if (getrusage(RUSAGE_SELF, ru) == -1) return -1; + if (getrusage(RUSAGE_SELF, ru) == -1) + return -1; out_times->tms_utime = ConvertMicros(ru->ru_utime); out_times->tms_stime = ConvertMicros(ru->ru_stime); - if (getrusage(RUSAGE_CHILDREN, ru) == -1) return -1; + if (getrusage(RUSAGE_CHILDREN, ru) == -1) + return -1; out_times->tms_cutime = ConvertMicros(ru->ru_utime); out_times->tms_cstime = ConvertMicros(ru->ru_stime); } else { @@ -54,7 +56,8 @@ static dontinline long times2(struct tms *out_times, struct rusage *ru) { out_times->tms_cutime = 0; out_times->tms_cstime = 0; } - if (gettimeofday(&tv, NULL) == -1) return -1; + if (gettimeofday(&tv, NULL) == -1) + return -1; return ConvertMicros(tv); } diff --git a/libc/proc/wait4-nt.c b/libc/proc/wait4-nt.c index 3cbb5bc57..d1f2bc396 100644 --- a/libc/proc/wait4-nt.c +++ b/libc/proc/wait4-nt.c @@ -116,7 +116,8 @@ static textwindows int __proc_wait(int pid, int *wstatus, int options, for (struct Dll *e = dll_first(__proc.list); e; e = dll_next(__proc.list, e)) { pr = PROC_CONTAINER(e); - if (pid == pr->pid) break; + if (pid == pr->pid) + break; } if (pr) { // by making the waiter count non-zero, the proc daemon stops @@ -211,12 +212,15 @@ static textwindows int __proc_wait(int pid, int *wstatus, int options, textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { // no support for WCONTINUED and WUNTRACED yet - if (options & ~WNOHANG) return einval(); + if (options & ~WNOHANG) + return einval(); // XXX: NT doesn't really have process groups. For instance the // CreateProcess() flag for starting a process group actually // just does an "ignore ctrl-c" internally. - if (pid == 0) pid = -1; - if (pid < -1) pid = -pid; + if (pid == 0) + pid = -1; + if (pid < -1) + pid = -pid; sigset_t m = __sig_block(); int rc = __proc_wait(pid, opt_out_wstatus, options, opt_out_rusage, m | 1ull << (SIGCHLD - 1)); diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index 7a9913ccb..16c07cf22 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -118,7 +118,8 @@ WinThreadEntry(int rdi, // rcx int rdx, // r8 struct CloneArgs *wt) { // r9 int rc; - if (wt->tls) __set_tls_win32(wt->tls); + if (wt->tls) + __set_tls_win32(wt->tls); *wt->ctid = wt->tid; rc = __stack_call(wt->arg, wt->tid, 0, 0, wt->func, wt); // we can now clear ctid directly since we're no longer using our own @@ -465,17 +466,20 @@ static errno_t CloneFreebsd(int (*func)(void *, int), char *stk, size_t stksz, : CFLAG_CONSTRAINT(failed), "=a"(ax) : "1"(__NR_thr_new), "D"(¶ms), "S"(sizeof(params)) : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory"); - if (failed) return ax; + if (failed) + return ax; #elif defined(__aarch64__) register long x0 asm("x0") = (long)¶ms; register long x1 asm("x1") = sizeof(params); register int x8 asm("x8") = 0x1c7; // thr_new asm volatile("svc\t0" : "+r"(x0) : "r"(x1), "r"(x8) : "memory"); - if (x0) return x0; + if (x0) + return x0; #else #error "unsupported architecture" #endif - if (flags & CLONE_PARENT_SETTID) *ptid = tid; + if (flags & CLONE_PARENT_SETTID) + *ptid = tid; return 0; } diff --git a/libc/runtime/closesymboltable.c b/libc/runtime/closesymboltable.c index 1f825d3ee..ae13b7a3a 100644 --- a/libc/runtime/closesymboltable.c +++ b/libc/runtime/closesymboltable.c @@ -25,7 +25,8 @@ */ int CloseSymbolTable(struct SymbolTable **table) { struct SymbolTable *t; - if (!*table) return 0; + if (!*table) + return 0; t = *table; *table = 0; return munmap(t, t->mapsize); diff --git a/libc/runtime/cosmo2.c b/libc/runtime/cosmo2.c index 8181bb9b3..afdf39d8b 100644 --- a/libc/runtime/cosmo2.c +++ b/libc/runtime/cosmo2.c @@ -104,7 +104,8 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename, char **argv = (char **)(sp + 1); char **envp = (char **)(sp + 1 + argc + 1); unsigned long *auxv = (unsigned long *)(sp + 1 + argc + 1); - while (*auxv++) donothing; + while (*auxv++) + donothing; // set helpful globals __argc = argc; diff --git a/libc/runtime/efimain.greg.c b/libc/runtime/efimain.greg.c index 5b15f73d6..4ecda0eca 100644 --- a/libc/runtime/efimain.greg.c +++ b/libc/runtime/efimain.greg.c @@ -109,7 +109,8 @@ static void EfiInitVga(struct mman *mm, EFI_SYSTEM_TABLE *SystemTable) { default: notpossible; } - if (!bytes_per_pix) notpossible; + if (!bytes_per_pix) + notpossible; mm->pc_video_type = vid_typ; mm->pc_video_stride = GraphMode->Info->PixelsPerScanLine * bytes_per_pix; mm->pc_video_width = GraphMode->Info->HorizontalResolution; @@ -217,7 +218,8 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, SystemTable->BootServices->HandleProtocol(ImageHandle, &kEfiLoadedImageProtocol, &ImgInfo); CmdLine = (const char16_t *)ImgInfo->LoadOptions; - if (!CmdLine || !CmdLine[0]) CmdLine = u"BOOTX64.EFI"; + if (!CmdLine || !CmdLine[0]) + CmdLine = u"BOOTX64.EFI"; Args = GetDosArgv(CmdLine, ArgBlock->ArgBlock, sizeof(ArgBlock->ArgBlock), ArgBlock->Args, ARRAYLEN(ArgBlock->Args)); @@ -226,7 +228,8 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, * TODO: if needed, switch to a video mode that has a linear frame buffer * type we support. */ - if (_weaken(vga_console)) EfiInitVga(mm, SystemTable); + if (_weaken(vga_console)) + EfiInitVga(mm, SystemTable); /* * Gets a pointer to the ACPI RSDP. @@ -250,7 +253,8 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, case EfiLoaderData: case EfiBootServicesCode: case EfiBootServicesData: - if (Desc->PhysicalStart != 0) break; + if (Desc->PhysicalStart != 0) + break; /* fallthrough */ case EfiConventionalMemory: mm->e820[j].addr = Desc->PhysicalStart; diff --git a/libc/runtime/fpathconf.c b/libc/runtime/fpathconf.c index 183766fff..43623cc50 100644 --- a/libc/runtime/fpathconf.c +++ b/libc/runtime/fpathconf.c @@ -24,27 +24,48 @@ #include "libc/sysv/errfuns.h" long fpathconf(int fd, int name) { - if (name == _PC_LINK_MAX) return _POSIX_LINK_MAX; - if (name == _PC_MAX_CANON) return _POSIX_MAX_CANON; - if (name == _PC_MAX_INPUT) return _POSIX_MAX_INPUT; - if (name == _PC_NAME_MAX) return NAME_MAX; - if (name == _PC_PATH_MAX) return PATH_MAX; - if (name == _PC_PIPE_BUF) return PIPE_BUF; - if (name == _PC_CHOWN_RESTRICTED) return 1; - if (name == _PC_NO_TRUNC) return 1; - if (name == _PC_VDISABLE) return 0; - if (name == _PC_SYNC_IO) return 1; - if (name == _PC_ASYNC_IO) return -1; - if (name == _PC_PRIO_IO) return -1; - if (name == _PC_SOCK_MAXBUF) return -1; - if (name == _PC_FILESIZEBITS) return FILESIZEBITS; - if (name == _PC_REC_INCR_XFER_SIZE) return 4096; - if (name == _PC_REC_MAX_XFER_SIZE) return 4096; - if (name == _PC_REC_MIN_XFER_SIZE) return 4096; - if (name == _PC_REC_XFER_ALIGN) return 4096; - if (name == _PC_ALLOC_SIZE_MIN) return 4096; - if (name == _PC_SYMLINK_MAX) return -1; - if (name == _PC_2_SYMLINKS) return 1; + if (name == _PC_LINK_MAX) + return _POSIX_LINK_MAX; + if (name == _PC_MAX_CANON) + return _POSIX_MAX_CANON; + if (name == _PC_MAX_INPUT) + return _POSIX_MAX_INPUT; + if (name == _PC_NAME_MAX) + return NAME_MAX; + if (name == _PC_PATH_MAX) + return PATH_MAX; + if (name == _PC_PIPE_BUF) + return PIPE_BUF; + if (name == _PC_CHOWN_RESTRICTED) + return 1; + if (name == _PC_NO_TRUNC) + return 1; + if (name == _PC_VDISABLE) + return 0; + if (name == _PC_SYNC_IO) + return 1; + if (name == _PC_ASYNC_IO) + return -1; + if (name == _PC_PRIO_IO) + return -1; + if (name == _PC_SOCK_MAXBUF) + return -1; + if (name == _PC_FILESIZEBITS) + return FILESIZEBITS; + if (name == _PC_REC_INCR_XFER_SIZE) + return 4096; + if (name == _PC_REC_MAX_XFER_SIZE) + return 4096; + if (name == _PC_REC_MIN_XFER_SIZE) + return 4096; + if (name == _PC_REC_XFER_ALIGN) + return 4096; + if (name == _PC_ALLOC_SIZE_MIN) + return 4096; + if (name == _PC_SYMLINK_MAX) + return -1; + if (name == _PC_2_SYMLINKS) + return 1; return einval(); } diff --git a/libc/runtime/ftracer.c b/libc/runtime/ftracer.c index 2d54afe92..d2e686d3b 100644 --- a/libc/runtime/ftracer.c +++ b/libc/runtime/ftracer.c @@ -61,7 +61,8 @@ __funline int GetNestingLevelImpl(struct StackFrame *frame) { __funline int GetNestingLevel(struct CosmoFtrace *ft, struct StackFrame *sf) { int nesting; nesting = GetNestingLevelImpl(sf); - if (nesting < ft->ft_skew) ft->ft_skew = nesting; + if (nesting < ft->ft_skew) + ft->ft_skew = nesting; nesting -= ft->ft_skew; return MIN(MAX_NESTING, nesting); } @@ -84,10 +85,12 @@ privileged void ftracer(void) { struct PosixThread *pt; sf = __builtin_frame_address(0); st = (uintptr_t)__argv - sizeof(uintptr_t); - if (__ftrace <= 0) return; + if (__ftrace <= 0) + return; if (__tls_enabled) { tib = __get_tls_privileged(); - if (tib->tib_ftrace <= 0) return; + if (tib->tib_ftrace <= 0) + return; ft = &tib->tib_ftracer; if ((char *)sf >= tib->tib_sigstack_addr && (char *)sf <= tib->tib_sigstack_addr + tib->tib_sigstack_size) { diff --git a/libc/runtime/getavphyspages.c b/libc/runtime/getavphyspages.c index 70741f811..9dcd12ade 100644 --- a/libc/runtime/getavphyspages.c +++ b/libc/runtime/getavphyspages.c @@ -21,6 +21,7 @@ long __get_avphys_pages(void) { struct sysinfo si; - if (sysinfo(&si) == -1) return -1; + if (sysinfo(&si) == -1) + return -1; return (((int64_t)si.freeram + si.bufferram) * si.mem_unit) / FRAMESIZE; } diff --git a/libc/runtime/getdosargv.c b/libc/runtime/getdosargv.c index 76885d738..87ecd5a39 100644 --- a/libc/runtime/getdosargv.c +++ b/libc/runtime/getdosargv.c @@ -31,7 +31,8 @@ struct DosArgv { textwindows void DecodeDosArgv(int ignore, struct DosArgv *st) { wint_t x, y; for (;;) { - if (!(x = *st->s++)) break; + if (!(x = *st->s++)) + break; if (!IsUcs2(x)) { if ((y = *st->s++)) { x = MergeUtf16(x, y); @@ -48,7 +49,8 @@ static textwindows void AppendDosArgv(wint_t wc, struct DosArgv *st) { uint64_t w; w = tpenc(wc); do { - if (st->p >= st->pe) break; + if (st->p >= st->pe) + break; *st->p++ = w & 0xff; } while (w >>= 8); } @@ -97,13 +99,15 @@ textwindows int GetDosArgv(const char16_t *cmdline, char *buf, size_t size, while (st->wc && (st->wc == ' ' || st->wc == '\t')) { DecodeDosArgv(ignore, st); } - if (!st->wc) break; + if (!st->wc) + break; if (++argc < max) { argv[argc - 1] = st->p < st->pe ? st->p : NULL; } inquote = false; while (st->wc) { - if (!inquote && (st->wc == ' ' || st->wc == '\t')) break; + if (!inquote && (st->wc == ' ' || st->wc == '\t')) + break; if (st->wc == '"' || st->wc == '\\') { slashes = Count('\\', st); quotes = Count('"', st); @@ -121,7 +125,8 @@ textwindows int GetDosArgv(const char16_t *cmdline, char *buf, size_t size, quotes--; } if (quotes > 0) { - if (!inquote) quotes--; + if (!inquote) + quotes--; for (i = 3; i <= quotes + 1; i += 3) { AppendDosArgv('"', st); } @@ -136,7 +141,9 @@ textwindows int GetDosArgv(const char16_t *cmdline, char *buf, size_t size, AppendDosArgv('\0', st); } AppendDosArgv('\0', st); - if (size) buf[MIN(st->p - buf, size - 1)] = '\0'; - if (max) argv[MIN(argc, max - 1)] = NULL; + if (size) + buf[MIN(st->p - buf, size - 1)] = '\0'; + if (max) + argv[MIN(argc, max - 1)] = NULL; return argc; } diff --git a/libc/runtime/getdosenviron.c b/libc/runtime/getdosenviron.c index 286e93bb9..ba12636d6 100644 --- a/libc/runtime/getdosenviron.c +++ b/libc/runtime/getdosenviron.c @@ -43,7 +43,8 @@ static abi axdx_t Recode16to8(char *dst, size_t dstsize, const char16_t *src) { uint64_t w; wint_t x, y; for (v = false, r.ax = 0, r.dx = 0;;) { - if (!(x = src[r.dx++])) break; + if (!(x = src[r.dx++])) + break; if (!IsUcs2(x)) { y = src[r.dx++]; x = MergeUtf16(x, y); @@ -117,7 +118,8 @@ abi int GetDosEnviron(const char16_t *env, char *buf, size_t size, char **envp, i = 0; --size; while (*env) { - if (i + 1 < max) envp[i++] = buf; + if (i + 1 < max) + envp[i++] = buf; r = Recode16to8(buf, size, env); if ((p = MemChr(buf, '=', r.ax)) && IsAlpha(p[1]) && p[2] == ':' && (p[3] == '\\' || p[3] == '/')) { diff --git a/libc/runtime/getphyspages.c b/libc/runtime/getphyspages.c index ee932042e..8c9eabc26 100644 --- a/libc/runtime/getphyspages.c +++ b/libc/runtime/getphyspages.c @@ -21,6 +21,7 @@ long __get_phys_pages(void) { struct sysinfo si; - if (sysinfo(&si) == -1) return -1; + if (sysinfo(&si) == -1) + return -1; return ((int64_t)si.totalram * si.mem_unit) / FRAMESIZE; } diff --git a/libc/runtime/getresourcelimit.c b/libc/runtime/getresourcelimit.c index 7e01b81dc..d68b256b3 100644 --- a/libc/runtime/getresourcelimit.c +++ b/libc/runtime/getresourcelimit.c @@ -23,7 +23,9 @@ long __get_rlimit(int resource) { struct rlimit rl; - if (getrlimit(resource, &rl) == -1) return -1; - if (rl.rlim_cur == RLIM_INFINITY) return -1; + if (getrlimit(resource, &rl) == -1) + return -1; + if (rl.rlim_cur == RLIM_INFINITY) + return -1; return MIN(rl.rlim_cur, LONG_MAX); } diff --git a/libc/runtime/getsymbolbyaddr.c b/libc/runtime/getsymbolbyaddr.c index 58fe0b12a..623e02d82 100644 --- a/libc/runtime/getsymbolbyaddr.c +++ b/libc/runtime/getsymbolbyaddr.c @@ -29,6 +29,7 @@ char *GetSymbolByAddr(int64_t addr) { struct SymbolTable *st; st = GetSymbolTable(); i = __get_symbol(st, addr); - if (i == -1) i = __get_symbol(st, addr - 1); + if (i == -1) + i = __get_symbol(st, addr - 1); return __get_symbol_name(st, i); } diff --git a/libc/runtime/getsymboltable.c b/libc/runtime/getsymboltable.c index fff3282f9..b9f8ae2cb 100644 --- a/libc/runtime/getsymboltable.c +++ b/libc/runtime/getsymboltable.c @@ -122,7 +122,8 @@ static struct SymbolTable *GetSymbolTableFromElf(void) { */ struct SymbolTable *GetSymbolTable(void) { struct Zipos *z; - if (pthread_spin_trylock(&g_lock)) return 0; + if (pthread_spin_trylock(&g_lock)) + return 0; if (!__symtab && !__isworker) { if (_weaken(__zipos_get) && (z = _weaken(__zipos_get)())) { if ((__symtab = GetSymbolTableFromZip(z))) { diff --git a/libc/runtime/grow.c b/libc/runtime/grow.c index 1d5c32835..efee95fce 100644 --- a/libc/runtime/grow.c +++ b/libc/runtime/grow.c @@ -46,7 +46,8 @@ bool __grow(void *pp, size_t *capacity, size_t itemsize, size_t extra) { n2 = (*p ? n1 + (n1 >> 1) : MAX(4, INITIAL_CAPACITY / itemsize)) + extra; if (!ckd_mul(&t1, n1, itemsize) && !ckd_mul(&t2, n2, itemsize)) { if (_weaken(realloc) && (p2 = _weaken(realloc)(p1, ROUNDUP(t2, 32)))) { - if (!p1 && *p) memcpy(p2, *p, t1); + if (!p1 && *p) + memcpy(p2, *p, t1); bzero((char *)p2 + t1, t2 - t1); *capacity = n2; *p = p2; diff --git a/libc/runtime/hook.greg.c b/libc/runtime/hook.greg.c index 91e50fec6..16596bf6a 100644 --- a/libc/runtime/hook.greg.c +++ b/libc/runtime/hook.greg.c @@ -36,17 +36,21 @@ static privileged bool IsVirginFunction(const code_t *func) { long i; // function must be preceeded by 9 nops for (i = -9; i < 0; ++i) { - if (func[i] != 0x90) return false; + if (func[i] != 0x90) + return false; } // function must start with `nop nop` or `xchg %ax,%ax` - if (func[0] == 0x90 && func[1] == 0x90) return true; - if (func[0] == 0x66 && func[1] == 0x90) return true; + if (func[0] == 0x90 && func[1] == 0x90) + return true; + if (func[0] == 0x66 && func[1] == 0x90) + return true; return false; #elif defined(__aarch64__) long i; // function must be preceeded by 6 nops for (i = -6; i < 0; ++i) { - if (func[i] != 0xd503201f) return false; + if (func[i] != 0xd503201f) + return false; } // function must start with one nop return func[0] == 0xd503201f; @@ -57,7 +61,8 @@ static privileged void HookFunction(code_t *func, void *dest) { long dp; #ifdef __x86_64__ dp = (intptr_t)dest - (intptr_t)(func - 7 + 5); - if (!(INT32_MIN <= dp && dp <= INT32_MAX)) return; + if (!(INT32_MIN <= dp && dp <= INT32_MAX)) + return; // emit `ud2` signature for safety and checkability func[-9] = 0x0f; func[-8] = 0x0b; @@ -75,7 +80,8 @@ static privileged void HookFunction(code_t *func, void *dest) { func[+1] = -7 - 2; #elif defined(__aarch64__) dp = (code_t *)dest - (func - 3); - if (!(-33554432 <= dp && dp <= +33554431)) return; + if (!(-33554432 <= dp && dp <= +33554431)) + return; func[-6] = 0xd4200000 | (31337 << 5); // brk #31337 func[-5] = 0xa9bf7bfd; // stp x29,x30,[sp, #-16]! func[-4] = 0x910003fd; // mov x29,sp @@ -110,16 +116,21 @@ privileged int __hook(void *dest, struct SymbolTable *st) { long i; code_t *p, *pe; intptr_t lowest; - if (!st) return -1; + if (!st) + return -1; __morph_begin(); lowest = MAX((intptr_t)__executable_start, (intptr_t)_ereal); for (i = 0; i < st->count; ++i) { - if (st->symbols[i].x < 9) continue; - if (st->addr_base + st->symbols[i].x < lowest) continue; - if (st->addr_base + st->symbols[i].y >= (intptr_t)__privileged_start) break; + if (st->symbols[i].x < 9) + continue; + if (st->addr_base + st->symbols[i].x < lowest) + continue; + if (st->addr_base + st->symbols[i].y >= (intptr_t)__privileged_start) + break; p = (code_t *)((char *)st->addr_base + st->symbols[i].x); pe = (code_t *)((char *)st->addr_base + st->symbols[i].y); - if (pe - p < 2) continue; + if (pe - p < 2) + continue; if (IsVirginFunction(p)) { // kprintf("hooking %t\n", p); HookFunction(p, dest); diff --git a/libc/runtime/ismemtracked.greg.c b/libc/runtime/ismemtracked.greg.c index a613e91a7..da848a25d 100644 --- a/libc/runtime/ismemtracked.greg.c +++ b/libc/runtime/ismemtracked.greg.c @@ -21,12 +21,17 @@ static inline bool IsMemtrackedImpl(int x, int y) { unsigned i; i = __find_memory(&_mmi, x); - if (i == _mmi.i) return false; - if (x < _mmi.p[i].x) return false; + if (i == _mmi.i) + return false; + if (x < _mmi.p[i].x) + return false; for (;;) { - if (y <= _mmi.p[i].y) return true; - if (++i == _mmi.i) return false; - if (_mmi.p[i].x != _mmi.p[i - 1].y + 1) return false; + if (y <= _mmi.p[i].y) + return true; + if (++i == _mmi.i) + return false; + if (_mmi.p[i].x != _mmi.p[i - 1].y + 1) + return false; } } diff --git a/libc/runtime/isstackoverflow.c b/libc/runtime/isstackoverflow.c index ac2a1e091..efe0d0696 100644 --- a/libc/runtime/isstackoverflow.c +++ b/libc/runtime/isstackoverflow.c @@ -29,8 +29,10 @@ */ char __is_stack_overflow(siginfo_t *si, void *arg) { ucontext_t *uc = arg; - if (!si || !uc) return false; - if (si->si_signo != SIGSEGV && si->si_signo != SIGBUS) return false; + if (!si || !uc) + return false; + if (si->si_signo != SIGSEGV && si->si_signo != SIGBUS) + return false; intptr_t sp = uc->uc_mcontext.SP; intptr_t fp = (intptr_t)si->si_addr; return ABS(fp - sp) < getauxval(AT_PAGESZ); diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index 68bda1c2b..3a066c64e 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -77,7 +77,8 @@ static inline pureconst unsigned long __rounddown2pow(unsigned long x) { } static wontreturn void __mmap_die(const char *s) { - if (_weaken(__die)) _weaken(__die)(); + if (_weaken(__die)) + _weaken(__die)(); STRACE("%s %m", s); _Exit(199); } @@ -89,9 +90,12 @@ static inline bool __overlaps_existing_mapping(char *p, size_t n) { b = FRAME(p + (n - 1)); i = __find_memory(&_mmi, a); if (i < _mmi.i) { - if (a <= _mmi.p[i].x && _mmi.p[i].x <= b) return true; - if (a <= _mmi.p[i].y && _mmi.p[i].y <= b) return true; - if (_mmi.p[i].x <= a && b <= _mmi.p[i].y) return true; + if (a <= _mmi.p[i].x && _mmi.p[i].x <= b) + return true; + if (a <= _mmi.p[i].y && _mmi.p[i].y <= b) + return true; + if (_mmi.p[i].x <= a && b <= _mmi.p[i].y) + return true; } return false; } @@ -219,7 +223,8 @@ static textwindows dontinline void *__map_memories(char *addr, size_t size, oi = fd == -1 ? 0 : off + m; sz = size - m; dm = sys_mmap(addr + m, sz, prot, f, fd, oi); - if (dm.addr == MAP_FAILED) return MAP_FAILED; + if (dm.addr == MAP_FAILED) + return MAP_FAILED; iscow = (flags & MAP_TYPE) != MAP_SHARED && fd != -1; readonlyfile = (flags & MAP_TYPE) == MAP_SHARED && fd != -1 && (g_fds.p[fd].flags & O_ACCMODE) == O_RDONLY; diff --git a/libc/runtime/morph.c b/libc/runtime/morph.c index 4d35f50ef..08abcc410 100644 --- a/libc/runtime/morph.c +++ b/libc/runtime/morph.c @@ -43,7 +43,8 @@ __funline void __morph_mprotect(void *addr, size_t size, int prot, int ntprot) { : "1"(__NR_mprotect), "D"(addr), "S"(size), "2"(prot) : "rcx", "r8", "r9", "r10", "r11", "memory"); #ifndef NDEBUG - if (cf) ax = -ax; + if (cf) + ax = -ax; if (ax == -EPERM) { kprintf("error: need pledge(prot_exec) permission to code morph\n"); } diff --git a/libc/runtime/opensymboltable.greg.c b/libc/runtime/opensymboltable.greg.c index 95313ceda..3359e46bd 100644 --- a/libc/runtime/opensymboltable.greg.c +++ b/libc/runtime/opensymboltable.greg.c @@ -49,15 +49,23 @@ static struct SymbolTable *OpenSymbolTableImpl(const char *filename) { const Elf64_Sym *symtab, *sym; ptrdiff_t names_offset, name_base_offset, stp_offset; map = MAP_FAILED; - if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) == -1) return 0; - if ((filesize = lseek(fd, 0, SEEK_END)) == -1) goto SystemError; - if (filesize > INT_MAX) goto RaiseE2big; - if (filesize < 64) goto RaiseEnoexec; + if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) == -1) + return 0; + if ((filesize = lseek(fd, 0, SEEK_END)) == -1) + goto SystemError; + if (filesize > INT_MAX) + goto RaiseE2big; + if (filesize < 64) + goto RaiseEnoexec; elf = map = mmap(0, filesize, PROT_READ, MAP_PRIVATE, fd, 0); - if (map == MAP_FAILED) goto SystemError; - if (READ32LE((char *)map) != READ32LE("\177ELF")) goto RaiseEnoexec; - if (!(name_base = GetStrtab(map, &m))) goto RaiseEnobufs; - if (!(symtab = GetSymtab(map, &n))) goto RaiseEnobufs; + if (map == MAP_FAILED) + goto SystemError; + if (READ32LE((char *)map) != READ32LE("\177ELF")) + goto RaiseEnoexec; + if (!(name_base = GetStrtab(map, &m))) + goto RaiseEnobufs; + if (!(symtab = GetSymtab(map, &n))) + goto RaiseEnobufs; tsz = 0; tsz += sizeof(struct SymbolTable); tsz += sizeof(struct Symbol) * n; @@ -71,7 +79,8 @@ static struct SymbolTable *OpenSymbolTableImpl(const char *filename) { tsz += sizeof(const Elf64_Sym *) * n; tsz = ROUNDUP(tsz, FRAMESIZE); t = mmap(0, tsz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (t == MAP_FAILED) goto SystemError; + if (t == MAP_FAILED) + goto SystemError; t->magic = SYMBOLS_MAGIC; t->abi = SYMBOLS_ABI; t->size = size; @@ -90,8 +99,10 @@ static struct SymbolTable *OpenSymbolTableImpl(const char *filename) { ELF64_ST_TYPE(sym->st_info) == STT_OBJECT))) { continue; } - if (sym->st_value > t->addr_end) continue; - if (sym->st_value < t->addr_base) continue; + if (sym->st_value > t->addr_end) + continue; + if (sym->st_value < t->addr_base) + continue; x = sym->st_value - t->addr_base; stp[m++] = (unsigned long)x << 32 | i; } diff --git a/libc/runtime/warnifpowersave.c b/libc/runtime/warnifpowersave.c index 07afe8e89..1a01d81d3 100644 --- a/libc/runtime/warnifpowersave.c +++ b/libc/runtime/warnifpowersave.c @@ -44,7 +44,8 @@ void __warn_if_powersave(void) { if ((fd = __sys_openat(AT_FDCWD, FILE, O_RDONLY, 0)) != -1) { sys_read(fd, buf, 15); sys_close(fd); - if (!startswith(buf, "powersave")) return; + if (!startswith(buf, "powersave")) + return; sys_write(2, WARN, sizeof(WARN) - 1); } ALLOW_CANCELATION; diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index 3c0ae49ed..d24bc90c0 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -94,11 +94,15 @@ static abi char16_t *StrStr(const char16_t *haystack, const char16_t *needle) { size_t i; for (;;) { for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char16_t *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ char16_t *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; } @@ -124,7 +128,8 @@ static abi bool32 WinFileExists(const char *path) { uint16_t path16[PATH_MAX]; size_t z = ARRAYLEN(path16); size_t n = tprecode8to16(path16, z, path).ax; - if (n >= z - 1) return false; + if (n >= z - 1) + return false; return __imp_GetFileAttributesW(path16) != -1u; } @@ -236,7 +241,8 @@ static abi wontreturn void WinInit(const char16_t *cmdline) { // normalize executable path if (wa->argv[0] && !WinFileExists(wa->argv[0])) { unsigned i, n = 0; - while (wa->argv[0][n]) ++n; + while (wa->argv[0][n]) + ++n; if (n + 4 < sizeof(wa->argv0buf)) { for (i = 0; i < n; ++i) { wa->argv0buf[i] = wa->argv[0][i]; @@ -302,7 +308,8 @@ abi int64_t WinMain(int64_t hInstance, int64_t hPrevInstance, cmdline = MyCommandLine(); #if SYSDEBUG // sloppy flag-only check for early initialization - if (StrStr(cmdline, u"--strace")) ++__strace; + if (StrStr(cmdline, u"--strace")) + ++__strace; #endif if (_weaken(WinSockInit)) { _weaken(WinSockInit)(); diff --git a/libc/runtime/zipos-fcntl.c b/libc/runtime/zipos-fcntl.c index 939ce56fa..0c1c799ad 100644 --- a/libc/runtime/zipos-fcntl.c +++ b/libc/runtime/zipos-fcntl.c @@ -28,7 +28,8 @@ static int __zipos_dupfd(int fd, int cmd, int start) { int rc; - if (start < 0) return einval(); + if (start < 0) + return einval(); if (IsWindows()) { return sys_dup_nt(fd, -1, (cmd == F_DUPFD_CLOEXEC ? _O_CLOEXEC : 0), start); diff --git a/libc/runtime/zipos-fstat.c b/libc/runtime/zipos-fstat.c index 4f0d4a40e..c1fd552fb 100644 --- a/libc/runtime/zipos-fstat.c +++ b/libc/runtime/zipos-fstat.c @@ -26,7 +26,8 @@ * @asyncsignalsafe */ int __zipos_fstat(struct ZiposHandle *h, struct stat *st) { - if (__zipos_stat_impl(h->zipos, h->cfile, st)) return -1; + if (__zipos_stat_impl(h->zipos, h->cfile, st)) + return -1; st->st_ino = __zipos_inode(h->zipos, h->cfile, h->data, h->size); return 0; } diff --git a/libc/runtime/zipos-get.c b/libc/runtime/zipos-get.c index b06e5f0e4..ba2506a05 100644 --- a/libc/runtime/zipos-get.c +++ b/libc/runtime/zipos-get.c @@ -54,14 +54,17 @@ static void __zipos_dismiss(uint8_t *map, const uint8_t *cdir, long pg) { n = GetZipCdirRecords(cdir); for (lo = c, hi = i = 0; i < n; ++i, c += ZIP_CFILE_HDRSIZE(map + c)) { lf = GetZipCfileOffset(map + c); - if (lf < lo) lo = lf; + if (lf < lo) + lo = lf; ef = lf + ZIP_LFILE_HDRSIZE(map + lf) + GetZipLfileCompressedSize(map + lf); - if (ef > hi) hi = ef; + if (ef > hi) + hi = ef; } // unmap the executable portion beneath the local files mo = ROUNDDOWN(lo, FRAMESIZE); - if (mo) munmap(map, mo); + if (mo) + munmap(map, mo); // this is supposed to reduce our rss usage but does it really? lo = ROUNDDOWN(lo, pg); @@ -81,7 +84,8 @@ static int __zipos_compare_names(const void *a, const void *b, void *c) { if (n) { int res = memcmp(ZIP_CFILE_NAME(z->map + *x), ZIP_CFILE_NAME(z->map + *y), n); - if (res) return res; + if (res) + return res; } return xn - yn; // xn and yn are 16-bit } diff --git a/libc/runtime/zipos-inode.c b/libc/runtime/zipos-inode.c index a406f496a..c4f26ae27 100644 --- a/libc/runtime/zipos-inode.c +++ b/libc/runtime/zipos-inode.c @@ -27,7 +27,8 @@ uint64_t __zipos_inode(struct Zipos *zipos, int64_t cfile, // const void *name, size_t namelen) { unassert(cfile >= 0); if (cfile == ZIPOS_SYNTHETIC_DIRECTORY) { - if (namelen && ((char *)name)[namelen - 1] == '/') --namelen; + if (namelen && ((char *)name)[namelen - 1] == '/') + --namelen; cfile = INT64_MIN | __fnv(name, namelen); } return cfile; diff --git a/libc/runtime/zipos-normpath.c b/libc/runtime/zipos-normpath.c index 2311c4110..81464671f 100644 --- a/libc/runtime/zipos-normpath.c +++ b/libc/runtime/zipos-normpath.c @@ -39,8 +39,10 @@ size_t __zipos_normpath(char *d, const char *s, size_t n) { s[1] == '.' && // (!s[2] || s[2] == '/')) { // matched "/../" or "^..$" or "^../" or "/..$" - while (p > d && p[-1] == '/') --p; - while (p > d && p[-1] != '/') --p; + while (p > d && p[-1] == '/') + --p; + while (p > d && p[-1] != '/') + --p; } else { *p++ = *s; } diff --git a/libc/runtime/zipos-notat.c b/libc/runtime/zipos-notat.c index 5c8e46e5a..2b27672e5 100644 --- a/libc/runtime/zipos-notat.c +++ b/libc/runtime/zipos-notat.c @@ -22,7 +22,8 @@ int __zipos_notat(int dirfd, const char *path) { struct ZiposUri zipname; - if (!path) return efault(); + if (!path) + return efault(); if (__isfdkind(dirfd, kFdZip) || __zipos_parseuri(path, &zipname) != -1) { return einval(); } diff --git a/libc/runtime/zipos-open.c b/libc/runtime/zipos-open.c index d3bb03555..25e89d48b 100644 --- a/libc/runtime/zipos-open.c +++ b/libc/runtime/zipos-open.c @@ -76,7 +76,8 @@ static void *__zipos_mmap_space(size_t mapsize) { offset = __zipos_maptotal; __zipos_maptotal += mapsize; start = (char *)kMemtrackZiposStart; - if (!__zipos_mapend) __zipos_mapend = start; + if (!__zipos_mapend) + __zipos_mapend = start; __zipos_mapend = _extend(start, __zipos_maptotal, __zipos_mapend, MAP_PRIVATE, kMemtrackZiposStart + kMemtrackZiposSize); return start + offset; @@ -98,7 +99,8 @@ void __zipos_drop(struct ZiposHandle *h) { h->mapsize - sizeof(struct ZiposHandle), kAsanHeapFree); } __zipos_lock(); - do h->next = h->zipos->freelist; + do + h->next = h->zipos->freelist; while (!_cmpxchg(&h->zipos->freelist, h->next, h)); __zipos_unlock(); } @@ -113,7 +115,8 @@ StartOver: ph = &zipos->freelist; while ((h = *ph)) { if (h->mapsize >= mapsize) { - if (!_cmpxchg(ph, h, h->next)) goto StartOver; + if (!_cmpxchg(ph, h, h->next)) + goto StartOver; break; } ph = &h->next; @@ -168,8 +171,10 @@ static int __zipos_load(struct Zipos *zipos, size_t cf, int flags, struct ZiposHandle *h; if (cf == ZIPOS_SYNTHETIC_DIRECTORY) { size = name->len; - if (!(h = __zipos_alloc(zipos, size + 1))) return -1; - if (size) memcpy(h->data, name->path, size); + if (!(h = __zipos_alloc(zipos, size + 1))) + return -1; + if (size) + memcpy(h->data, name->path, size); h->data[size] = 0; h->mem = h->data; } else { @@ -178,11 +183,13 @@ static int __zipos_load(struct Zipos *zipos, size_t cf, int flags, size = GetZipLfileUncompressedSize(zipos->map + lf); switch (ZIP_LFILE_COMPRESSIONMETHOD(zipos->map + lf)) { case kZipCompressionNone: - if (!(h = __zipos_alloc(zipos, 0))) return -1; + if (!(h = __zipos_alloc(zipos, 0))) + return -1; h->mem = ZIP_LFILE_CONTENT(zipos->map + lf); break; case kZipCompressionDeflate: - if (!(h = __zipos_alloc(zipos, size))) return -1; + if (!(h = __zipos_alloc(zipos, size))) + return -1; if (!__inflate(h->data, size, ZIP_LFILE_CONTENT(zipos->map + lf), GetZipLfileCompressedSize(zipos->map + lf))) { h->mem = h->data; diff --git a/libc/runtime/zipos-read.c b/libc/runtime/zipos-read.c index a7ca7c8be..7bb1ce215 100644 --- a/libc/runtime/zipos-read.c +++ b/libc/runtime/zipos-read.c @@ -53,7 +53,8 @@ static ssize_t __zipos_read_impl(struct ZiposHandle *h, const struct iovec *iov, } for (i = 0; i < iovlen && y < h->size; ++i, y += b) { b = MIN(iov[i].iov_len, h->size - y); - if (b) memcpy(iov[i].iov_base, h->mem + y, b); + if (b) + memcpy(iov[i].iov_base, h->mem + y, b); } if (opt_offset == -1) { unassert(y != SIZE_MAX); diff --git a/libc/runtime/zipos-stat.c b/libc/runtime/zipos-stat.c index 7f61e3bc7..30a20bc1b 100644 --- a/libc/runtime/zipos-stat.c +++ b/libc/runtime/zipos-stat.c @@ -29,9 +29,12 @@ int __zipos_stat(struct ZiposUri *name, struct stat *st) { ssize_t cf; struct Zipos *zipos; - if (!(zipos = __zipos_get())) return enoexec(); - if ((cf = __zipos_find(zipos, name)) == -1) return -1; - if (__zipos_stat_impl(zipos, cf, st)) return -1; + if (!(zipos = __zipos_get())) + return enoexec(); + if ((cf = __zipos_find(zipos, name)) == -1) + return -1; + if (__zipos_stat_impl(zipos, cf, st)) + return -1; st->st_ino = __zipos_inode(zipos, cf, name->path, name->len); return 0; } diff --git a/libc/sock/accept-nt.c b/libc/sock/accept-nt.c index 22e7cb549..b5dff0705 100644 --- a/libc/sock/accept-nt.c +++ b/libc/sock/accept-nt.c @@ -126,8 +126,10 @@ textwindows int sys_accept_nt(struct Fd *f, struct sockaddr_storage *addr, // create file descriptor for new socket // don't inherit the file open mode bits int oflags = 0; - if (accept4_flags & SOCK_CLOEXEC) oflags |= O_CLOEXEC; - if (accept4_flags & SOCK_NONBLOCK) oflags |= O_NONBLOCK; + if (accept4_flags & SOCK_CLOEXEC) + oflags |= O_CLOEXEC; + if (accept4_flags & SOCK_NONBLOCK) + oflags |= O_NONBLOCK; client = __reservefd(-1); g_fds.p[client].flags = oflags; g_fds.p[client].mode = 0140666; diff --git a/libc/sock/accept4-sysv.c b/libc/sock/accept4-sysv.c index 588f4ea85..20ed11c37 100644 --- a/libc/sock/accept4-sysv.c +++ b/libc/sock/accept4-sysv.c @@ -37,7 +37,8 @@ int sys_accept4(int server, struct sockaddr_storage *addr, int flags) { if (client == -1 && errno == ENOSYS) { // XNU/RHEL5/etc. don't support accept4(), but it's easilly polyfilled errno = olderr; - if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) return einval(); + if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) + return einval(); if ((client = __sys_accept(server, addr, &size, 0)) != -1) { // __sys_accept() has inconsistent flag inheritence across platforms // this is one of the issues that accept4() was invented for solving diff --git a/libc/sock/asanmsghdr.c b/libc/sock/asanmsghdr.c index 6c1ff3868..f9af26ab2 100644 --- a/libc/sock/asanmsghdr.c +++ b/libc/sock/asanmsghdr.c @@ -22,12 +22,15 @@ #if IsAsan() bool __asan_is_valid_msghdr(const struct msghdr *msg) { - if (!__asan_is_valid(msg, sizeof(struct msghdr))) return false; + if (!__asan_is_valid(msg, sizeof(struct msghdr))) + return false; if (msg->msg_name) { - if (!__asan_is_valid(msg->msg_name, msg->msg_namelen)) return false; + if (!__asan_is_valid(msg->msg_name, msg->msg_namelen)) + return false; } if (msg->msg_control) { - if (!__asan_is_valid(msg->msg_control, msg->msg_controllen)) return false; + if (!__asan_is_valid(msg->msg_control, msg->msg_controllen)) + return false; } return __asan_is_valid_iov(msg->msg_iov, msg->msg_iovlen); } diff --git a/libc/sock/basesocket.c b/libc/sock/basesocket.c index 570dbd87f..75ea4462e 100644 --- a/libc/sock/basesocket.c +++ b/libc/sock/basesocket.c @@ -37,8 +37,10 @@ textwindows int64_t GetNtBaseSocket(int64_t socket) { int64_t base_socket; for (;;) { base_socket = GetNtBspSocket(socket, kNtSioBaseHandle); - if (base_socket != -1) return base_socket; - if (WSAGetLastError() == WSAENOTSOCK) return __winsockerr(); + if (base_socket != -1) + return base_socket; + if (WSAGetLastError() == WSAENOTSOCK) + return __winsockerr(); /* * Even though Microsoft documentation clearly states that Layered * Spyware Providers must never ever intercept the SIO_BASE_HANDLE diff --git a/libc/sock/connect-nt.c b/libc/sock/connect-nt.c index 0615366d9..3065c51c4 100644 --- a/libc/sock/connect-nt.c +++ b/libc/sock/connect-nt.c @@ -63,7 +63,8 @@ void sys_connect_nt_cleanup(struct Fd *f, bool cancel) { struct NtOverlapped *overlap; if ((overlap = f->connect_op)) { uint32_t got, flags; - if (cancel) CancelIoEx(f->handle, overlap); + if (cancel) + CancelIoEx(f->handle, overlap); if (WSAGetOverlappedResult(f->handle, overlap, &got, cancel, &flags) || WSAGetLastError() != kNtErrorIoIncomplete) { WSACloseEvent(overlap->hEvent); @@ -92,13 +93,15 @@ static textwindows int sys_connect_nt_impl(struct Fd *f, const void *addr, cosmo_once(&g_connectex.once, connectex_init); // fail if previous connect() is still in progress - if (f->connect_op) return ealready(); + if (f->connect_op) + return ealready(); // ConnectEx() requires bind() be called beforehand if (!f->isbound) { struct sockaddr_storage ss = {0}; ss.ss_family = ((struct sockaddr *)addr)->sa_family; - if (sys_bind_nt(f, &ss, sizeof(ss)) == -1) return -1; + if (sys_bind_nt(f, &ss, sizeof(ss)) == -1) + return -1; } // perform normal connect @@ -119,7 +122,8 @@ static textwindows int sys_connect_nt_impl(struct Fd *f, const void *addr, // 2. poll(POLLOUT) bool32 ok; struct NtOverlapped *overlap = calloc(1, sizeof(struct NtOverlapped)); - if (!overlap) return -1; + if (!overlap) + return -1; overlap->hEvent = WSACreateEvent(); ok = g_connectex.lpConnectEx(f->handle, addr, addrsize, 0, 0, 0, overlap); if (ok) { diff --git a/libc/sock/epoll.c b/libc/sock/epoll.c index 4c86e35e1..1be06e4d5 100644 --- a/libc/sock/epoll.c +++ b/libc/sock/epoll.c @@ -144,7 +144,8 @@ https://github.com/piscisaureus/wepoll"); q->parent = parent; \ p->parent = q; \ p->trans = q->cis; \ - if (p->trans) p->trans->parent = p; \ + if (p->trans) \ + p->trans->parent = p; \ q->cis = p; #define TREE__INSERT_OR_DESCEND(side) \ @@ -402,7 +403,8 @@ static textwindows int afd_cancel_poll( struct NtIoStatusBlock cancel_iosb; /* If the poll operation has already completed or has been cancelled earlier, there's nothing left for us to do. */ - if (io_status_block->Status != kNtStatusPending) return 0; + if (io_status_block->Status != kNtStatusPending) + return 0; cancel_status = NtCancelIoFileEx(afd_device_handle, io_status_block, &cancel_iosb); /* NtCancelIoFileEx() may return STATUS_NOT_FOUND if the operation completed @@ -479,20 +481,23 @@ static textwindows void queue_remove(struct QueueNode *node) { static textwindows struct PortState *port__alloc(void) { struct PortState *port_state = malloc(sizeof *port_state); - if (!port_state) RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); + if (!port_state) + RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); return port_state; } static textwindows int64_t port__create_iocp(void) { int64_t iocp_handle = CreateIoCompletionPort(kNtInvalidHandleValue, 0, 0, 0); - if (!iocp_handle) RETURN_MAP_ERROR(0); + if (!iocp_handle) + RETURN_MAP_ERROR(0); return iocp_handle; } static textwindows int port__close_iocp(struct PortState *port_state) { int64_t iocp_handle = port_state->iocp_handle; port_state->iocp_handle = 0; - if (!CloseHandle(iocp_handle)) RETURN_MAP_ERROR(-1); + if (!CloseHandle(iocp_handle)) + RETURN_MAP_ERROR(-1); return 0; } @@ -569,9 +574,11 @@ static textwindows struct PortState *port_new(int64_t *iocp_handle_out) { struct PortState *port_state; int64_t iocp_handle; port_state = port__alloc(); - if (!port_state) goto err1; + if (!port_state) + goto err1; iocp_handle = port__create_iocp(); - if (!iocp_handle) goto err2; + if (!iocp_handle) + goto err2; bzero(port_state, sizeof *port_state); port_state->iocp_handle = iocp_handle; tree_init(&port_state->sock_tree); @@ -601,7 +608,8 @@ static textwindows int sock__cancel_poll(struct SockState *sock_state) { static textwindows void port_cancel_socket_update( struct PortState *port_state, struct SockState *sock_state) { - if (!queue_is_enqueued(sock_state_to_queue_node(sock_state))) return; + if (!queue_is_enqueued(sock_state_to_queue_node(sock_state))) + return; queue_remove(sock_state_to_queue_node(sock_state)); } @@ -623,7 +631,8 @@ static textwindows struct TreeNode *tree_find(const struct Tree *tree, static textwindows struct TsTreeNode *ts_tree__find_node(struct TsTree *ts_tree, uintptr_t key) { struct TreeNode *tree_node = tree_find(&ts_tree->tree, key); - if (!tree_node) return NULL; + if (!tree_node) + return NULL; return CONTAINOF(tree_node, struct TsTreeNode, tree_node); } @@ -639,7 +648,8 @@ static textwindows void tree_del(struct Tree *tree, struct TreeNode *node) { next = left; } else { next = right; - while (next->left) next = next->left; + while (next->left) + next = next->left; } if (parent) { if (parent->left == node) { @@ -671,14 +681,17 @@ static textwindows void tree_del(struct Tree *tree, struct TreeNode *node) { red = node->red; node = next; } - if (node) node->parent = parent; - if (red) return; + if (node) + node->parent = parent; + if (red) + return; if (node && node->red) { node->red = false; return; } do { - if (node == tree->root) break; + if (node == tree->root) + break; if (node == parent->left) { TREE__REBALANCE_AFTER_REMOVE(left, right) } else { @@ -687,19 +700,22 @@ static textwindows void tree_del(struct Tree *tree, struct TreeNode *node) { node = parent; parent = parent->parent; } while (!node->red); - if (node) node->red = false; + if (node) + node->red = false; } static textwindows void reflock__signal_event(void *address) { NtStatus status = NtReleaseKeyedEvent(reflock__keyed_event, address, false, NULL); - if (status != kNtStatusSuccess) abort(); + if (status != kNtStatusSuccess) + abort(); } static textwindows void reflock__await_event(void *address) { NtStatus status = NtWaitForKeyedEvent(reflock__keyed_event, address, false, NULL); - if (status != kNtStatusSuccess) abort(); + if (status != kNtStatusSuccess) + abort(); } static textwindows void reflock_ref(struct RefLock *reflock) { @@ -712,7 +728,8 @@ static textwindows void reflock_unref(struct RefLock *reflock) { long state = InterlockedAdd(&reflock->state, -REFLOCK__REF); /* Verify that the lock was referenced and not already destroyed.*/ npassert((state & REFLOCK__DESTROY_MASK & ~REFLOCK__DESTROY) == 0); - if (state == REFLOCK__DESTROY) reflock__signal_event(reflock); + if (state == REFLOCK__DESTROY) + reflock__signal_event(reflock); } static textwindows struct TsTreeNode *ts_tree_del_and_ref( @@ -733,7 +750,8 @@ static textwindows struct TsTreeNode *ts_tree_find_and_ref( struct TsTreeNode *ts_tree_node; AcquireSRWLockShared(&ts_tree->lock); ts_tree_node = ts_tree__find_node(ts_tree, key); - if (ts_tree_node != NULL) reflock_ref(&ts_tree_node->reflock); + if (ts_tree_node != NULL) + reflock_ref(&ts_tree_node->reflock); ReleaseSRWLockShared(&ts_tree->lock); return ts_tree_node; } @@ -748,7 +766,8 @@ static textwindows void reflock_unref_and_destroy(struct RefLock *reflock) { ref_count = state & REFLOCK__REF_MASK; /* Verify that the lock was referenced and not already destroyed. */ npassert((state & REFLOCK__DESTROY_MASK) == REFLOCK__DESTROY); - if (ref_count != 0) reflock__await_event(reflock); + if (ref_count != 0) + reflock__await_event(reflock); state = InterlockedExchange(&reflock->state, REFLOCK__POISON); npassert(state == REFLOCK__DESTROY); } @@ -765,7 +784,8 @@ static textwindows void port_unregister_socket(struct PortState *port_state, static textwindows void port_remove_deleted_socket( struct PortState *port_state, struct SockState *sock_state) { - if (!queue_is_enqueued(sock_state_to_queue_node(sock_state))) return; + if (!queue_is_enqueued(sock_state_to_queue_node(sock_state))) + return; queue_remove(sock_state_to_queue_node(sock_state)); } @@ -790,7 +810,8 @@ static textwindows void sock__free(struct SockState *sock_state) { static textwindows void port_add_deleted_socket(struct PortState *port_state, struct SockState *sock_state) { - if (queue_is_enqueued(sock_state_to_queue_node(sock_state))) return; + if (queue_is_enqueued(sock_state_to_queue_node(sock_state))) + return; queue_append(&port_state->sock_deleted_queue, sock_state_to_queue_node(sock_state)); } @@ -871,7 +892,8 @@ static textwindows struct PollGroup *poll_group__new( int64_t iocp_handle = port_get_iocp_handle(port_state); struct Queue *poll_group_queue = port_get_poll_group_queue(port_state); struct PollGroup *poll_group = malloc(sizeof *poll_group); - if (!poll_group) RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); + if (!poll_group) + RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); bzero(poll_group, sizeof *poll_group); queue_node_init(&poll_group->queue_node); poll_group->port_state = port_state; @@ -893,7 +915,8 @@ static textwindows struct PollGroup *poll_group_acquire( : NULL; if (!poll_group || poll_group->group_size >= MAX_GROUP_SIZE) poll_group = poll_group__new(port_state); - if (!poll_group) return NULL; + if (!poll_group) + return NULL; if (++poll_group->group_size == MAX_GROUP_SIZE) queue_move_to_start(poll_group_queue, &poll_group->queue_node); return poll_group; @@ -911,22 +934,33 @@ static textwindows uint32_t sock__epoll_events_to_afd_events(uint32_t e) { /* Always monitor for kNtAfdPollLocalClose, which is triggered when the socket is closed with closesocket() or CloseHandle(). */ uint32_t a = kNtAfdPollLocalClose; - if (e & (EPOLLIN | EPOLLRDNORM)) a |= kNtAfdPollReceive | kNtAfdPollAccept; - if (e & (EPOLLPRI | EPOLLRDBAND)) a |= kNtAfdPollReceiveExpedited; - if (e & (EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND)) a |= kNtAfdPollSend; - if (e & (EPOLLIN | EPOLLRDNORM | EPOLLRDHUP)) a |= kNtAfdPollDisconnect; - if (e & EPOLLHUP) a |= kNtAfdPollAbort; - if (e & EPOLLERR) a |= kNtAfdPollConnectFail; + if (e & (EPOLLIN | EPOLLRDNORM)) + a |= kNtAfdPollReceive | kNtAfdPollAccept; + if (e & (EPOLLPRI | EPOLLRDBAND)) + a |= kNtAfdPollReceiveExpedited; + if (e & (EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND)) + a |= kNtAfdPollSend; + if (e & (EPOLLIN | EPOLLRDNORM | EPOLLRDHUP)) + a |= kNtAfdPollDisconnect; + if (e & EPOLLHUP) + a |= kNtAfdPollAbort; + if (e & EPOLLERR) + a |= kNtAfdPollConnectFail; return a; } static textwindows uint32_t sock__afd_events_to_epoll_events(uint32_t a) { uint32_t e = 0; - if (a & (kNtAfdPollReceive | kNtAfdPollAccept)) e |= EPOLLIN | EPOLLRDNORM; - if (a & kNtAfdPollReceiveExpedited) e |= EPOLLPRI | EPOLLRDBAND; - if (a & kNtAfdPollSend) e |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND; - if (a & kNtAfdPollDisconnect) e |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; - if (a & kNtAfdPollAbort) e |= EPOLLHUP; + if (a & (kNtAfdPollReceive | kNtAfdPollAccept)) + e |= EPOLLIN | EPOLLRDNORM; + if (a & kNtAfdPollReceiveExpedited) + e |= EPOLLPRI | EPOLLRDBAND; + if (a & kNtAfdPollSend) + e |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND; + if (a & kNtAfdPollDisconnect) + e |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; + if (a & kNtAfdPollAbort) + e |= EPOLLHUP; if (a & kNtAfdPollConnectFail) { /* Linux reports all these events after connect() has failed. */ e |= EPOLLIN | EPOLLOUT | EPOLLERR | EPOLLRDNORM | EPOLLWRNORM | EPOLLRDHUP; @@ -950,7 +984,8 @@ static textwindows int sock_update(struct PortState *port_state, the pending *poll operation; when we receive it's completion package, a new poll *operation will be submitted with the correct event mask. */ - if (sock__cancel_poll(sock_state) < 0) return -1; + if (sock__cancel_poll(sock_state) < 0) + return -1; } else if (sock_state->poll_status == kPollCancelled) { /* The poll operation has already been cancelled, we're still waiting for it to return.For now, there' s nothing that needs to be done. */ @@ -995,7 +1030,8 @@ static textwindows int port__update_events(struct PortState *port_state) { while (!queue_is_empty(sock_update_queue)) { queue_node = queue_first(sock_update_queue); sock_state = sock_state_from_queue_node(queue_node); - if (sock_update(port_state, sock_state) < 0) return -1; + if (sock_update(port_state, sock_state) < 0) + return -1; /* sock_update() removes the socket from the update queue.*/ } return 0; @@ -1003,12 +1039,14 @@ static textwindows int port__update_events(struct PortState *port_state) { static textwindows void port__update_events_if_polling( struct PortState *port_state) { - if (port_state->active_poll_count > 0) port__update_events(port_state); + if (port_state->active_poll_count > 0) + port__update_events(port_state); } static textwindows void port_request_socket_update( struct PortState *port_state, struct SockState *sock_state) { - if (queue_is_enqueued(sock_state_to_queue_node(sock_state))) return; + if (queue_is_enqueued(sock_state_to_queue_node(sock_state))) + return; queue_append(&port_state->sock_update_queue, sock_state_to_queue_node(sock_state)); } @@ -1047,7 +1085,8 @@ static textwindows int sock_feed_event(struct PortState *port_state, /* Filter out events that the user didn't ask for. */ epoll_events &= sock_state->user_events; /* Return if there are no epoll events to report.*/ - if (epoll_events == 0) return 0; + if (epoll_events == 0) + return 0; /* If the the socket has the EPOLLONESHOT flag set, unmonitor all events, even EPOLLERR and EPOLLHUP. But always keep looking for closed sockets. */ @@ -1082,14 +1121,16 @@ static textwindows int port__poll(struct PortState *port_state, uint32_t maxevents, uint32_t timeout) { bool32 r; uint32_t completion_count; - if (port__update_events(port_state) < 0) return -1; + if (port__update_events(port_state) < 0) + return -1; port_state->active_poll_count++; LeaveCriticalSection(&port_state->lock); r = GetQueuedCompletionStatusEx(port_state->iocp_handle, iocp_events, maxevents, &completion_count, timeout, false); EnterCriticalSection(&port_state->lock); port_state->active_poll_count--; - if (!r) RETURN_MAP_ERROR(-1); + if (!r) + RETURN_MAP_ERROR(-1); return port__feed_events(port_state, epoll_events, iocp_events, completion_count); } @@ -1103,7 +1144,8 @@ static textwindows int port_wait(struct PortState *port_state, struct NtOverlappedEntry *iocp_events; struct NtOverlappedEntry stack_iocp_events[64]; /* Check whether `maxevents` is in range.*/ - if (maxevents <= 0) RETURN_SET_ERROR(-1, kNtErrorInvalidParameter); + if (maxevents <= 0) + RETURN_SET_ERROR(-1, kNtErrorInvalidParameter); /* Decide whether the IOCP completion list can live on the stack, or allocate memory for it on the heap. */ if ((size_t)maxevents <= ARRAYLEN(stack_iocp_events)) { @@ -1129,9 +1171,11 @@ static textwindows int port_wait(struct PortState *port_state, for (;;) { result = port__poll(port_state, events, iocp_events, (uint32_t)maxevents, gqcs_timeout); - if (result < 0 || result > 0) break; + if (result < 0 || result > 0) + break; /* Result, error, or time - out. */ - if (timeout < 0) continue; + if (timeout < 0) + continue; /* When timeout is negative, never time out. */ /* Update time. */ now = GetTickCount64(); @@ -1204,7 +1248,8 @@ static textwindows int64_t ws_get_base_socket(int64_t socket) { static textwindows struct SockState *sock__alloc(void) { struct SockState *sock_state = malloc(sizeof *sock_state); - if (!sock_state) RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); + if (!sock_state) + RETURN_SET_ERROR(NULL, kNtErrorNotEnoughMemory); return sock_state; } @@ -1223,19 +1268,24 @@ static textwindows struct SockState *sock_new(struct PortState *port_state, int64_t base_socket; struct PollGroup *poll_group; struct SockState *sock_state; - if (socket == 0 || socket == -1) RETURN_SET_ERROR(0, kNtErrorInvalidHandle); + if (socket == 0 || socket == -1) + RETURN_SET_ERROR(0, kNtErrorInvalidHandle); base_socket = ws_get_base_socket(socket); - if (base_socket == -1) return NULL; + if (base_socket == -1) + return NULL; poll_group = poll_group_acquire(port_state); - if (!poll_group) return NULL; + if (!poll_group) + return NULL; sock_state = sock__alloc(); - if (!sock_state) goto err1; + if (!sock_state) + goto err1; bzero(sock_state, sizeof *sock_state); sock_state->base_socket = base_socket; sock_state->poll_group = poll_group; tree_node_init(&sock_state->tree_node); queue_node_init(&sock_state->queue_node); - if (port_register_socket(port_state, sock_state, socket) < 0) goto err2; + if (port_register_socket(port_state, sock_state, socket) < 0) + goto err2; return sock_state; err2: sock__free(sock_state); @@ -1262,7 +1312,8 @@ static textwindows int sock_set_event(struct PortState *port_state, static textwindows int port__ctl_add(struct PortState *port_state, int64_t sock, struct epoll_event *ev) { struct SockState *sock_state = sock_new(port_state, sock); - if (!sock_state) return -1; + if (!sock_state) + return -1; if (sock_set_event(port_state, sock_state, ev) < 0) { sock_delete(port_state, sock_state); return -1; @@ -1274,15 +1325,18 @@ static textwindows int port__ctl_add(struct PortState *port_state, int64_t sock, static textwindows struct SockState *port_find_socket( struct PortState *port_state, int64_t socket) { struct TreeNode *tree_node = tree_find(&port_state->sock_tree, socket); - if (!tree_node) RETURN_SET_ERROR(NULL, kNtErrorNotFound); + if (!tree_node) + RETURN_SET_ERROR(NULL, kNtErrorNotFound); return sock_state_from_tree_node(tree_node); } static textwindows int port__ctl_mod(struct PortState *port_state, int64_t sock, struct epoll_event *ev) { struct SockState *sock_state = port_find_socket(port_state, sock); - if (!sock_state) return -1; - if (sock_set_event(port_state, sock_state, ev) < 0) return -1; + if (!sock_state) + return -1; + if (sock_set_event(port_state, sock_state, ev) < 0) + return -1; port__update_events_if_polling(port_state); return 0; } @@ -1290,7 +1344,8 @@ static textwindows int port__ctl_mod(struct PortState *port_state, int64_t sock, static textwindows int port__ctl_del(struct PortState *port_state, int64_t sock) { struct SockState *sock_state = port_find_socket(port_state, sock); - if (!sock_state) return -1; + if (!sock_state) + return -1; sock_delete(port_state, sock_state); return 0; } @@ -1328,9 +1383,11 @@ static textwindows dontinline int sys_epoll_create1_nt(uint32_t flags) { int64_t ephnd; struct PortState *port_state; struct TsTreeNode *tree_node; - if (wepoll_init() < 0) return -1; + if (wepoll_init() < 0) + return -1; fd = __reservefd(-1); - if (fd == -1) return -1; + if (fd == -1) + return -1; port_state = port_new(&ephnd); if (!port_state) { __releasefd(fd); @@ -1361,9 +1418,12 @@ static textwindows dontinline int sys_epoll_ctl_nt(int epfd, int op, int fd, if (!IsWindows()) { return sys_epoll_ctl(epfd, op, fd, ev); } else { - if (wepoll_init() < 0) return -1; - if (!__isfdopen(fd)) return ebadf(); - if (!__isfdkind(epfd, kFdEpoll)) return ebadf(); + if (wepoll_init() < 0) + return -1; + if (!__isfdopen(fd)) + return ebadf(); + if (!__isfdkind(epfd, kFdEpoll)) + return ebadf(); tree_node = ts_tree_find_and_ref(&epoll__handle_tree, g_fds.p[epfd].handle); if (!tree_node) { err_set_win_error(kNtErrorInvalidParameter); @@ -1372,7 +1432,8 @@ static textwindows dontinline int sys_epoll_ctl_nt(int epfd, int op, int fd, port_state = port_state_from_handle_tree_node(tree_node); r = port_ctl(port_state, op, g_fds.p[fd].handle, ev); ts_tree_node_unref(tree_node); - if (r < 0) goto err; + if (r < 0) + goto err; return 0; err: /* On Linux, in the case of epoll_ctl(), EBADF takes priority over @@ -1390,9 +1451,12 @@ static textwindows dontinline int sys_epoll_wait_nt(int epfd, int num_events; struct PortState *port_state; struct TsTreeNode *tree_node; - if (!__isfdkind(epfd, kFdEpoll)) return ebadf(); - if (maxevents <= 0) return einval(); - if (wepoll_init() < 0) return -1; + if (!__isfdkind(epfd, kFdEpoll)) + return ebadf(); + if (maxevents <= 0) + return einval(); + if (wepoll_init() < 0) + return -1; tree_node = ts_tree_find_and_ref(&epoll__handle_tree, g_fds.p[epfd].handle); if (!tree_node) { err_set_win_error(kNtErrorInvalidParameter); @@ -1401,7 +1465,8 @@ static textwindows dontinline int sys_epoll_wait_nt(int epfd, port_state = port_state_from_handle_tree_node(tree_node); num_events = port_wait(port_state, events, maxevents, timeoutms); ts_tree_node_unref(tree_node); - if (num_events < 0) goto err; + if (num_events < 0) + goto err; return num_events; err: err_check_handle(g_fds.p[epfd].handle); @@ -1412,7 +1477,8 @@ err: textwindows int sys_close_epoll_nt(int fd) { struct PortState *port_state; struct TsTreeNode *tree_node; - if (wepoll_init() < 0) return -1; + if (wepoll_init() < 0) + return -1; tree_node = ts_tree_del_and_ref(&epoll__handle_tree, g_fds.p[fd].handle); if (!tree_node) { err_set_win_error(kNtErrorInvalidParameter); @@ -1570,9 +1636,11 @@ int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, sizeof(*sigmask)); if (rc == -1 && errno == ENOSYS) { errno = e; - if (sigmask) sys_sigprocmask(SIG_SETMASK, sigmask, &oldmask); + if (sigmask) + sys_sigprocmask(SIG_SETMASK, sigmask, &oldmask); rc = sys_epoll_wait(epfd, events, maxevents, timeoutms); - if (sigmask) sys_sigprocmask(SIG_SETMASK, &oldmask, 0); + if (sigmask) + sys_sigprocmask(SIG_SETMASK, &oldmask, 0); } } else { BLOCK_SIGNALS; diff --git a/libc/sock/gethostips.c b/libc/sock/gethostips.c index ee00e78c4..4a402ac1e 100644 --- a/libc/sock/gethostips.c +++ b/libc/sock/gethostips.c @@ -37,7 +37,8 @@ static uint32_t *GetUnixIps(void) { uint64_t z; uint32_t *a; char *b, *p, *e, c[16]; - if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) == -1) return 0; + if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) == -1) + return 0; a = 0; n = 0; z = 15000; @@ -47,7 +48,8 @@ static uint32_t *GetUnixIps(void) { if (sys_ioctl(fd, SIOCGIFCONF, &c) != -1) { for (p = b, e = p + MIN(z, READ32LE(c)); p + 16 + 16 <= e; p += IsBsd() ? 16 + MAX(16, p[16] & 255) : 40) { - if ((p[IsBsd() ? 17 : 16] & 255) != AF_INET) continue; + if ((p[IsBsd() ? 17 : 16] & 255) != AF_INET) + continue; a = realloc(a, ++n * sizeof(*a)); a[n - 1] = READ32BE(p + 20); } @@ -66,13 +68,15 @@ static textwindows uint32_t *GetWindowsIps(void) { i = 0; z = 15000; do { - if (!(ifaces = malloc(z))) return 0; + if (!(ifaces = malloc(z))) + return 0; rc = GetAdaptersAddresses(AF_INET, kNtGaaFlagSkipAnycast | kNtGaaFlagSkipMulticast | kNtGaaFlagSkipDnsServer | kNtGaaFlagSkipFriendlyName, 0, ifaces, &z); - if (rc != kNtErrorBufferOverflow) break; + if (rc != kNtErrorBufferOverflow) + break; free(ifaces); ifaces = 0; } while (++i < 3); @@ -80,9 +84,11 @@ static textwindows uint32_t *GetWindowsIps(void) { a = calloc(1, sizeof(*a)); } else if (rc == kNtNoError) { for (a = 0, n = 0, p = ifaces; p; p = p->Next) { - if (p->OperStatus != kNtIfOperStatusUp) continue; + if (p->OperStatus != kNtIfOperStatusUp) + continue; for (u = p->FirstUnicastAddress; u; u = u->Next) { - if (u->Address.lpSockaddr->sa_family != AF_INET) continue; + if (u->Address.lpSockaddr->sa_family != AF_INET) + continue; a = realloc(a, ++n * sizeof(*a)); a[n - 1] = ntohl( ((struct sockaddr_in *)u->Address.lpSockaddr)->sin_addr.s_addr); diff --git a/libc/sock/goodsocket.c b/libc/sock/goodsocket.c index 3b0de25ba..910ca47a8 100644 --- a/libc/sock/goodsocket.c +++ b/libc/sock/goodsocket.c @@ -25,7 +25,8 @@ #include "libc/sysv/consts/tcp.h" static bool Tune(int fd, int a, int b, int x) { - if (!b) return false; + if (!b) + return false; return setsockopt(fd, a, b, &x, sizeof(x)) != -1; } diff --git a/libc/sock/inet_aton.c b/libc/sock/inet_aton.c index c826cb955..d08e5c0d9 100644 --- a/libc/sock/inet_aton.c +++ b/libc/sock/inet_aton.c @@ -42,11 +42,14 @@ int inet_aton(const char *s0, struct in_addr *dest) { int i; for (i = 0; i < 4; i++) { a[i] = strtoul(s, &z, 0); - if (z == s || (*z && *z != '.') || !isdigit(*s)) return 0; - if (!*z) break; + if (z == s || (*z && *z != '.') || !isdigit(*s)) + return 0; + if (!*z) + break; s = z + 1; } - if (i == 4) return 0; + if (i == 4) + return 0; switch (i) { case 0: a[1] = a[0] & 0xffffff; @@ -59,7 +62,8 @@ int inet_aton(const char *s0, struct in_addr *dest) { a[2] >>= 8; } for (i = 0; i < 4; i++) { - if (a[i] > 255) return 0; + if (a[i] > 255) + return 0; d[i] = a[i]; } return 1; diff --git a/libc/sock/inet_ntop.c b/libc/sock/inet_ntop.c index 5018a0c89..578ebc26e 100644 --- a/libc/sock/inet_ntop.c +++ b/libc/sock/inet_ntop.c @@ -35,7 +35,8 @@ const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) { int i, t, a, b, c, d; const unsigned char *ip; p = dst; - if (!size) return dst; + if (!size) + return dst; if ((ip = src)) { if (af == AF_INET) { if (size >= 16) { @@ -84,9 +85,12 @@ const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) { b = (ip[i + 0] & 0x0F) >> 0; c = (ip[i + 1] & 0xF0) >> 4; d = (ip[i + 1] & 0x0F) >> 0; - if (a) *p++ = "0123456789abcdef"[a]; - if (a || b) *p++ = "0123456789abcdef"[b]; - if (a || b || c) *p++ = "0123456789abcdef"[c]; + if (a) + *p++ = "0123456789abcdef"[a]; + if (a || b) + *p++ = "0123456789abcdef"[b]; + if (a || b || c) + *p++ = "0123456789abcdef"[c]; *p++ = "0123456789abcdef"[d]; } *p = '\0'; diff --git a/libc/sock/inet_pton.c b/libc/sock/inet_pton.c index 332c59b18..5693977b9 100644 --- a/libc/sock/inet_pton.c +++ b/libc/sock/inet_pton.c @@ -159,8 +159,10 @@ static int inet_pton_inet6_impl(const char *src, uint8_t *dst) { int inet_pton(int af, const char *src, void *dst) { uint8_t *p; int b, c, j; - if (af == AF_INET6) return inet_pton_inet6_impl(src, dst); - if (af != AF_INET) return eafnosupport(); + if (af == AF_INET6) + return inet_pton_inet6_impl(src, dst); + if (af != AF_INET) + return eafnosupport(); j = 0; p = dst; p[0] = 0; @@ -168,9 +170,11 @@ int inet_pton(int af, const char *src, void *dst) { if (isdigit(c)) { b = c - '0' + p[j] * 10; p[j] = MIN(255, b); - if (b > 255) return 0; + if (b > 255) + return 0; } else if (c == '.') { - if (++j == 4) return 0; + if (++j == 4) + return 0; p[j] = 0; } else { return 0; diff --git a/libc/sock/recvfrom-nt.c b/libc/sock/recvfrom-nt.c index 101277262..25d571ad7 100644 --- a/libc/sock/recvfrom-nt.c +++ b/libc/sock/recvfrom-nt.c @@ -55,7 +55,8 @@ textwindows ssize_t sys_recvfrom_nt(int fd, const struct iovec *iov, size_t iovlen, uint32_t flags, void *opt_out_srcaddr, uint32_t *opt_inout_srcaddrsize) { - if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_PEEK)) return einval(); + if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_PEEK)) + return einval(); ssize_t rc; struct Fd *f = g_fds.p + fd; sigset_t m = __sig_block(); diff --git a/libc/sock/recvmsg.c b/libc/sock/recvmsg.c index caac4fc50..85c3fc761 100644 --- a/libc/sock/recvmsg.c +++ b/libc/sock/recvmsg.c @@ -113,7 +113,8 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags) { kprintf(".name=%#.*hhs, ", msg->msg_namelen, msg->msg_name); if (msg->msg_controllen) kprintf(".control=%#.*hhs, ", msg->msg_controllen, msg->msg_control); - if (msg->msg_flags) kprintf(".flags=%#x, ", msg->msg_flags); + if (msg->msg_flags) + kprintf(".flags=%#x, ", msg->msg_flags); kprintf(".iov=%s", DescribeIovec(rc, msg->msg_iov, msg->msg_iovlen)); kprintf("], %#x) → %'ld% m\n", flags, rc); } diff --git a/libc/sock/send-nt.c b/libc/sock/send-nt.c index 667f1082e..a186159b2 100644 --- a/libc/sock/send-nt.c +++ b/libc/sock/send-nt.c @@ -49,7 +49,8 @@ static textwindows int sys_send_nt_start(int64_t handle, textwindows ssize_t sys_send_nt(int fd, const struct iovec *iov, size_t iovlen, uint32_t flags) { - if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_DONTROUTE)) return einval(); + if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_DONTROUTE)) + return einval(); ssize_t rc; struct Fd *f = g_fds.p + fd; sigset_t m = __sig_block(); diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index 9e0865233..633c81273 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -65,8 +65,10 @@ static dontinline textwindows ssize_t sys_sendfile_nt( uint32_t flags = 0; int64_t ih, oh, eof, offset; struct NtByHandleFileInformation wst; - if (!__isfdkind(infd, kFdFile)) return ebadf(); - if (!__isfdkind(outfd, kFdSocket)) return ebadf(); + if (!__isfdkind(infd, kFdFile)) + return ebadf(); + if (!__isfdkind(outfd, kFdSocket)) + return ebadf(); ih = g_fds.p[infd].handle; oh = g_fds.p[outfd].handle; if (opt_in_out_inoffset) { @@ -119,12 +121,14 @@ static ssize_t sys_sendfile_bsd(int outfd, int infd, } if (IsFreebsd()) { rc = sys_sendfile_freebsd(infd, outfd, offset, uptobytes, 0, &sbytes, 0); - if (rc == -1 && errno == ENOBUFS) errno = ENOMEM; + if (rc == -1 && errno == ENOBUFS) + errno = ENOMEM; } else { sbytes = uptobytes; rc = sys_sendfile_xnu(infd, outfd, offset, &sbytes, 0, 0); } - if (rc == -1 && errno == ENOTSOCK) errno = EBADF; + if (rc == -1 && errno == ENOTSOCK) + errno = EBADF; if (rc != -1) { if (opt_in_out_inoffset) { *opt_in_out_inoffset += sbytes; diff --git a/libc/sock/sendmsg.c b/libc/sock/sendmsg.c index 5fd2dae11..2eb0c7f5b 100644 --- a/libc/sock/sendmsg.c +++ b/libc/sock/sendmsg.c @@ -99,7 +99,8 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) { kprintf(".name=%#.*hhs, ", msg->msg_namelen, msg->msg_name); if (msg->msg_controllen) kprintf(", .control=%#.*hhs, ", msg->msg_controllen, msg->msg_control); - if (msg->msg_flags) kprintf(".flags=%#x, ", msg->msg_flags); + if (msg->msg_flags) + kprintf(".flags=%#x, ", msg->msg_flags); kprintf(", .iov=%s", DescribeIovec(rc != -1 ? rc : -2, msg->msg_iov, msg->msg_iovlen)); } diff --git a/libc/sock/sendto-nt.c b/libc/sock/sendto-nt.c index b49e3559e..e6fdb1f17 100644 --- a/libc/sock/sendto-nt.c +++ b/libc/sock/sendto-nt.c @@ -52,7 +52,8 @@ static textwindows int sys_sendto_nt_start(int64_t handle, textwindows ssize_t sys_sendto_nt(int fd, const struct iovec *iov, size_t iovlen, uint32_t flags, void *opt_in_addr, uint32_t in_addrsize) { - if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_DONTROUTE)) return einval(); + if (flags & ~(_MSG_DONTWAIT | _MSG_OOB | _MSG_DONTROUTE)) + return einval(); ssize_t rc; struct Fd *f = g_fds.p + fd; sigset_t m = __sig_block(); diff --git a/libc/sock/setsockopt-nt.c b/libc/sock/setsockopt-nt.c index 0c2c6e522..c6a79b57a 100644 --- a/libc/sock/setsockopt-nt.c +++ b/libc/sock/setsockopt-nt.c @@ -38,12 +38,16 @@ textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname, // socket read/write timeouts if (level == SOL_SOCKET && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)) { - if (!(optval && optlen == sizeof(struct timeval))) return einval(); + if (!(optval && optlen == sizeof(struct timeval))) + return einval(); const struct timeval *tv = optval; int64_t ms = timeval_tomillis(*tv); - if (ms >= 0xffffffffu) ms = 0; // wait forever (default) - if (optname == SO_RCVTIMEO) fd->rcvtimeo = ms; - if (optname == SO_SNDTIMEO) fd->sndtimeo = ms; + if (ms >= 0xffffffffu) + ms = 0; // wait forever (default) + if (optname == SO_RCVTIMEO) + fd->rcvtimeo = ms; + if (optname == SO_SNDTIMEO) + fd->sndtimeo = ms; return 0; // we want to handle this on our own } diff --git a/libc/sock/sockaddr.c b/libc/sock/sockaddr.c index b038cc3ef..f72f664ac 100644 --- a/libc/sock/sockaddr.c +++ b/libc/sock/sockaddr.c @@ -64,12 +64,16 @@ void __convert_sockaddr_to_bsd(struct sockaddr_storage *addr) { // copies sockaddr from internal memory to user's buffer void __write_sockaddr(const struct sockaddr_storage *addr, void *out_addr, uint32_t *inout_addrsize) { - if (!out_addr) return; - if (!inout_addrsize) return; + if (!out_addr) + return; + if (!inout_addrsize) + return; uint32_t insize = *inout_addrsize; - if (insize) bzero(out_addr, insize); + if (insize) + bzero(out_addr, insize); uint32_t outsize = __get_sockaddr_len(addr); uint32_t copysize = MIN(insize, outsize); - if (copysize) memcpy(out_addr, addr, copysize); + if (copysize) + memcpy(out_addr, addr, copysize); *inout_addrsize = outsize; } diff --git a/libc/sock/sockaddr2linux.c b/libc/sock/sockaddr2linux.c index 7482b8847..69efdb9f1 100644 --- a/libc/sock/sockaddr2linux.c +++ b/libc/sock/sockaddr2linux.c @@ -64,7 +64,8 @@ void sockaddr2linux(const union sockaddr_storage_bsd *addr, uint32_t addrsize, sizeof(addr->sun.sun_family)), size - sizeof(out_addr->sun.sun_family))); out_addr->sun.sun_family = AF_UNIX; - if (len) memcpy(out_addr->sun.sun_path, addr->sun.sun_path, len); + if (len) + memcpy(out_addr->sun.sun_path, addr->sun.sun_path, len); *inout_addrsize = sizeof(out_addr->sun.sun_family) + len + 1; } } diff --git a/libc/sock/sockatmark.c b/libc/sock/sockatmark.c index 49dba8a1e..767305d7b 100644 --- a/libc/sock/sockatmark.c +++ b/libc/sock/sockatmark.c @@ -30,8 +30,10 @@ static textwindows int sockatmark_nt(int fd, unsigned long magnum) { bool32 res; int64_t hand; uint32_t bytes; - if (fd >= g_fds.n) return ebadf(); - if (g_fds.p[fd].kind != kFdSocket) return einval(); + if (fd >= g_fds.n) + return ebadf(); + if (g_fds.p[fd].kind != kFdSocket) + return einval(); hand = g_fds.p[fd].handle; if (WSAIoctl(hand, magnum, 0, 0, &res, sizeof(res), &bytes, 0, 0) == -1) { return __winsockerr(); diff --git a/libc/sock/sockdebug.c b/libc/sock/sockdebug.c index 97f5074ff..89e029fba 100644 --- a/libc/sock/sockdebug.c +++ b/libc/sock/sockdebug.c @@ -64,7 +64,8 @@ const char *(DescribeSockaddr)(char buf[128], const struct sockaddr *sa, unix = (const struct sockaddr_un *)sa; n = strnlen(unix->sun_path, sizeof(unix->sun_path)); n = MIN(n, 128 - 1); - if (n) memcpy(buf, unix->sun_path, n); + if (n) + memcpy(buf, unix->sun_path, n); buf[n] = 0; } } diff --git a/libc/sock/socket-nt.c b/libc/sock/socket-nt.c index c993401b8..31954a708 100644 --- a/libc/sock/socket-nt.c +++ b/libc/sock/socket-nt.c @@ -34,13 +34,16 @@ textwindows int sys_socket_nt(int family, int type, int protocol) { int64_t h; int fd, oflags, truetype; fd = __reservefd(-1); - if (fd == -1) return -1; + if (fd == -1) + return -1; truetype = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK); if ((h = WSASocket(family, truetype, protocol, NULL, 0, kNtWsaFlagOverlapped)) != -1) { oflags = O_RDWR; - if (type & SOCK_CLOEXEC) oflags |= O_CLOEXEC; - if (type & SOCK_NONBLOCK) oflags |= O_NONBLOCK; + if (type & SOCK_CLOEXEC) + oflags |= O_CLOEXEC; + if (type & SOCK_NONBLOCK) + oflags |= O_NONBLOCK; g_fds.p[fd].family = family; g_fds.p[fd].type = truetype; g_fds.p[fd].protocol = protocol; diff --git a/libc/sock/socketpair-nt.c b/libc/sock/socketpair-nt.c index d7f241f07..8a6bdb625 100644 --- a/libc/sock/socketpair-nt.c +++ b/libc/sock/socketpair-nt.c @@ -45,7 +45,8 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) { } oflags = 0; - if (type & SOCK_CLOEXEC) oflags |= O_CLOEXEC; + if (type & SOCK_CLOEXEC) + oflags |= O_CLOEXEC; type &= ~SOCK_CLOEXEC; if (type == SOCK_STREAM) { @@ -62,8 +63,10 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) { writer = __reservefd_unlocked(-1); __fds_unlock(); if (reader == -1 || writer == -1) { - if (reader != -1) __releasefd(reader); - if (writer != -1) __releasefd(writer); + if (reader != -1) + __releasefd(reader); + if (writer != -1) + __releasefd(writer); return -1; } if ((hpipe = CreateNamedPipe( diff --git a/libc/sock/socketpair-sysv.c b/libc/sock/socketpair-sysv.c index c3d7a647d..cbe1da77a 100644 --- a/libc/sock/socketpair-sysv.c +++ b/libc/sock/socketpair-sysv.c @@ -23,7 +23,8 @@ int sys_socketpair(int family, int type, int protocol, int sv[2]) { int e = errno; - if (__sys_socketpair(family, type, protocol, sv) != -1) return 0; + if (__sys_socketpair(family, type, protocol, sv) != -1) + return 0; if ((type & (SOCK_CLOEXEC | SOCK_NONBLOCK)) && (errno == EINVAL || errno == EPROTOTYPE || errno == EPROTONOSUPPORT)) { errno = e; diff --git a/libc/sock/socketpair.c b/libc/sock/socketpair.c index 22d2e3c77..d208910eb 100644 --- a/libc/sock/socketpair.c +++ b/libc/sock/socketpair.c @@ -37,7 +37,8 @@ * @asyncsignalsafe */ int socketpair(int family, int type, int protocol, int sv[2]) { - if (family == AF_UNSPEC) family = AF_UNIX; + if (family == AF_UNSPEC) + family = AF_UNIX; if (!IsWindows()) { return sys_socketpair(family, type, protocol, sv); } else { diff --git a/libc/sock/syslog.c b/libc/sock/syslog.c index 2a3ed5595..771394cbb 100644 --- a/libc/sock/syslog.c +++ b/libc/sock/syslog.c @@ -62,7 +62,8 @@ static struct sockaddr_un log_addr = {AF_UNIX, "/dev/log"}; static int64_t Time(int64_t *tp) { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - if (tp) *tp = ts.tv_sec; + if (tp) + *tp = ts.tv_sec; return ts.tv_sec; } @@ -125,8 +126,10 @@ void vsyslog(int priority, const char *message, va_list ap) { int hlen; /* If LOG_CONS is specified, use to store the point in * the header message after the timestamp */ BLOCK_CANCELATION; - if (log_fd < 0) __openlog(); - if (!(priority & LOG_FACMASK)) priority |= log_facility; + if (log_fd < 0) + __openlog(); + if (!(priority & LOG_FACMASK)) + priority |= log_facility; /* Build the time string */ now = Time(NULL); gmtime_r(&now, &tm); @@ -226,9 +229,11 @@ void vsyslog(int priority, const char *message, va_list ap) { */ int setlogmask(int maskpri) { int ret; - if (log_facility == -1) __initlog(); + if (log_facility == -1) + __initlog(); ret = log_mask; - if (maskpri) log_mask = LOG_PRI(maskpri); + if (maskpri) + log_mask = LOG_PRI(maskpri); return ret; } @@ -261,13 +266,16 @@ int setlogmask(int maskpri) { */ void openlog(const char *ident, int opt, int facility) { BLOCK_CANCELATION; - if (log_facility == -1) __initlog(); - if (!ident) ident = firstnonnull(program_invocation_short_name, "unknown"); + if (log_facility == -1) + __initlog(); + if (!ident) + ident = firstnonnull(program_invocation_short_name, "unknown"); tprecode8to16(log_ident, ARRAYLEN(log_ident), ident); log_opt = opt; log_facility = facility; log_id = 0; - if ((opt & LOG_NDELAY) && log_fd < 0) __openlog(); + if ((opt & LOG_NDELAY) && log_fd < 0) + __openlog(); ALLOW_CANCELATION; } diff --git a/libc/sock/winsockblock.c b/libc/sock/winsockblock.c index 8a21df234..e0d0b2848 100644 --- a/libc/sock/winsockblock.c +++ b/libc/sock/winsockblock.c @@ -42,7 +42,8 @@ __winsock_block(int64_t handle, uint32_t flags, bool nonblock, RestartOperation: int rc, sig, reason = 0; uint32_t status, exchanged; - if (_check_cancel() == -1) return -1; // ECANCELED + if (_check_cancel() == -1) + return -1; // ECANCELED if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { goto HandleInterrupt; } @@ -93,8 +94,10 @@ RestartOperation: if (_weaken(__sig_get) && (sig = _weaken(__sig_get)(waitmask))) { HandleInterrupt: int handler_was_called = _weaken(__sig_relay)(sig, SI_KERNEL, waitmask); - if (_check_cancel() == -1) return -1; - if (handler_was_called != 1) goto RestartOperation; + if (_check_cancel() == -1) + return -1; + if (handler_was_called != 1) + goto RestartOperation; } return eintr(); } diff --git a/libc/stdio/__freadptr.c b/libc/stdio/__freadptr.c index e90ff8b2e..11c454d6b 100644 --- a/libc/stdio/__freadptr.c +++ b/libc/stdio/__freadptr.c @@ -20,7 +20,8 @@ #include "libc/stdio/stdio_ext.h" const char *__freadptr(FILE *f, size_t *sizep) { - if (f->beg == f->end) return 0; + if (f->beg == f->end) + return 0; *sizep = f->end - f->beg; return (const char *)f->buf + f->beg; } diff --git a/libc/stdio/appendd.c b/libc/stdio/appendd.c index 62e44cc92..409f5d550 100644 --- a/libc/stdio/appendd.c +++ b/libc/stdio/appendd.c @@ -48,8 +48,10 @@ ssize_t appendd(char **b, const void *s, size_t l) { z = appendz((p = *b)); n = ROUNDUP(z.i + l + 1, 8) + W; if (n > z.n) { - if (!z.n) z.n = W * 2; - while (n > z.n) z.n += z.n >> 1; + if (!z.n) + z.n = W * 2; + while (n > z.n) + z.n += z.n >> 1; z.n = ROUNDUP(z.n, W); if ((p = realloc(p, z.n))) { z.n = malloc_usable_size(p); @@ -65,7 +67,8 @@ ssize_t appendd(char **b, const void *s, size_t l) { p[z.i] = 0; } z.i += l; - if (!IsTiny() && W == 8) z.i |= (size_t)APPEND_COOKIE << 48; + if (!IsTiny() && W == 8) + z.i |= (size_t)APPEND_COOKIE << 48; *(size_t *)(p + z.n - W) = z.i; return l; } diff --git a/libc/stdio/appendstrlist.c b/libc/stdio/appendstrlist.c index e9ec4f180..71e4b05a5 100644 --- a/libc/stdio/appendstrlist.c +++ b/libc/stdio/appendstrlist.c @@ -25,7 +25,8 @@ int AppendStrList(struct StrList *sl) { char **p2; if (sl->i == sl->n) { n2 = sl->n; - if (!n2) n2 = 2; + if (!n2) + n2 = 2; n2 += n2 >> 1; if ((p2 = realloc(sl->p, n2 * sizeof(*p2)))) { sl->p = p2; diff --git a/libc/stdio/appendw.c b/libc/stdio/appendw.c index c5848b70d..9c90ff6d0 100644 --- a/libc/stdio/appendw.c +++ b/libc/stdio/appendw.c @@ -62,8 +62,10 @@ ssize_t appendw(char **b, uint64_t w) { l = w ? (bsrl(w) >> 3) + 1 : 1; n = ROUNDUP(z.i + 8 + 1, 8) + W; if (n > z.n) { - if (!z.n) z.n = W * 2; - while (n > z.n) z.n += z.n >> 1; + if (!z.n) + z.n = W * 2; + while (n > z.n) + z.n += z.n >> 1; z.n = ROUNDUP(z.n, W); if ((p = realloc(p, z.n))) { z.n = malloc_usable_size(p); @@ -77,7 +79,8 @@ ssize_t appendw(char **b, uint64_t w) { WRITE64LE(q, w); q[8] = 0; z.i += l; - if (!IsTiny() && W == 8) z.i |= (size_t)APPEND_COOKIE << 48; + if (!IsTiny() && W == 8) + z.i |= (size_t)APPEND_COOKIE << 48; *(size_t *)(p + z.n - W) = z.i; return l; } diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index 0ba27eadb..2f080fabe 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -214,7 +214,8 @@ TryAgain: // e.g. \\?\C:\ stays the same } else { --i; // foo\bar\ -> foo\ (parent) - while (i && jp[i - 1] != '\\') --i; + while (i && jp[i - 1] != '\\') + --i; } } else { while (*p) { @@ -259,7 +260,8 @@ GiveUpOnGettingInode: dir->windata.cFileName); dir->ent.d_type = GetNtDirentType(&dir->windata); dir->isdone = !FindNextFile(dir->hand, &dir->windata); - if (pretend_this_file_doesnt_exist) goto TryAgain; + if (pretend_this_file_doesnt_exist) + goto TryAgain; return &dir->ent; } @@ -332,7 +334,8 @@ DIR *fdopendir(int fd) { enametoolong(); return 0; } - if (len) memcpy(dir->zip.prefix.path, name, len); + if (len) + memcpy(dir->zip.prefix.path, name, len); if (len && dir->zip.prefix.path[len - 1] != '/') { dir->zip.prefix.path[len++] = '/'; } @@ -379,7 +382,8 @@ DIR *opendir(const char *name) { return 0; } DIR *res = fdopendir(fd); - if (!res) close(fd); + if (!res) + close(fd); return res; } @@ -402,10 +406,14 @@ static struct dirent *readdir_zipos(DIR *dir) { ent->d_name[2] = 0; struct ZiposUri p; p.len = dir->zip.prefix.len; - if (p.len) memcpy(p.path, dir->zip.prefix.path, p.len); - while (p.len && p.path[p.len - 1] == '/') --p.len; - while (p.len && p.path[p.len - 1] != '/') --p.len; - while (p.len && p.path[p.len - 1] == '/') --p.len; + if (p.len) + memcpy(p.path, dir->zip.prefix.path, p.len); + while (p.len && p.path[p.len - 1] == '/') + --p.len; + while (p.len && p.path[p.len - 1] != '/') + --p.len; + while (p.len && p.path[p.len - 1] == '/') + --p.len; p.path[p.len] = 0; ent->d_ino = __zipos_inode( dir->zip.zipos, __zipos_scan(dir->zip.zipos, &p), p.path, p.len); diff --git a/libc/stdio/dumphexc.c b/libc/stdio/dumphexc.c index d096997f8..3bf900cb6 100644 --- a/libc/stdio/dumphexc.c +++ b/libc/stdio/dumphexc.c @@ -29,7 +29,8 @@ char *DumpHexc(const char *p, size_t n, size_t *z) { long o; int i, m; char A[128], *q, *s = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; appendw(&s, '"' | '\\' << 8 | '\n' << 16); for (o = 0; (m = MIN(16, n)); p += m, n -= m) { q = A; @@ -39,12 +40,14 @@ char *DumpHexc(const char *p, size_t n, size_t *z) { *q++ = "0123456789abcdef"[(p[i] & 0xF0) >> 4]; *q++ = "0123456789abcdef"[(p[i] & 0x0F) >> 0]; } - if (o) appendw(&s, '\\' | '\n' << 8); + if (o) + appendw(&s, '\\' | '\n' << 8); appendd(&s, A, q - A); o += m; } if (appendw(&s, '"') != -1) { - if (z) *z = appendz(s).i; + if (z) + *z = appendz(s).i; return s; } else { free(s); diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c index da0b4521c..b02c8bf20 100644 --- a/libc/stdio/fclose.c +++ b/libc/stdio/fclose.c @@ -35,7 +35,8 @@ */ int fclose(FILE *f) { int rc; - if (!f) return 0; + if (!f) + return 0; __fflush_unregister(f); fflush(f); if (_weaken(free)) { diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c index 7cf55d4d1..4a9ef6c8e 100644 --- a/libc/stdio/fflush.c +++ b/libc/stdio/fflush.c @@ -26,8 +26,10 @@ */ int fflush(FILE *f) { int rc; - if (f) flockfile(f); + if (f) + flockfile(f); rc = fflush_unlocked(f); - if (f) funlockfile(f); + if (f) + funlockfile(f); return rc; } diff --git a/libc/stdio/fgetc_unlocked.c b/libc/stdio/fgetc_unlocked.c index 33b4d55b1..9a1d784e6 100644 --- a/libc/stdio/fgetc_unlocked.c +++ b/libc/stdio/fgetc_unlocked.c @@ -31,7 +31,8 @@ int fgetc_unlocked(FILE *f) { if (f->beg < f->end) { return f->buf[f->beg++] & 255; } else { - if (!fread_unlocked(b, 1, 1, f)) return -1; + if (!fread_unlocked(b, 1, 1, f)) + return -1; return b[0]; } } diff --git a/libc/stdio/fgetln.c b/libc/stdio/fgetln.c index a6277eabb..74edcdcd8 100644 --- a/libc/stdio/fgetln.c +++ b/libc/stdio/fgetln.c @@ -46,7 +46,8 @@ char *fgetln(FILE *stream, size_t *len) { size_t n = 0; flockfile(stream); if ((rc = getdelim_unlocked(&stream->getln, &n, '\n', stream)) > 0) { - if (len) *len = rc; + if (len) + *len = rc; res = stream->getln; } else { res = 0; diff --git a/libc/stdio/fgets_unlocked.c b/libc/stdio/fgets_unlocked.c index b910fbc34..c01a3105e 100644 --- a/libc/stdio/fgets_unlocked.c +++ b/libc/stdio/fgets_unlocked.c @@ -48,11 +48,13 @@ char *fgets_unlocked(char *s, int size, FILE *f) { if ((t = memchr(b, '\n', n))) { n = t + 1 - b; } - if (n) memcpy(p, b, n); + if (n) + memcpy(p, b, n); f->beg += n; size -= n - 1; p += n; - if (t) break; + if (t) + break; } else { if ((c = fgetc_unlocked(f)) == -1) { if (ferror_unlocked(f) == EINTR) { @@ -62,7 +64,8 @@ char *fgets_unlocked(char *s, int size, FILE *f) { } } *p++ = c & 255; - if (c == '\n') break; + if (c == '\n') + break; } } if (p > s || f->state != -1) { diff --git a/libc/stdio/fgetwc_unlocked.c b/libc/stdio/fgetwc_unlocked.c index a90f86122..0f442fed6 100644 --- a/libc/stdio/fgetwc_unlocked.c +++ b/libc/stdio/fgetwc_unlocked.c @@ -35,11 +35,13 @@ wint_t fgetwc_unlocked(FILE *f) { } else { return -1; } - if (b < 0300) return b; + if (b < 0300) + return b; n = ThomPikeLen(b); x = ThomPikeByte(b); while (--n) { - if ((c = fgetc_unlocked(f)) == -1) return -1; + if ((c = fgetc_unlocked(f)) == -1) + return -1; y = c; if (ThomPikeCont(y)) { x = ThomPikeMerge(x, y); diff --git a/libc/stdio/fgetws_unlocked.c b/libc/stdio/fgetws_unlocked.c index c8108529b..3a7978327 100644 --- a/libc/stdio/fgetws_unlocked.c +++ b/libc/stdio/fgetws_unlocked.c @@ -38,11 +38,13 @@ wchar_t *fgetws_unlocked(wchar_t *s, int size, FILE *f) { if (size > 0) { while (--size > 0) { if ((c = fgetwc_unlocked(f)) == -1) { - if (ferror_unlocked(f) == EINTR) continue; + if (ferror_unlocked(f) == EINTR) + continue; break; } *p++ = c; - if (c == '\n') break; + if (c == '\n') + break; } *p = '\0'; } diff --git a/libc/stdio/fmemopen.c b/libc/stdio/fmemopen.c index 81e886ff7..21945de76 100644 --- a/libc/stdio/fmemopen.c +++ b/libc/stdio/fmemopen.c @@ -50,7 +50,8 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) { if (buf) { f->nofree = true; } else { - if (!size) size = BUFSIZ; + if (!size) + size = BUFSIZ; // TODO(jart): Why do we need calloc()? if (!_weaken(calloc) || !(buf = _weaken(calloc)(1, size))) { __stdio_free(f); diff --git a/libc/stdio/fmt.c b/libc/stdio/fmt.c index b90f936c8..b8c31bc63 100644 --- a/libc/stdio/fmt.c +++ b/libc/stdio/fmt.c @@ -140,7 +140,8 @@ static int __fmt_atoi(const char **str) { static int __fmt_pad(int out(const char *, void *, size_t), void *arg, unsigned long n) { int i, rc; - for (rc = i = 0; i < n; ++i) rc |= out(" ", arg, 1); + for (rc = i = 0; i < n; ++i) + rc |= out(" ", arg, 1); return rc; } @@ -212,24 +213,30 @@ static int __fmt_ntoa_format(int out(const char *, void *, size_t), void *arg, /* pad spaces up to given width */ if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { if (len < width) { - if (__fmt_pad(out, arg, width - len) == -1) return -1; + if (__fmt_pad(out, arg, width - len) == -1) + return -1; } } - if (sign_character != '\0' && out(&sign_character, arg, 1) == -1) return -1; + if (sign_character != '\0' && out(&sign_character, arg, 1) == -1) + return -1; if (flags & FLAGS_HASH) { - if (out("0", arg, 1) == -1) return -1; + if (out("0", arg, 1) == -1) + return -1; if (alternate_form_middle_char != '\0' && out(&alternate_form_middle_char, arg, 1) == -1) return -1; } for (i = 0; i < prec_width_zeros; ++i) - if (out("0", arg, 1) == -1) return -1; + if (out("0", arg, 1) == -1) + return -1; reverse(buf, actual_buf_len); - if (out(buf, arg, actual_buf_len) == -1) return -1; + if (out(buf, arg, actual_buf_len) == -1) + return -1; /* append pad spaces up to given width */ if (flags & FLAGS_LEFT) { if (len < width) { - if (__fmt_pad(out, arg, width - len) == -1) return -1; + if (__fmt_pad(out, arg, width - len) == -1) + return -1; } } return 0; @@ -245,7 +252,8 @@ static int __fmt_ntoa2(int out(const char *, void *, size_t), void *arg, len = 0; // we check for log2base!=3, since otherwise we'll print nothing for // a value of 0 with precision 0 when # mandates that one be printed - if (!value && log2base != 3) flags &= ~FLAGS_HASH; + if (!value && log2base != 3) + flags &= ~FLAGS_HASH; if (value || !(flags & FLAGS_PRECISION)) { count = 0; do { @@ -357,7 +365,8 @@ static int __fmt_stoa_byte(out_f out, void *a, uint64_t c) { static int __fmt_stoa_wide(out_f out, void *a, uint64_t w) { char buf[8]; - if (!isascii(w)) w = tpenc(w); + if (!isascii(w)) + w = tpenc(w); WRITE64LE(buf, w); return out(buf, a, w ? (bsr(w) >> 3) + 1 : 1); } @@ -431,7 +440,8 @@ static int __fmt_stoa(int out(const char *, void *, size_t), void *arg, emit = __fmt_stoa_byte; } - if (!(flags & FLAGS_PRECISION)) precision = -1; + if (!(flags & FLAGS_PRECISION)) + precision = -1; if (!(flags & FLAGS_PRECISION) || !ignorenul) { if (signbit == 63) { precision = wcsnlen((const wchar_t *)p, precision); @@ -461,30 +471,37 @@ static int __fmt_stoa(int out(const char *, void *, size_t), void *arg, } if (pad && !(flags & FLAGS_LEFT)) { - if (__fmt_pad(out, arg, pad) == -1) return -1; + if (__fmt_pad(out, arg, pad) == -1) + return -1; } if (!(flags & FLAGS_NOQUOTE) && (flags & FLAGS_REPR)) { if (signbit == 63) { - if (out("L", arg, 1) == -1) return -1; + if (out("L", arg, 1) == -1) + return -1; } else if (signbit == 15) { - if (out("u", arg, 1) == -1) return -1; + if (out("u", arg, 1) == -1) + return -1; } buf[0] = qchar; - if (out(buf, arg, 1) == -1) return -1; + if (out(buf, arg, 1) == -1) + return -1; } if (justdobytes) { while (precision--) { wc = *p++ & 0xff; - if (!wc && !ignorenul) break; - if (emit(out, arg, wc) == -1) return -1; + if (!wc && !ignorenul) + break; + if (emit(out, arg, wc) == -1) + return -1; } } else { while (precision--) { if (signbit == 15) { wc = *(const char16_t *)p; - if (!wc && !ignorenul) break; + if (!wc && !ignorenul) + break; if (IsUcs2(wc)) { p += sizeof(char16_t); } else if (IsUtf16Cont(wc)) { @@ -498,34 +515,42 @@ static int __fmt_stoa(int out(const char *, void *, size_t), void *arg, } } else if (signbit == 63) { wc = *(const wint_t *)p; - if (!wc && !ignorenul) break; + if (!wc && !ignorenul) + break; p += sizeof(wint_t); - if (!wc) break; + if (!wc) + break; } else { wc = *p++ & 0xff; - if (!wc && !ignorenul) break; + if (!wc && !ignorenul) + break; if (!isascii(wc)) { - if (ThomPikeCont(wc)) continue; + if (ThomPikeCont(wc)) + continue; n = ThomPikeLen(wc) - 1; wc = ThomPikeByte(wc); - if (n > precision) break; + if (n > precision) + break; precision -= n; while (n--) { wc = ThomPikeMerge(wc, *p++); } } } - if (emit(out, arg, wc) == -1) return -1; + if (emit(out, arg, wc) == -1) + return -1; } } if (!(flags & FLAGS_NOQUOTE) && (flags & FLAGS_REPR)) { buf[0] = qchar; - if (out(buf, arg, 1) == -1) return -1; + if (out(buf, arg, 1) == -1) + return -1; } if (pad && (flags & FLAGS_LEFT)) { - if (__fmt_pad(out, arg, pad) == -1) return -1; + if (__fmt_pad(out, arg, pad) == -1) + return -1; } return 0; @@ -606,7 +631,8 @@ static int __fmt_fpiprec(struct FPBits *b) { const FPI *fpi; int i, j, k, m; uint32_t *bits; - if (b->kind == STRTOG_Zero) return (b->ex = 0); + if (b->kind == STRTOG_Zero) + return (b->ex = 0); fpi = b->fpi; bits = b->bits; for (k = (fpi->nbits - 1) >> 2; k > 0; --k) { @@ -623,14 +649,16 @@ static int __fmt_fpiprec(struct FPBits *b) { } break; } - for (i = 0; i < 28 && !((bits[0] >> i) & 0xf); i += 4) donothing; + for (i = 0; i < 28 && !((bits[0] >> i) & 0xf); i += 4) + donothing; if (i) { b->ex += i; m = k >> 3; k -= (i >> 2); for (j = 0;; ++j) { bits[j] >>= i; - if (j == m) break; + if (j == m) + break; bits[j] |= bits[j + 1] << (32 - i); } } @@ -650,8 +678,10 @@ static int __fmt_bround(struct FPBits *b, int prec, int prec1) { inc = 0; k = m - 1; if ((t = bits[k >> 3] >> (j = (k & 7) * 4)) & 8) { - if (t & 7) goto inc1; - if (j && bits[k >> 3] << (32 - j)) goto inc1; + if (t & 7) + goto inc1; + if (j && bits[k >> 3] << (32 - j)) + goto inc1; while (k >= 8) { k -= 8; if (bits[k >> 3]) { @@ -669,26 +699,31 @@ haveinc: if ((n = 4 * (m & 7))) for (;; ++j) { bits[j - i] = bits[j] >> n; - if (j == k) break; + if (j == k) + break; bits[j - i] |= bits[j + 1] << (32 - n); } else for (;; ++j) { bits[j - i] = bits[j]; - if (j == k) break; + if (j == k) + break; } k = prec >> 3; if (inc) { - for (j = 0; !(++bits[j] & 0xffffffff); ++j) donothing; + for (j = 0; !(++bits[j] & 0xffffffff); ++j) + donothing; if (j > k) { onebit: bits[0] = 1; b->ex += 4 * prec; return 1; } - if ((j = prec & 7) < 7 && bits[k] >> (j + 1) * 4) goto onebit; + if ((j = prec & 7) < 7 && bits[k] >> (j + 1) * 4) + goto onebit; } - for (i = 0; !(bits[i >> 3] & (0xf << 4 * (i & 7))); ++i) donothing; + for (i = 0; !(bits[i >> 3] & (0xf << 4 * (i & 7))); ++i) + donothing; if (i) { b->ex += 4 * i; prec -= i; @@ -697,7 +732,8 @@ haveinc: i *= 4; for (m = j;; ++m) { bits[m - j] = bits[m] >> i; - if (m == k) break; + if (m == k) + break; bits[m - j] |= bits[m + 1] << (32 - i); } } @@ -805,9 +841,11 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { while (*format) { if (*format != '%') { for (n = 1; format[n]; ++n) { - if (format[n] == '%') break; + if (format[n] == '%') + break; } - if (out(format, arg, n) == -1) return -1; + if (out(format, arg, n) == -1) + return -1; format += n; continue; } @@ -815,38 +853,46 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { if (!IsTiny()) { if (format[1] == 's') { // FAST PATH: PLAIN STRING s = va_arg(va, char *); - if (!s) s = "(null)"; - if (out(s, arg, strlen(s)) == -1) return -1; + if (!s) + s = "(null)"; + if (out(s, arg, strlen(s)) == -1) + return -1; format += 2; continue; } else if (format[1] == 'd') { // FAST PATH: PLAIN INTEGER d = va_arg(va, int); - if (out(ibuf, arg, FormatInt32(ibuf, d) - ibuf) == -1) return -1; + if (out(ibuf, arg, FormatInt32(ibuf, d) - ibuf) == -1) + return -1; format += 2; continue; } else if (format[1] == 'u') { // FAST PATH: PLAIN UNSIGNED u = va_arg(va, unsigned); - if (out(ibuf, arg, FormatUint32(ibuf, u) - ibuf) == -1) return -1; + if (out(ibuf, arg, FormatUint32(ibuf, u) - ibuf) == -1) + return -1; format += 2; continue; } else if (format[1] == 'x') { // FAST PATH: PLAIN HEX u = va_arg(va, unsigned); - if (out(ibuf, arg, uint64toarray_radix16(u, ibuf)) == -1) return -1; + if (out(ibuf, arg, uint64toarray_radix16(u, ibuf)) == -1) + return -1; format += 2; continue; } else if (format[1] == 'l' && format[2] == 'x') { lu = va_arg(va, unsigned long); // FAST PATH: PLAIN LONG HEX - if (out(ibuf, arg, uint64toarray_radix16(lu, ibuf)) == -1) return -1; + if (out(ibuf, arg, uint64toarray_radix16(lu, ibuf)) == -1) + return -1; format += 3; continue; } else if (format[1] == 'l' && format[2] == 'd') { ld = va_arg(va, long); // FAST PATH: PLAIN LONG - if (out(ibuf, arg, FormatInt64(ibuf, ld) - ibuf) == -1) return -1; + if (out(ibuf, arg, FormatInt64(ibuf, ld) - ibuf) == -1) + return -1; format += 3; continue; } else if (format[1] == 'l' && format[2] == 'u') { lu = va_arg(va, unsigned long); // FAST PATH: PLAIN UNSIGNED LONG - if (out(ibuf, arg, FormatUint64(ibuf, lu) - ibuf) == -1) return -1; + if (out(ibuf, arg, FormatUint64(ibuf, lu) - ibuf) == -1) + return -1; format += 3; continue; } else if (format[1] == '.' && format[2] == '*' && format[3] == 's') { @@ -858,7 +904,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { s = "(null)"; n = MIN(6, n); } - if (out(s, arg, n) == -1) return -1; + if (out(s, arg, n) == -1) + return -1; format += 4; continue; } @@ -951,7 +998,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { format++; break; } - if (format[1] == 'l') format++; + if (format[1] == 'l') + format++; // fallthrough case 't': // ptrdiff_t case 'z': // size_t @@ -1074,7 +1122,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { case 'F': case 'f': - if (!(flags & FLAGS_PRECISION)) prec = 6; + if (!(flags & FLAGS_PRECISION)) + prec = 6; if (!longdouble) { x = va_arg(va, double); s = s0 = dtoa(x, 3, prec, &decpt, &fpb.sign, &se); @@ -1093,7 +1142,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { } if (decpt == 9999) { Format9999: - if (s0) freedtoa(s0); + if (s0) + freedtoa(s0); bzero(special, sizeof(special)); s = q = special; if (fpb.sign) { @@ -1107,37 +1157,49 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { flags &= ~(FLAGS_PRECISION | FLAGS_PLUS | FLAGS_HASH | FLAGS_SPACE); prec = 0; rc = __fmt_stoa(out, arg, s, flags, prec, width, signbit, qchar); - if (rc == -1) return -1; + if (rc == -1) + return -1; break; } FormatReal: - if (fpb.sign /* && (x || sign) */) sign = '-'; - if (prec > 0) width -= prec; + if (fpb.sign /* && (x || sign) */) + sign = '-'; + if (prec > 0) + width -= prec; if (width > 0) { - if (sign) --width; + if (sign) + --width; if (decpt <= 0) { --width; - if (prec > 0) --width; + if (prec > 0) + --width; } else { - if (s == se) decpt = 1; + if (s == se) + decpt = 1; width -= decpt; - if (prec > 0 || (flags & FLAGS_HASH)) --width; + if (prec > 0 || (flags & FLAGS_HASH)) + --width; } } if (width > 0 && !(flags & FLAGS_LEFT)) { if ((flags & FLAGS_ZEROPAD)) { - if (sign) __FMT_PUT(sign); + if (sign) + __FMT_PUT(sign); sign = 0; - do __FMT_PUT('0'); + do + __FMT_PUT('0'); while (--width > 0); } else - do __FMT_PUT(' '); + do + __FMT_PUT(' '); while (--width > 0); } - if (sign) __FMT_PUT(sign); + if (sign) + __FMT_PUT(sign); if (decpt <= 0) { __FMT_PUT('0'); - if (prec > 0 || (flags & FLAGS_HASH)) __FMT_PUT('.'); + if (prec > 0 || (flags & FLAGS_HASH)) + __FMT_PUT('.'); while (decpt < 0) { __FMT_PUT('0'); prec--; @@ -1152,7 +1214,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { } __FMT_PUT(c); } while (--decpt > 0); - if (prec > 0 || (flags & FLAGS_HASH)) __FMT_PUT('.'); + if (prec > 0 || (flags & FLAGS_HASH)) + __FMT_PUT('.'); } while (--prec >= 0) { if ((c = *s)) { @@ -1162,14 +1225,18 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { } __FMT_PUT(c); } - while (--width >= 0) __FMT_PUT(' '); - if (s0) freedtoa(s0); + while (--width >= 0) + __FMT_PUT(' '); + if (s0) + freedtoa(s0); break; case 'G': case 'g': - if (!(flags & FLAGS_PRECISION)) prec = 6; - if (prec < 1) prec = 1; + if (!(flags & FLAGS_PRECISION)) + prec = 6; + if (prec < 1) + prec = 1; if (!longdouble) { x = va_arg(va, double); s = s0 = dtoa(x, 2, prec, &decpt, &fpb.sign, &se); @@ -1186,7 +1253,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec, &decpt, &se); } - if (decpt == 9999) goto Format9999; + if (decpt == 9999) + goto Format9999; c = se - s; prec1 = prec; if (!prec) { @@ -1199,18 +1267,22 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { prec -= decpt; else prec = c - decpt; - if (prec < 0) prec = 0; + if (prec < 0) + prec = 0; goto FormatReal; } d -= 2; - if (!(flags & FLAGS_HASH) && prec > c) prec = c; + if (!(flags & FLAGS_HASH) && prec > c) + prec = c; --prec; goto FormatExpo; case 'e': case 'E': - if (!(flags & FLAGS_PRECISION)) prec = 6; - if (prec < 0) prec = 0; + if (!(flags & FLAGS_PRECISION)) + prec = 6; + if (prec < 0) + prec = 0; if (!longdouble) { x = va_arg(va, double); s = s0 = dtoa(x, 2, prec + 1, &decpt, &fpb.sign, &se); @@ -1227,31 +1299,41 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { s = s0 = gdtoa(fpb.fpi, fpb.ex, fpb.bits, &fpb.kind, prec ? 2 : 0, prec, &decpt, &se); } - if (decpt == 9999) goto Format9999; + if (decpt == 9999) + goto Format9999; FormatExpo: - if (fpb.sign /* && (x || sign) */) sign = '-'; + if (fpb.sign /* && (x || sign) */) + sign = '-'; if ((width -= prec + 5) > 0) { - if (sign) --width; - if (prec || (flags & FLAGS_HASH)) --width; + if (sign) + --width; + if (prec || (flags & FLAGS_HASH)) + --width; } - if ((c = --decpt) < 0) c = -c; + if ((c = --decpt) < 0) + c = -c; while (c >= 100) { --width; c /= 10; } if (width > 0 && !(flags & FLAGS_LEFT)) { if ((flags & FLAGS_ZEROPAD)) { - if (sign) __FMT_PUT(sign); + if (sign) + __FMT_PUT(sign); sign = 0; - do __FMT_PUT('0'); + do + __FMT_PUT('0'); while (--width > 0); } else - do __FMT_PUT(' '); + do + __FMT_PUT(' '); while (--width > 0); } - if (sign) __FMT_PUT(sign); + if (sign) + __FMT_PUT(sign); __FMT_PUT(*s++); - if (prec || (flags & FLAGS_HASH)) __FMT_PUT('.'); + if (prec || (flags & FLAGS_HASH)) + __FMT_PUT('.'); while (--prec >= 0) { if ((c = *s)) { s++; @@ -1273,7 +1355,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { for (;;) { i1 = decpt / k; __FMT_PUT(i1 + '0'); - if (--c <= 0) break; + if (--c <= 0) + break; decpt -= i1 * k; decpt *= 10; } @@ -1307,7 +1390,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { bw = 1; bex = fpb.ex + 4 * prec1; if (bex) { - if ((i1 = bex) < 0) i1 = -i1; + if ((i1 = bex) < 0) + i1 = -i1; while (i1 >= 10) { ++bw; i1 /= 10; @@ -1317,19 +1401,24 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { sign = '-'; } if ((width -= bw + 5) > 0) { - if (sign) --width; - if (prec1 || (flags & FLAGS_HASH)) --width; + if (sign) + --width; + if (prec1 || (flags & FLAGS_HASH)) + --width; } if ((width -= MAX(prec, prec1)) > 0 && !(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { - do __FMT_PUT(' '); + do + __FMT_PUT(' '); while (--width > 0); } - if (sign) __FMT_PUT(sign); + if (sign) + __FMT_PUT(sign); __FMT_PUT('0'); __FMT_PUT(alphabet[17]); // x or X if ((flags & FLAGS_ZEROPAD) && width > 0 && !(flags & FLAGS_LEFT)) { - do __FMT_PUT('0'); + do + __FMT_PUT('0'); while (--width > 0); } i1 = prec1 & 7; @@ -1340,7 +1429,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { } while (prec1 > 0) { if (--i1 < 0) { - if (--k < 0) break; + if (--k < 0) + break; i1 = 7; } __FMT_PUT(alphabet[(fpb.bits[k] >> 4 * i1) & 0xf]); @@ -1363,7 +1453,8 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { for (;;) { i1 = bex / c; __FMT_PUT('0' + i1); - if (!--bw) break; + if (!--bw) + break; bex -= i1 * c; bex *= 10; } diff --git a/libc/stdio/fputc_unlocked.c b/libc/stdio/fputc_unlocked.c index d4c38f340..5a3923032 100644 --- a/libc/stdio/fputc_unlocked.c +++ b/libc/stdio/fputc_unlocked.c @@ -33,7 +33,8 @@ int fputc_unlocked(int c, FILE *f) { return c & 255; } else { b = c; - if (!fwrite_unlocked(&b, 1, 1, f)) return -1; + if (!fwrite_unlocked(&b, 1, 1, f)) + return -1; return b; } } diff --git a/libc/stdio/fputs_unlocked.c b/libc/stdio/fputs_unlocked.c index 39285789d..61dc0c31a 100644 --- a/libc/stdio/fputs_unlocked.c +++ b/libc/stdio/fputs_unlocked.c @@ -34,6 +34,7 @@ int fputs_unlocked(const char *s, FILE *f) { size_t n, r; n = strlen(s); r = fwrite_unlocked(s, 1, n, f); - if (!r && n) return -1; + if (!r && n) + return -1; return r; } diff --git a/libc/stdio/fread_unlocked.c b/libc/stdio/fread_unlocked.c index b71a19c1f..eac24b6e3 100644 --- a/libc/stdio/fread_unlocked.c +++ b/libc/stdio/fread_unlocked.c @@ -97,7 +97,8 @@ size_t fread_unlocked(void *buf, size_t stride, size_t count, FILE *f) { return count; } else { n = (m + n) / stride; - if (n < count) f->state = -1; + if (n < count) + f->state = -1; return n; } } diff --git a/libc/stdio/fseek_unlocked.c b/libc/stdio/fseek_unlocked.c index 4ec7bbcda..6703a59ec 100644 --- a/libc/stdio/fseek_unlocked.c +++ b/libc/stdio/fseek_unlocked.c @@ -40,7 +40,8 @@ int fseek_unlocked(FILE *f, int64_t offset, int whence) { int res; int64_t pos; if (f->fd != -1) { - if (__fflush_impl(f) == -1) return -1; + if (__fflush_impl(f) == -1) + return -1; if (whence == SEEK_CUR && f->beg < f->end) { offset -= f->end - f->beg; } diff --git a/libc/stdio/ftell.c b/libc/stdio/ftell.c index 003819b97..7330e35d6 100644 --- a/libc/stdio/ftell.c +++ b/libc/stdio/ftell.c @@ -26,9 +26,11 @@ static inline int64_t ftell_unlocked(FILE *f) { int64_t pos; if (f->fd != -1) { - if (__fflush_impl(f) == -1) return -1; + if (__fflush_impl(f) == -1) + return -1; if ((pos = lseek(f->fd, 0, SEEK_CUR)) != -1) { - if (f->beg < f->end) pos -= f->end - f->beg; + if (f->beg < f->end) + pos -= f->end - f->beg; return pos; } else { f->state = errno == ESPIPE ? EBADF : errno; diff --git a/libc/stdio/getcwd.c b/libc/stdio/getcwd.c index cd7ab2b7a..5a5c01809 100644 --- a/libc/stdio/getcwd.c +++ b/libc/stdio/getcwd.c @@ -49,7 +49,8 @@ char *getcwd(char *buf, size_t size) { return 0; } } else { - if (!size) size = 4096; + if (!size) + size = 4096; if (!(path = malloc(size))) { return 0; // enomem } diff --git a/libc/stdio/getdelim_unlocked.c b/libc/stdio/getdelim_unlocked.c index 11970dd0a..036017097 100644 --- a/libc/stdio/getdelim_unlocked.c +++ b/libc/stdio/getdelim_unlocked.c @@ -40,7 +40,8 @@ ssize_t getdelim_unlocked(char **s, size_t *n, int delim, FILE *f) { f->state = errno = EINVAL; return -1; } - if (!*s) *n = 0; + if (!*s) + *n = 0; for (i = 0;; i += m) { m = f->end - f->beg; if ((p = memchr(f->buf + f->beg, delim, m))) { @@ -67,7 +68,8 @@ ssize_t getdelim_unlocked(char **s, size_t *n, int delim, FILE *f) { } else if (f->fd == -1) { break; } else if ((rc = read(f->fd, f->buf, f->size)) != -1) { - if (!rc) break; + if (!rc) + break; f->end = rc; } else if (errno != EINTR) { f->state = errno; diff --git a/libc/stdio/getentropy.c b/libc/stdio/getentropy.c index a028053d4..ec2e68570 100644 --- a/libc/stdio/getentropy.c +++ b/libc/stdio/getentropy.c @@ -42,12 +42,14 @@ int getentropy(void *p, size_t n) { } else if ((!p && n) || (IsAsan() && !__asan_is_valid(p, n))) { rc = efault(); } else if (IsXnu() || IsOpenbsd()) { - if (sys_getentropy(p, n)) notpossible; + if (sys_getentropy(p, n)) + notpossible; rc = 0; } else { BLOCK_SIGNALS; BLOCK_CANCELATION; - if (__getrandom(p, n, 0) != n) notpossible; + if (__getrandom(p, n, 0) != n) + notpossible; ALLOW_CANCELATION; ALLOW_SIGNALS; rc = 0; diff --git a/libc/stdio/kvappendf.c b/libc/stdio/kvappendf.c index 9dfa79edd..5c171a1c4 100644 --- a/libc/stdio/kvappendf.c +++ b/libc/stdio/kvappendf.c @@ -46,8 +46,10 @@ ssize_t kvappendf(char **b, const char *f, va_list v) { if ((r = kvsnprintf(p + z.i, z.n ? z.n - W - z.i : 0, f, v)) >= 0) { n = ROUNDUP(z.i + r + 1, 8) + W; if (n > z.n) { - if (!z.n) z.n = W * 2; - while (n > z.n) z.n += z.n >> 1; + if (!z.n) + z.n = W * 2; + while (n > z.n) + z.n += z.n >> 1; z.n = ROUNDUP(z.n, W); if ((p = realloc(p, z.n))) { z.n = malloc_usable_size(p); @@ -61,7 +63,8 @@ ssize_t kvappendf(char **b, const char *f, va_list v) { } } z.i += r; - if (!IsTiny() && W == 8) z.i |= (size_t)APPEND_COOKIE << 48; + if (!IsTiny() && W == 8) + z.i |= (size_t)APPEND_COOKIE << 48; *(size_t *)(p + z.n - W) = z.i; } va_end(w); diff --git a/libc/stdio/mt19937.c b/libc/stdio/mt19937.c index 8a4b8b8d2..72fd5fce7 100644 --- a/libc/stdio/mt19937.c +++ b/libc/stdio/mt19937.c @@ -100,13 +100,16 @@ void _Smt19937(uint64_t K[], size_t n) { for (i = 1, j = 0, k = MAX(NN, n); k; k--) { mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 62)) * 0x369dea0f31a53f85)) + K[j] + j; - if (++i >= NN) mt[0] = mt[NN - 1], i = 1; - if (++j >= n) j = 0; + if (++i >= NN) + mt[0] = mt[NN - 1], i = 1; + if (++j >= n) + j = 0; } for (k = NN - 1; k; k--) { mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 62)) * 0x27bb2ee687b0b0fd)) - i; - if (++i >= NN) mt[0] = mt[NN - 1], i = 1; + if (++i >= NN) + mt[0] = mt[NN - 1], i = 1; } mt[0] = 0x8000000000000000; /* assures non-zero initial array */ } @@ -122,7 +125,8 @@ uint64_t _mt19937(void) { int i; uint64_t x; if (mti >= NN) { - if (mti == NN + 1) _smt19937(5489); + if (mti == NN + 1) + _smt19937(5489); for (i = 0; i < NN - MM; i++) { x = (mt[i] & UM) | (mt[i + 1] & LM); mt[i] = mt[i + MM] ^ (x >> 1) ^ mag01[x & 1]; diff --git a/libc/stdio/pclose.c b/libc/stdio/pclose.c index e83d7729a..2ed6ef434 100644 --- a/libc/stdio/pclose.c +++ b/libc/stdio/pclose.c @@ -42,7 +42,8 @@ int pclose(FILE *f) { bool iscancelled, wasinterrupted; pid = f->pid; fclose(f); - if (!pid) return 0; + if (!pid) + return 0; iscancelled = false; wasinterrupted = false; for (e = errno;;) { diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c index 766ddcb00..d53d5a426 100644 --- a/libc/stdio/popen.c +++ b/libc/stdio/popen.c @@ -70,14 +70,17 @@ FILE *popen(const char *cmdline, const char *mode) { errno = rc; return 0; } - if (pipe2(pipefds, O_CLOEXEC) == -1) return NULL; + if (pipe2(pipefds, O_CLOEXEC) == -1) + return NULL; if ((f = fdopen(pipefds[dir], mode))) { switch ((pid = fork())) { case 0: unassert(dup2(pipefds[!dir], !dir) == !dir); // we can't rely on cloexec because cocmd builtins don't execve - if (pipefds[0] != !dir) unassert(!close(pipefds[0])); - if (pipefds[1] != !dir) unassert(!close(pipefds[1])); + if (pipefds[0] != !dir) + unassert(!close(pipefds[0])); + if (pipefds[1] != !dir) + unassert(!close(pipefds[1])); // "The popen() function shall ensure that any streams from // previous popen() calls that remain open in the parent // process are closed in the new child process." -POSIX diff --git a/libc/stdio/printargs.c b/libc/stdio/printargs.c index eb7dbac63..34b2c362f 100644 --- a/libc/stdio/printargs.c +++ b/libc/stdio/printargs.c @@ -187,7 +187,8 @@ textstartup void __printargs(const char *prologue) { (void)x; - if (!PLEDGED(STDIO)) return; + if (!PLEDGED(STDIO)) + return; ftrace_enabled(-1); strace_enabled(-1); @@ -263,25 +264,44 @@ textstartup void __printargs(const char *prologue) { }); kprintf(prologue); kprintf(" "); - if (X86_HAVE(SSE3)) kprintf(" SSE3"); - if (X86_HAVE(SSSE3)) kprintf(" SSSE3"); - if (X86_HAVE(SSE4_2)) kprintf(" SSE4_2"); - if (X86_HAVE(POPCNT)) kprintf(" POPCNT"); - if (X86_HAVE(AVX)) kprintf(" AVX"); - if (X86_HAVE(AVX2)) kprintf(" AVX2"); - if (X86_HAVE(FMA)) kprintf(" FMA"); - if (X86_HAVE(BMI)) kprintf(" BMI"); - if (X86_HAVE(BMI2)) kprintf(" BMI2"); - if (X86_HAVE(ADX)) kprintf(" ADX"); - if (X86_HAVE(F16C)) kprintf(" F16C"); - if (X86_HAVE(SHA)) kprintf(" SHA"); - if (X86_HAVE(AES)) kprintf(" AES"); - if (X86_HAVE(RDRND)) kprintf(" RDRND"); - if (X86_HAVE(RDSEED)) kprintf(" RDSEED"); - if (X86_HAVE(RDTSCP)) kprintf(" RDTSCP"); - if (X86_HAVE(RDPID)) kprintf(" RDPID"); - if (X86_HAVE(LA57)) kprintf(" LA57"); - if (X86_HAVE(FSGSBASE)) kprintf(" FSGSBASE"); + if (X86_HAVE(SSE3)) + kprintf(" SSE3"); + if (X86_HAVE(SSSE3)) + kprintf(" SSSE3"); + if (X86_HAVE(SSE4_2)) + kprintf(" SSE4_2"); + if (X86_HAVE(POPCNT)) + kprintf(" POPCNT"); + if (X86_HAVE(AVX)) + kprintf(" AVX"); + if (X86_HAVE(AVX2)) + kprintf(" AVX2"); + if (X86_HAVE(FMA)) + kprintf(" FMA"); + if (X86_HAVE(BMI)) + kprintf(" BMI"); + if (X86_HAVE(BMI2)) + kprintf(" BMI2"); + if (X86_HAVE(ADX)) + kprintf(" ADX"); + if (X86_HAVE(F16C)) + kprintf(" F16C"); + if (X86_HAVE(SHA)) + kprintf(" SHA"); + if (X86_HAVE(AES)) + kprintf(" AES"); + if (X86_HAVE(RDRND)) + kprintf(" RDRND"); + if (X86_HAVE(RDSEED)) + kprintf(" RDSEED"); + if (X86_HAVE(RDTSCP)) + kprintf(" RDTSCP"); + if (X86_HAVE(RDPID)) + kprintf(" RDPID"); + if (X86_HAVE(LA57)) + kprintf(" LA57"); + if (X86_HAVE(FSGSBASE)) + kprintf(" FSGSBASE"); #elif defined(__aarch64__) kprintf(" AARCH64\n"); #else @@ -297,7 +317,8 @@ textstartup void __printargs(const char *prologue) { if ((n = poll(u.pfds, ARRAYLEN(u.pfds), 0)) != -1) { for (i = 0; i < ARRAYLEN(u.pfds); ++i) { char oflagbuf[128]; - if (i && (u.pfds[i].revents & POLLNVAL)) continue; + if (i && (u.pfds[i].revents & POLLNVAL)) + continue; PRINT(" ☼ %d (revents=%#hx fcntl(F_GETFL)=%s isatty()=%hhhd)", i, u.pfds[i].revents, (DescribeOpenFlags)(oflagbuf, fcntl(i, F_GETFL)), isatty(i)); @@ -364,8 +385,10 @@ textstartup void __printargs(const char *prologue) { for (gotsome = false, i = 0; i < RLIM_NLIMITS; ++i) { if (!getrlimit(i, &rlim)) { char buf[20]; - if (rlim.rlim_cur == RLIM_INFINITY) rlim.rlim_cur = -1; - if (rlim.rlim_max == RLIM_INFINITY) rlim.rlim_max = -1; + if (rlim.rlim_cur == RLIM_INFINITY) + rlim.rlim_cur = -1; + if (rlim.rlim_max == RLIM_INFINITY) + rlim.rlim_max = -1; PRINT(" ☼ %-20s %,16ld %,16ld", (DescribeRlimitName)(buf, i), rlim.rlim_cur, rlim.rlim_max); gotsome = true; @@ -488,32 +511,55 @@ textstartup void __printargs(const char *prologue) { } kprintf(prologue); kprintf(" c_iflag ="); - if (termios.c_iflag & IGNBRK) kprintf(" IGNBRK"); - if (termios.c_iflag & BRKINT) kprintf(" BRKINT"); - if (termios.c_iflag & IGNPAR) kprintf(" IGNPAR"); - if (termios.c_iflag & PARMRK) kprintf(" PARMRK"); - if (termios.c_iflag & INPCK) kprintf(" INPCK"); - if (termios.c_iflag & ISTRIP) kprintf(" ISTRIP"); - if (termios.c_iflag & INLCR) kprintf(" INLCR"); - if (termios.c_iflag & IGNCR) kprintf(" IGNCR"); - if (termios.c_iflag & ICRNL) kprintf(" ICRNL"); - if (termios.c_iflag & IXON) kprintf(" IXON"); - if (termios.c_iflag & IXANY) kprintf(" IXANY"); - if (termios.c_iflag & IXOFF) kprintf(" IXOFF"); - if (termios.c_iflag & IMAXBEL) kprintf(" IMAXBEL"); - if (termios.c_iflag & IUTF8) kprintf(" IUTF8"); - if (termios.c_iflag & IUCLC) kprintf(" IUCLC"); + if (termios.c_iflag & IGNBRK) + kprintf(" IGNBRK"); + if (termios.c_iflag & BRKINT) + kprintf(" BRKINT"); + if (termios.c_iflag & IGNPAR) + kprintf(" IGNPAR"); + if (termios.c_iflag & PARMRK) + kprintf(" PARMRK"); + if (termios.c_iflag & INPCK) + kprintf(" INPCK"); + if (termios.c_iflag & ISTRIP) + kprintf(" ISTRIP"); + if (termios.c_iflag & INLCR) + kprintf(" INLCR"); + if (termios.c_iflag & IGNCR) + kprintf(" IGNCR"); + if (termios.c_iflag & ICRNL) + kprintf(" ICRNL"); + if (termios.c_iflag & IXON) + kprintf(" IXON"); + if (termios.c_iflag & IXANY) + kprintf(" IXANY"); + if (termios.c_iflag & IXOFF) + kprintf(" IXOFF"); + if (termios.c_iflag & IMAXBEL) + kprintf(" IMAXBEL"); + if (termios.c_iflag & IUTF8) + kprintf(" IUTF8"); + if (termios.c_iflag & IUCLC) + kprintf(" IUCLC"); kprintf("\n"); kprintf(prologue); kprintf(" c_oflag ="); - if (termios.c_oflag & OPOST) kprintf(" OPOST"); - if (termios.c_oflag & ONLCR) kprintf(" ONLCR"); - if (termios.c_oflag & OCRNL) kprintf(" OCRNL"); - if (termios.c_oflag & ONOCR) kprintf(" ONOCR"); - if (termios.c_oflag & ONLRET) kprintf(" ONLRET"); - if (termios.c_oflag & OFILL) kprintf(" OFILL"); - if (termios.c_oflag & OFDEL) kprintf(" OFDEL"); - if (termios.c_oflag & OLCUC) kprintf(" OLCUC"); + if (termios.c_oflag & OPOST) + kprintf(" OPOST"); + if (termios.c_oflag & ONLCR) + kprintf(" ONLCR"); + if (termios.c_oflag & OCRNL) + kprintf(" OCRNL"); + if (termios.c_oflag & ONOCR) + kprintf(" ONOCR"); + if (termios.c_oflag & ONLRET) + kprintf(" ONLRET"); + if (termios.c_oflag & OFILL) + kprintf(" OFILL"); + if (termios.c_oflag & OFDEL) + kprintf(" OFDEL"); + if (termios.c_oflag & OLCUC) + kprintf(" OLCUC"); if ((termios.c_oflag & NLDLY) == NL1) { kprintf(" NL1"); } else if ((termios.c_oflag & NLDLY) == NL2) { @@ -547,13 +593,20 @@ textstartup void __printargs(const char *prologue) { kprintf("\n"); kprintf(prologue); kprintf(" c_cflag ="); - if (termios.c_cflag & PARENB) kprintf(" PARENB"); - if (termios.c_cflag & PARODD) kprintf(" PARODD"); - if (termios.c_cflag & CSTOPB) kprintf(" CSTOPB"); - if (termios.c_cflag & PARODD) kprintf(" PARODD"); - if (termios.c_cflag & HUPCL) kprintf(" HUPCL"); - if (termios.c_cflag & CREAD) kprintf(" CREAD"); - if (termios.c_cflag & CLOCAL) kprintf(" CLOCAL"); + if (termios.c_cflag & PARENB) + kprintf(" PARENB"); + if (termios.c_cflag & PARODD) + kprintf(" PARODD"); + if (termios.c_cflag & CSTOPB) + kprintf(" CSTOPB"); + if (termios.c_cflag & PARODD) + kprintf(" PARODD"); + if (termios.c_cflag & HUPCL) + kprintf(" HUPCL"); + if (termios.c_cflag & CREAD) + kprintf(" CREAD"); + if (termios.c_cflag & CLOCAL) + kprintf(" CLOCAL"); if ((termios.c_cflag & CSIZE) == CS5) { kprintf(" CS5"); } else if ((termios.c_cflag & CSIZE) == CS6) { @@ -566,21 +619,36 @@ textstartup void __printargs(const char *prologue) { kprintf("\n"); kprintf(prologue); kprintf(" c_lflag ="); - if (termios.c_lflag & ISIG) kprintf(" ISIG"); - if (termios.c_lflag & ICANON) kprintf(" ICANON"); - if (termios.c_lflag & ECHO) kprintf(" ECHO"); - if (termios.c_lflag & ECHOE) kprintf(" ECHOE"); - if (termios.c_lflag & ECHOK) kprintf(" ECHOK"); - if (termios.c_lflag & ECHONL) kprintf(" ECHONL"); - if (termios.c_lflag & NOFLSH) kprintf(" NOFLSH"); - if (termios.c_lflag & TOSTOP) kprintf(" TOSTOP"); - if (termios.c_lflag & IEXTEN) kprintf(" IEXTEN"); - if (termios.c_lflag & ECHOCTL) kprintf(" ECHOCTL"); - if (termios.c_lflag & ECHOPRT) kprintf(" ECHOPRT"); - if (termios.c_lflag & ECHOKE) kprintf(" ECHOKE"); - if (termios.c_lflag & FLUSHO) kprintf(" FLUSHO"); - if (termios.c_lflag & PENDIN) kprintf(" PENDIN"); - if (termios.c_lflag & XCASE) kprintf(" XCASE"); + if (termios.c_lflag & ISIG) + kprintf(" ISIG"); + if (termios.c_lflag & ICANON) + kprintf(" ICANON"); + if (termios.c_lflag & ECHO) + kprintf(" ECHO"); + if (termios.c_lflag & ECHOE) + kprintf(" ECHOE"); + if (termios.c_lflag & ECHOK) + kprintf(" ECHOK"); + if (termios.c_lflag & ECHONL) + kprintf(" ECHONL"); + if (termios.c_lflag & NOFLSH) + kprintf(" NOFLSH"); + if (termios.c_lflag & TOSTOP) + kprintf(" TOSTOP"); + if (termios.c_lflag & IEXTEN) + kprintf(" IEXTEN"); + if (termios.c_lflag & ECHOCTL) + kprintf(" ECHOCTL"); + if (termios.c_lflag & ECHOPRT) + kprintf(" ECHOPRT"); + if (termios.c_lflag & ECHOKE) + kprintf(" ECHOKE"); + if (termios.c_lflag & FLUSHO) + kprintf(" FLUSHO"); + if (termios.c_lflag & PENDIN) + kprintf(" PENDIN"); + if (termios.c_lflag & XCASE) + kprintf(" XCASE"); kprintf("\n"); PRINT(" cfgetispeed() = %u", cfgetispeed(&termios)); PRINT(" cfgetospeed() = %u", cfgetospeed(&termios)); diff --git a/libc/stdio/puts_unlocked.c b/libc/stdio/puts_unlocked.c index 14752ccaa..5e5d2c38a 100644 --- a/libc/stdio/puts_unlocked.c +++ b/libc/stdio/puts_unlocked.c @@ -29,11 +29,14 @@ int puts_unlocked(const char *s) { size_t n, r; if ((n = strlen(s))) { r = fwrite_unlocked(s, 1, n, stdout); - if (!r) return -1; - if (r < n) return r; + if (!r) + return -1; + if (r < n) + return r; } if (fputc_unlocked('\n', stdout) == -1) { - if (feof_unlocked(stdout)) return n; + if (feof_unlocked(stdout)) + return n; return -1; } return n + 1; diff --git a/libc/stdio/random.c b/libc/stdio/random.c index aa78e31c9..7d1ef0bf8 100644 --- a/libc/stdio/random.c +++ b/libc/stdio/random.c @@ -87,7 +87,8 @@ void srandom(unsigned seed) { char *initstate(unsigned seed, char *state, size_t size) { void *old; - if (size < 8) return 0; + if (size < 8) + return 0; old = savestate(); if (size < 32) { n = 0; @@ -115,10 +116,13 @@ char *setstate(char *state) { long random(void) { long k; - if (!n) return (x[0] = lcg31(x[0])); + if (!n) + return (x[0] = lcg31(x[0])); x[i] += x[j]; k = x[i] >> 1; - if (++i == n) i = 0; - if (++j == n) j = 0; + if (++i == n) + i = 0; + if (++j == n) + j = 0; return k; } diff --git a/libc/stdio/rdseed.c b/libc/stdio/rdseed.c index 4cde60469..f5b2375a0 100644 --- a/libc/stdio/rdseed.c +++ b/libc/stdio/rdseed.c @@ -48,7 +48,8 @@ uint64_t rdseed(void) { : CFLAG_CONSTRAINT(cf), "=r"(x) : /* no inputs */ : "cc"); - if (cf) return x; + if (cf) + return x; asm volatile("pause"); } } diff --git a/libc/stdio/rngset.c b/libc/stdio/rngset.c index 881eb9fa1..ff0c6274d 100644 --- a/libc/stdio/rngset.c +++ b/libc/stdio/rngset.c @@ -52,7 +52,8 @@ dontasan void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) { reseed = 8; } while (n) { - if (seed) t = seed(); + if (seed) + t = seed(); if (!seed || reseed > 8) { n -= (m = reseed < n ? reseed : n); while (m >= 8) { diff --git a/libc/stdio/setvbuf.c b/libc/stdio/setvbuf.c index 4dd749baf..6be7ca74b 100644 --- a/libc/stdio/setvbuf.c +++ b/libc/stdio/setvbuf.c @@ -36,7 +36,8 @@ int setvbuf(FILE *f, char *buf, int mode, size_t size) { flockfile(f); if (buf) { - if (!size) size = BUFSIZ; + if (!size) + size = BUFSIZ; if (!f->nofree && // f->buf != buf && // f->buf != f->mem && // diff --git a/libc/stdio/sortstrlist.c b/libc/stdio/sortstrlist.c index 0f6eede77..db80e5fc7 100644 --- a/libc/stdio/sortstrlist.c +++ b/libc/stdio/sortstrlist.c @@ -23,7 +23,8 @@ static int CompareStrings(const void *p1, const void *p2) { const char *a = *(const char **)p1; const char *b = *(const char **)p2; for (; *a == *b; a++, b++) { - if (!*a) break; + if (!*a) + break; } return (*a & 0xff) - (*b & 0xff); } diff --git a/libc/stdio/ungetc_unlocked.c b/libc/stdio/ungetc_unlocked.c index 853ff8d26..ce9f14920 100644 --- a/libc/stdio/ungetc_unlocked.c +++ b/libc/stdio/ungetc_unlocked.c @@ -24,7 +24,8 @@ * Pushes byte back to stream. */ int ungetc_unlocked(int c, FILE *f) { - if (c == -1) return -1; + if (c == -1) + return -1; if (f->beg) { if (c != f->buf[--f->beg]) { f->buf[f->beg] = c; diff --git a/libc/stdio/ungetwc_unlocked.c b/libc/stdio/ungetwc_unlocked.c index b802971f9..88e256366 100644 --- a/libc/stdio/ungetwc_unlocked.c +++ b/libc/stdio/ungetwc_unlocked.c @@ -27,7 +27,8 @@ wint_t ungetwc_unlocked(wint_t c, FILE *f) { char b[6]; unsigned n; uint64_t w; - if (c == -1) return -1; + if (c == -1) + return -1; n = 0; w = tpenc(c); do { diff --git a/libc/stdio/vappendf.c b/libc/stdio/vappendf.c index ca2b3ff86..726e59450 100644 --- a/libc/stdio/vappendf.c +++ b/libc/stdio/vappendf.c @@ -39,8 +39,10 @@ ssize_t(vappendf)(char **b, const char *f, va_list v) { if ((r = (vsnprintf)(p + z.i, z.n ? z.n - W - z.i : 0, f, v)) >= 0) { n = ROUNDUP(z.i + r + 1, 8) + W; if (n > z.n) { - if (!z.n) z.n = W * 2; - while (n > z.n) z.n += z.n >> 1; + if (!z.n) + z.n = W * 2; + while (n > z.n) + z.n += z.n >> 1; z.n = ROUNDUP(z.n, W); if ((p = realloc(p, z.n))) { z.n = malloc_usable_size(p); @@ -54,7 +56,8 @@ ssize_t(vappendf)(char **b, const char *f, va_list v) { } } z.i += r; - if (!IsTiny() && W == 8) z.i |= (size_t)APPEND_COOKIE << 48; + if (!IsTiny() && W == 8) + z.i |= (size_t)APPEND_COOKIE << 48; *(size_t *)(p + z.n - W) = z.i; } va_end(w); diff --git a/libc/stdio/vcscanf.c b/libc/stdio/vcscanf.c index f58f21e74..e37b374ed 100644 --- a/libc/stdio/vcscanf.c +++ b/libc/stdio/vcscanf.c @@ -29,11 +29,12 @@ #include "libc/sysv/errfuns.h" #include "third_party/gdtoa/gdtoa.h" -#define READ \ - ({ \ - int c = callback(arg); \ - if (c != -1) ++consumed; \ - c; \ +#define READ \ + ({ \ + int c = callback(arg); \ + if (c != -1) \ + ++consumed; \ + c; \ }) #define FP_BUFFER_GROW 48 @@ -150,7 +151,8 @@ int __vcscanf(int callback(void *), // break; case 'c': rawmode = true; - if (!width) width = 1; + if (!width) + width = 1; // fallthrough case 's': while (isspace(c)) { @@ -574,7 +576,8 @@ int __vcscanf(int callback(void *), // buf = NULL; } else { do { - if (isspace(c)) break; + if (isspace(c)) + break; } while ((c = READ) != -1); } break; @@ -589,9 +592,11 @@ Done: while (freeme) { struct FreeMe *entry = freeme; freeme = entry->next; - if (items == -1) free(entry->ptr); + if (items == -1) + free(entry->ptr); free(entry); } - if (fpbuf) free(fpbuf); + if (fpbuf) + free(fpbuf); return items; } diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c index 39ac6873a..8dd53830d 100644 --- a/libc/stdio/vdprintf.c +++ b/libc/stdio/vdprintf.c @@ -63,7 +63,8 @@ int vdprintf(int fd, const char *fmt, va_list va) { t.n = 0; t.t = 0; t.fd = fd; - if (__fmt(vdprintf_putc, &t, fmt, va) == -1) return -1; + if (__fmt(vdprintf_putc, &t, fmt, va) == -1) + return -1; if (t.n) { iov[0].iov_base = t.b; iov[0].iov_len = t.n; diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c index 4edffd902..cdc7d3521 100644 --- a/libc/stdio/vsnprintf.c +++ b/libc/stdio/vsnprintf.c @@ -59,7 +59,9 @@ static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) { int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) { struct SprintfStr str = {buf, 0, size}; int rc = __fmt(vsnprintfputchar, &str, fmt, va); - if (rc < 0) return rc; - if (str.n) str.p[MIN(str.i, str.n - 1)] = '\0'; + if (rc < 0) + return rc; + if (str.n) + str.p[MIN(str.i, str.n - 1)] = '\0'; return str.i; } diff --git a/libc/str/a64l.c b/libc/str/a64l.c index 459221e1a..7b1b4f784 100644 --- a/libc/str/a64l.c +++ b/libc/str/a64l.c @@ -46,7 +46,8 @@ long a64l(const char *s) { uint32_t i, v, x; for (x = i = 0; i < 6; ++i) { v = kBase64i[s[i] & 0xff]; - if (v == -1) break; + if (v == -1) + break; x |= v << (i * 6); } return (int32_t)x; diff --git a/libc/str/blake2.c b/libc/str/blake2.c index 362a198da..acbeb1b70 100644 --- a/libc/str/blake2.c +++ b/libc/str/blake2.c @@ -117,7 +117,8 @@ int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) { if (todo > len) { todo = len; } - if (todo) memcpy(&b2b->block.bytes[b2b->block_used], data, todo); + if (todo) + memcpy(&b2b->block.bytes[b2b->block_used], data, todo); b2b->block_used += todo; data += todo; len -= todo; @@ -136,7 +137,8 @@ int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) { data += BLAKE2B_CBLOCK; len -= BLAKE2B_CBLOCK; } - if (len) memcpy(b2b->block.bytes, data, len); + if (len) + memcpy(b2b->block.bytes, data, len); b2b->block_used = len; return 0; } diff --git a/libc/str/c16rtomb.c b/libc/str/c16rtomb.c index 34406401e..546f40741 100644 --- a/libc/str/c16rtomb.c +++ b/libc/str/c16rtomb.c @@ -34,11 +34,13 @@ __static_yoink("musl_libc_notice"); size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) { static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; + if (!ps) + ps = (void *)&internal_state; unsigned *x = (unsigned *)ps; wchar_t wc; if (!s) { - if (*x) goto ilseq; + if (*x) + goto ilseq; return 1; } if (!*x && c16 - 0xd800u < 0x400) { diff --git a/libc/str/compareslices.c b/libc/str/compareslices.c index 5bea6bf11..b57b902a6 100644 --- a/libc/str/compareslices.c +++ b/libc/str/compareslices.c @@ -21,8 +21,11 @@ int CompareSlices(const char *a, size_t n, const char *b, size_t m) { int c; - if ((c = memcmp(a, b, MIN(n, m)))) return c; - if (n < m) return -1; - if (n > m) return +1; + if ((c = memcmp(a, b, MIN(n, m)))) + return c; + if (n < m) + return -1; + if (n > m) + return +1; return 0; } diff --git a/libc/str/compareslicescase.c b/libc/str/compareslicescase.c index 49e436655..a4f881450 100644 --- a/libc/str/compareslicescase.c +++ b/libc/str/compareslicescase.c @@ -21,8 +21,11 @@ int CompareSlicesCase(const char *a, size_t n, const char *b, size_t m) { int c; - if ((c = memcasecmp(a, b, MIN(n, m)))) return c; - if (n < m) return -1; - if (n > m) return +1; + if ((c = memcasecmp(a, b, MIN(n, m)))) + return c; + if (n < m) + return -1; + if (n > m) + return +1; return 0; } diff --git a/libc/str/endswith.c b/libc/str/endswith.c index bb1eb813d..04d58ee1a 100644 --- a/libc/str/endswith.c +++ b/libc/str/endswith.c @@ -28,6 +28,7 @@ bool32 endswith(const char *s, const char *suffix) { size_t n, m; n = strlen(s); m = strlen(suffix); - if (m > n) return false; + if (m > n) + return false; return !memcmp(s + n - m, suffix, m); } diff --git a/libc/str/endswith16.c b/libc/str/endswith16.c index 9d26484a1..a12523050 100644 --- a/libc/str/endswith16.c +++ b/libc/str/endswith16.c @@ -28,6 +28,7 @@ bool32 endswith16(const char16_t *s, const char16_t *suffix) { size_t n, m; n = strlen16(s); m = strlen16(suffix); - if (m > n) return false; + if (m > n) + return false; return memcmp(s + n - m, suffix, m * sizeof(char16_t)) == 0; } diff --git a/libc/str/getzipcfiletimestamps.c b/libc/str/getzipcfiletimestamps.c index da058f9ab..0a06b6992 100644 --- a/libc/str/getzipcfiletimestamps.c +++ b/libc/str/getzipcfiletimestamps.c @@ -36,9 +36,12 @@ void GetZipCfileTimestamps(const uint8_t *cf, struct timespec *mtim, struct timespec *atim, struct timespec *ctim, int gmtoff) { const uint8_t *p, *pe; - if (mtim) *mtim = (struct timespec){0}; - if (atim) *atim = (struct timespec){0}; - if (ctim) *ctim = (struct timespec){0}; + if (mtim) + *mtim = (struct timespec){0}; + if (atim) + *atim = (struct timespec){0}; + if (ctim) + *ctim = (struct timespec){0}; for (p = ZIP_CFILE_EXTRA(cf), pe = p + ZIP_CFILE_EXTRASIZE(cf); p + 4 <= pe; p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraNtfs && @@ -88,8 +91,10 @@ void GetZipCfileTimestamps(const uint8_t *cf, struct timespec *mtim, p += ZIP_EXTRA_SIZE(p)) { if (ZIP_EXTRA_HEADERID(p) == kZipExtraUnix && ZIP_EXTRA_CONTENTSIZE(p) >= 4 + 4) { - if (atim) atim->tv_sec = (int32_t)ZIP_READ32(ZIP_EXTRA_CONTENT(p) + 0); - if (mtim) mtim->tv_sec = (int32_t)ZIP_READ32(ZIP_EXTRA_CONTENT(p) + 4); + if (atim) + atim->tv_sec = (int32_t)ZIP_READ32(ZIP_EXTRA_CONTENT(p) + 0); + if (mtim) + mtim->tv_sec = (int32_t)ZIP_READ32(ZIP_EXTRA_CONTENT(p) + 4); return; } } diff --git a/libc/str/getzipeocd.c b/libc/str/getzipeocd.c index 3b9677c6c..ee862cc19 100644 --- a/libc/str/getzipeocd.c +++ b/libc/str/getzipeocd.c @@ -83,6 +83,7 @@ void *GetZipEocd(const void *f, size_t n, int *e) { return (void *)(p + i); } } while (i > 0 && i-- + 0x10000 + 0x1000 >= n); - if (e) *e = err; + if (e) + *e = err; return 0; } diff --git a/libc/str/highwayhash64.c b/libc/str/highwayhash64.c index 5cd7581a3..7041f7052 100644 --- a/libc/str/highwayhash64.c +++ b/libc/str/highwayhash64.c @@ -137,7 +137,8 @@ static void PermuteAndUpdate(HighwayHashState *state) { static uint64_t HighwayHashFinalize64(HighwayHashState *state) { int i; - for (i = 0; i < 4; i++) PermuteAndUpdate(state); + for (i = 0; i < 4; i++) + PermuteAndUpdate(state); return state->v0[0] + state->v1[0] + state->mul0[0] + state->mul1[0]; } @@ -148,7 +149,8 @@ static void ProcessAll(const uint8_t *data, size_t size, const uint64_t key[4], for (i = 0; i + 32 <= size; i += 32) { HighwayHashUpdatePacket(data + i, state); } - if ((size & 31) != 0) HighwayHashUpdateRemainder(data + i, size & 31, state); + if ((size & 31) != 0) + HighwayHashUpdateRemainder(data + i, size & 31, state); } /** diff --git a/libc/str/intsort.c b/libc/str/intsort.c index abfd12e79..335b7f98d 100644 --- a/libc/str/intsort.c +++ b/libc/str/intsort.c @@ -39,9 +39,12 @@ static void IntSort(int *A, long n) { InsertionSort(A, n); } else { for (p = A[n >> 1], i = 0, j = n - 1;; i++, j--) { - while (A[i] < p) i++; - while (A[j] > p) j--; - if (i >= j) break; + while (A[i] < p) + i++; + while (A[j] > p) + j--; + if (i >= j) + break; t = A[i]; A[i] = A[j]; A[j] = t; diff --git a/libc/str/isutf8.c b/libc/str/isutf8.c index ddca5e330..30f9600cd 100644 --- a/libc/str/isutf8.c +++ b/libc/str/isutf8.c @@ -51,7 +51,8 @@ static const char kUtf8Dispatch[] = { bool32 isutf8(const void *data, size_t size) { long c; const char *p, *e; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; p = data; e = p + size; while (p < e) { @@ -74,8 +75,10 @@ bool32 isutf8(const void *data, size_t size) { } } #endif - if (LIKELY((c = *p++ & 255) < 0200)) continue; - if (UNLIKELY(c < 0300)) return false; + if (LIKELY((c = *p++ & 255) < 0200)) + continue; + if (UNLIKELY(c < 0300)) + return false; switch (kUtf8Dispatch[c - 0300]) { case 0: return false; diff --git a/libc/str/iswlower.c b/libc/str/iswlower.c index dece35ae2..aba9180c6 100644 --- a/libc/str/iswlower.c +++ b/libc/str/iswlower.c @@ -25,7 +25,8 @@ int iswlower(wint_t c) { if (c < 0200) { return 'a' <= c && c <= 'z'; } else { - if (towupper(c) != c) return 1; + if (towupper(c) != c) + return 1; switch (c) { case 0x00df: /* ß Watin */ case 0x0138: /* ĸ Watin-A */ diff --git a/libc/str/iswupper.c b/libc/str/iswupper.c index ee5af5624..f965d51a6 100644 --- a/libc/str/iswupper.c +++ b/libc/str/iswupper.c @@ -25,7 +25,8 @@ int iswupper(wint_t c) { if (c < 0200) { return 'A' <= c && c <= 'Z'; } else { - if (towlower(c) != c) return 1; + if (towlower(c) != c) + return 1; switch (c) { case 0x03d2: /* ϒ Greek */ case 0x03d3: /* ϓ Greek */ diff --git a/libc/str/joinpaths.c b/libc/str/joinpaths.c index 6ff69eb54..43ae66656 100644 --- a/libc/str/joinpaths.c +++ b/libc/str/joinpaths.c @@ -41,8 +41,10 @@ char *__join_paths(char *buf, size_t size, const char *path, const char *other) { size_t pathlen, otherlen; - if (!other) return (char *)path; - if (!path) return (char *)other; + if (!other) + return (char *)path; + if (!path) + return (char *)other; pathlen = strlen(path); if (!pathlen || *other == '/') { return (/*unconst*/ char *)other; diff --git a/libc/str/longsort.c b/libc/str/longsort.c index 0fad01898..5ed1911cf 100644 --- a/libc/str/longsort.c +++ b/libc/str/longsort.c @@ -38,9 +38,12 @@ static void LongSort(long *A, long n) { InsertionSort(A, n); } else { for (p = A[n >> 1], i = 0, j = n - 1;; i++, j--) { - while (A[i] < p) i++; - while (A[j] > p) j--; - if (i >= j) break; + while (A[i] < p) + i++; + while (A[j] > p) + j--; + if (i >= j) + break; t = A[i]; A[i] = A[j]; A[j] = t; diff --git a/libc/str/lz4cpy.c b/libc/str/lz4cpy.c index 8897518fd..827a5226d 100644 --- a/libc/str/lz4cpy.c +++ b/libc/str/lz4cpy.c @@ -45,7 +45,8 @@ textstartup void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) { } while (*ip++ == 255); } repmovsb((void **)&op, (const void **)&ip, length); - if (ip >= ipe) break; + if (ip >= ipe) + break; offset = READ16LE(ip); matchlen = token & fifteen; ip += 2; diff --git a/libc/str/lz4len.c b/libc/str/lz4len.c index a58019515..8dd0fcf04 100644 --- a/libc/str/lz4len.c +++ b/libc/str/lz4len.c @@ -41,7 +41,8 @@ size_t lz4len(const void *blockdata, size_t blocksize) { } ip += length; unpacklen += length; - if (ip >= ipe) break; + if (ip >= ipe) + break; matchlen = token & fifteen; ip += 2; if (matchlen == fifteen) { diff --git a/libc/str/mbrlen.c b/libc/str/mbrlen.c index d4e9e3e49..4f20fe1a0 100644 --- a/libc/str/mbrlen.c +++ b/libc/str/mbrlen.c @@ -20,6 +20,7 @@ size_t mbrlen(const char *s, size_t n, mbstate_t *t) { static mbstate_t ss; - if (!t) t = &ss; + if (!t) + t = &ss; return mbrtowc(0, s, n, t); } diff --git a/libc/str/mbrtoc16.c b/libc/str/mbrtoc16.c index 40d366118..492ae68b6 100644 --- a/libc/str/mbrtoc16.c +++ b/libc/str/mbrtoc16.c @@ -33,13 +33,16 @@ __static_yoink("musl_libc_notice"); size_t mbrtoc16(char16_t *pc16, const char *s, size_t n, mbstate_t *ps) { static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; + if (!ps) + ps = (void *)&internal_state; unsigned *pending = (unsigned *)ps; - if (!s) return mbrtoc16(0, "", 1, ps); + if (!s) + return mbrtoc16(0, "", 1, ps); /* mbrtowc states for partial UTF-8 characters have the high bit set; * we use nonzero states without high bit for pending surrogates. */ if ((int)*pending > 0) { - if (pc16) *pc16 = *pending; + if (pc16) + *pc16 = *pending; *pending = 0; return -3; } @@ -50,7 +53,8 @@ size_t mbrtoc16(char16_t *pc16, const char *s, size_t n, mbstate_t *ps) { *pending = (wc & 0x3ff) + 0xdc00; wc = 0xd7c0 + (wc >> 10); } - if (pc16) *pc16 = wc; + if (pc16) + *pc16 = wc; } return ret; } diff --git a/libc/str/mbrtoc32.c b/libc/str/mbrtoc32.c index 00cc13ba7..535cb4f2f 100644 --- a/libc/str/mbrtoc32.c +++ b/libc/str/mbrtoc32.c @@ -33,10 +33,13 @@ __static_yoink("musl_libc_notice"); size_t mbrtoc32(char32_t *pc32, const char *s, size_t n, mbstate_t *ps) { static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; - if (!s) return mbrtoc32(0, "", 1, ps); + if (!ps) + ps = (void *)&internal_state; + if (!s) + return mbrtoc32(0, "", 1, ps); wchar_t wc; size_t ret = mbrtowc(&wc, s, n, ps); - if (ret <= 4 && pc32) *pc32 = wc; + if (ret <= 4 && pc32) + *pc32 = wc; return ret; } diff --git a/libc/str/mbrtowc.c b/libc/str/mbrtowc.c index 8a0f996ef..c62d98dfc 100644 --- a/libc/str/mbrtowc.c +++ b/libc/str/mbrtowc.c @@ -39,26 +39,33 @@ size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) { const unsigned char *s = (const void *)src; const unsigned N = n; wchar_t dummy; - if (!st) st = (void *)&internal_state; + if (!st) + st = (void *)&internal_state; c = *(unsigned *)st; if (!s) { - if (c) goto ilseq; + if (c) + goto ilseq; return 0; } else if (!wc) { wc = &dummy; } - if (!n) return -2; + if (!n) + return -2; if (!c) { - if (*s < 0x80) return !!(*wc = *s); - if (MB_CUR_MAX == 1) return (*wc = CODEUNIT(*s)), 1; - if (*s - SA > SB - SA) goto ilseq; + if (*s < 0x80) + return !!(*wc = *s); + if (MB_CUR_MAX == 1) + return (*wc = CODEUNIT(*s)), 1; + if (*s - SA > SB - SA) + goto ilseq; wut = *s++ - SA; wut = MAX(0, MIN(ARRAYLEN(kMbBittab) - 1, wut)); c = kMbBittab[wut]; n--; } if (n) { - if (OOB(c, *s)) goto ilseq; + if (OOB(c, *s)) + goto ilseq; loop: c = c << 6 | (*s++ - 0x80); n--; @@ -68,7 +75,8 @@ size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) { return N - n; } if (n) { - if (*s - 0x80u >= 0x40) goto ilseq; + if (*s - 0x80u >= 0x40) + goto ilseq; goto loop; } } diff --git a/libc/str/mbsnrtowcs.c b/libc/str/mbsnrtowcs.c index 504a81c45..9884cc3a9 100644 --- a/libc/str/mbsnrtowcs.c +++ b/libc/str/mbsnrtowcs.c @@ -47,7 +47,8 @@ size_t mbsnrtowcs(wchar_t *wcs, const char **src, size_t n, size_t wn, * that mbsrtowcs never reads more than n input bytes. thus * we can use mbsrtowcs as long as it's practical.. */ while (s && wn && ((n2 = n / 4) >= wn || n2 > 32)) { - if (n2 >= wn) n2 = wn; + if (n2 >= wn) + n2 = wn; tmp_s = s; l = mbsrtowcs(ws, &s, n2, st); if (!(l + 1)) { @@ -85,6 +86,7 @@ size_t mbsnrtowcs(wchar_t *wcs, const char **src, size_t n, size_t wn, wn--; cnt++; } - if (wcs) *src = s; + if (wcs) + *src = s; return cnt; } diff --git a/libc/str/mbsrtowcs.c b/libc/str/mbsrtowcs.c index 986172725..eaebe234c 100644 --- a/libc/str/mbsrtowcs.c +++ b/libc/str/mbsrtowcs.c @@ -45,13 +45,15 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { } } if (MB_CUR_MAX == 1) { - if (!ws) return strlen((const char *)s); + if (!ws) + return strlen((const char *)s); for (;;) { if (!wn) { *src = (const void *)s; return wn0; } - if (!*s) break; + if (!*s) + break; c = *s++; *ws++ = CODEUNIT(c); wn--; @@ -67,7 +69,8 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { wn--; continue; } - if (*s - SA > SB - SA) break; + if (*s - SA > SB - SA) + break; c = kMbBittab[*s++ - SA]; resume0: if (OOB(c, *s)) { @@ -103,7 +106,8 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { wn--; continue; } - if (*s - SA > SB - SA) break; + if (*s - SA > SB - SA) + break; c = kMbBittab[*s++ - SA]; resume: if (OOB(c, *s)) { @@ -137,6 +141,7 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { return wn0 - wn; } errno = EILSEQ; - if (ws) *src = (const void *)s; + if (ws) + *src = (const void *)s; return -1; } diff --git a/libc/str/mbtowc.c b/libc/str/mbtowc.c index 155270726..34b5f773d 100644 --- a/libc/str/mbtowc.c +++ b/libc/str/mbtowc.c @@ -35,30 +35,40 @@ int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) { unsigned c; const unsigned char *s = (const void *)src; wchar_t dummy; - if (!s) return 0; - if (!n) goto ilseq; - if (!wc) wc = &dummy; - if (*s < 0x80) return !!(*wc = *s); - if (MB_CUR_MAX == 1) return (*wc = CODEUNIT(*s)), 1; - if (*s - SA > SB - SA) goto ilseq; + if (!s) + return 0; + if (!n) + goto ilseq; + if (!wc) + wc = &dummy; + if (*s < 0x80) + return !!(*wc = *s); + if (MB_CUR_MAX == 1) + return (*wc = CODEUNIT(*s)), 1; + if (*s - SA > SB - SA) + goto ilseq; c = kMbBittab[*s++ - SA]; /* Avoid excessive checks against n: If shifting the state n-1 * times does not clear the high bit, then the value of n is * insufficient to read a character */ - if (n < 4 && ((c << (6 * n - 6)) & (1U << 31))) goto ilseq; - if (OOB(c, *s)) goto ilseq; + if (n < 4 && ((c << (6 * n - 6)) & (1U << 31))) + goto ilseq; + if (OOB(c, *s)) + goto ilseq; c = c << 6 | (*s++ - 0x80); if (!(c & (1U << 31))) { *wc = c; return 2; } - if (*s - 0x80u >= 0x40) goto ilseq; + if (*s - 0x80u >= 0x40) + goto ilseq; c = c << 6 | (*s++ - 0x80); if (!(c & (1U << 31))) { *wc = c; return 3; } - if (*s - 0x80u >= 0x40) goto ilseq; + if (*s - 0x80u >= 0x40) + goto ilseq; *wc = c << 6 | (*s++ - 0x80); return 4; ilseq: diff --git a/libc/str/memmem.c b/libc/str/memmem.c index 51975a3ef..ef3f721f0 100644 --- a/libc/str/memmem.c +++ b/libc/str/memmem.c @@ -39,8 +39,10 @@ __vex void *memmem(const void *haystack, size_t haystacklen, const void *needle, const xmm_t *v; unsigned i, k, m; const char *p, *q, *e; - if (!needlelen) return (void *)haystack; - if (UNLIKELY(needlelen > haystacklen)) return 0; + if (!needlelen) + return (void *)haystack; + if (UNLIKELY(needlelen > haystacklen)) + return 0; q = needle; c = *q; n = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; @@ -54,29 +56,38 @@ __vex void *memmem(const void *haystack, size_t haystacklen, const void *needle, for (;;) { while (!m) { ++v; - if ((const char *)v >= e) return 0; + if ((const char *)v >= e) + return 0; m = __builtin_ia32_pmovmskb128(*v == n); } do { k = __builtin_ctzl(m); p = (const char *)v + k; - if (UNLIKELY(p + needlelen > e)) return 0; + if (UNLIKELY(p + needlelen > e)) + return 0; for (i = 1;; ++i) { - if (i == needlelen) return (/*unconst*/ char *)p; - if (p[i] != q[i]) break; + if (i == needlelen) + return (/*unconst*/ char *)p; + if (p[i] != q[i]) + break; } m &= ~(1 << k); } while (m); } #else size_t i, j; - if (!needlelen) return (void *)haystack; - if (needlelen > haystacklen) return 0; + if (!needlelen) + return (void *)haystack; + if (needlelen > haystacklen) + return 0; for (i = 0; i < haystacklen; ++i) { for (j = 0;; ++j) { - if (j == needlelen) return (/*unconst*/ char *)haystack + i; - if (i + j == haystacklen) break; - if (((char *)haystack)[i + j] != ((char *)needle)[j]) break; + if (j == needlelen) + return (/*unconst*/ char *)haystack + i; + if (i + j == haystacklen) + break; + if (((char *)haystack)[i + j] != ((char *)needle)[j]) + break; } } return 0; diff --git a/libc/str/rawmemchr.c b/libc/str/rawmemchr.c index d3b4a5523..dadf37160 100644 --- a/libc/str/rawmemchr.c +++ b/libc/str/rawmemchr.c @@ -81,7 +81,8 @@ __vex void *rawmemchr(const void *s, int c) { c &= 255; v = 0x0101010101010101ul * c; for (; (uintptr_t)p & 7; ++p) { - if (*p == c) return (void *)p; + if (*p == c) + return (void *)p; } for (;; p += 8) { w = UncheckedAlignedRead64(p); diff --git a/libc/str/smoothsort.c b/libc/str/smoothsort.c index ba84be2e4..fac8a9011 100644 --- a/libc/str/smoothsort.c +++ b/libc/str/smoothsort.c @@ -159,7 +159,8 @@ static void SmoothSort(struct SmoothSort *s, void *base, size_t nel, size_t p[2] = {1, 0}; int pshift = 1; int trail; - if (!size) return; + if (!size) + return; head = base; high = head + size - width; // precompute Leonardo numbers, scaled by element width diff --git a/libc/str/startswith.c b/libc/str/startswith.c index 822f372c4..008cd2e25 100644 --- a/libc/str/startswith.c +++ b/libc/str/startswith.c @@ -26,8 +26,11 @@ */ bool32 startswith(const char *s, const char *prefix) { for (;;) { - if (!*prefix) return true; - if (!*s) return false; - if (*s++ != *prefix++) return false; + if (!*prefix) + return true; + if (!*s) + return false; + if (*s++ != *prefix++) + return false; } } diff --git a/libc/str/startswith16.c b/libc/str/startswith16.c index 9de1b0730..8210dc3c1 100644 --- a/libc/str/startswith16.c +++ b/libc/str/startswith16.c @@ -26,8 +26,11 @@ */ bool32 startswith16(const char16_t *s, const char16_t *prefix) { for (;;) { - if (!*prefix) return true; - if (!*s) return false; - if (*s++ != *prefix++) return false; + if (!*prefix) + return true; + if (!*s) + return false; + if (*s++ != *prefix++) + return false; } } diff --git a/libc/str/startswithi.c b/libc/str/startswithi.c index dd5cb5707..974ece794 100644 --- a/libc/str/startswithi.c +++ b/libc/str/startswithi.c @@ -24,8 +24,11 @@ */ bool32 startswithi(const char *s, const char *prefix) { for (;;) { - if (!*prefix) return true; - if (!*s) return false; - if (kToLower[*s++ & 255] != kToLower[*prefix++ & 255]) return false; + if (!*prefix) + return true; + if (!*s) + return false; + if (kToLower[*s++ & 255] != kToLower[*prefix++ & 255]) + return false; } } diff --git a/libc/str/stpncpy.c b/libc/str/stpncpy.c index 6cae8f6bc..30b6f2bb9 100644 --- a/libc/str/stpncpy.c +++ b/libc/str/stpncpy.c @@ -38,8 +38,10 @@ char *stpncpy(char *dst, const char *src, size_t dstlen) { size_t srclen, cpylen, zerlen; srclen = strlen(src); cpylen = MIN(srclen, dstlen); - if (cpylen) memcpy(dst, src, cpylen); + if (cpylen) + memcpy(dst, src, cpylen); zerlen = dstlen - cpylen; - if (zerlen) bzero(dst + cpylen, zerlen); + if (zerlen) + bzero(dst + cpylen, zerlen); return dst + cpylen; } diff --git a/libc/str/strcasecmp.c b/libc/str/strcasecmp.c index edeb633fc..2443afd93 100644 --- a/libc/str/strcasecmp.c +++ b/libc/str/strcasecmp.c @@ -32,7 +32,8 @@ int strcasecmp(const char *a, const char *b) { int x, y; size_t i = 0; uint64_t v, w; - if (a == b) return 0; + if (a == b) + return 0; if (((uintptr_t)a & 7) == ((uintptr_t)b & 7)) { for (; (uintptr_t)(a + i) & 7; ++i) { CheckEm: @@ -50,7 +51,8 @@ int strcasecmp(const char *a, const char *b) { } } } else { - while ((x = kToLower[a[i] & 255]) == (y = kToLower[b[i] & 255]) && y) ++i; + while ((x = kToLower[a[i] & 255]) == (y = kToLower[b[i] & 255]) && y) + ++i; return x - y; } } diff --git a/libc/str/strcasecmp16.c b/libc/str/strcasecmp16.c index 948b81725..8420ba882 100644 --- a/libc/str/strcasecmp16.c +++ b/libc/str/strcasecmp16.c @@ -29,6 +29,7 @@ int strcasecmp16(const char16_t *l, const char16_t *r) { int x, y; size_t i = 0; - while ((x = towlower(l[i])) == (y = towlower(r[i])) && r[i]) ++i; + while ((x = towlower(l[i])) == (y = towlower(r[i])) && r[i]) + ++i; return x - y; } diff --git a/libc/str/strcasestr.c b/libc/str/strcasestr.c index cf46cb3f1..26f969c09 100644 --- a/libc/str/strcasestr.c +++ b/libc/str/strcasestr.c @@ -41,7 +41,8 @@ __vex char *strcasestr(const char *haystack, const char *needle) { unsigned k, m; const xmm_t *p; xmm_t v, n1, n2, z = {0}; - if (haystack == needle || !*needle) return (char *)haystack; + if (haystack == needle || !*needle) + return (char *)haystack; c = *needle; n1 = (xmm_t){c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; c = kToLower[c & 255]; @@ -59,23 +60,32 @@ __vex char *strcasestr(const char *haystack, const char *needle) { } haystack = (const char *)p + __builtin_ctzl(m); for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; #else size_t i; - if (haystack == needle || !*needle) return (void *)haystack; + if (haystack == needle || !*needle) + return (void *)haystack; for (;;) { for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; #endif diff --git a/libc/str/strchr16.c b/libc/str/strchr16.c index 2cd2c994c..15e9043de 100644 --- a/libc/str/strchr16.c +++ b/libc/str/strchr16.c @@ -23,7 +23,9 @@ */ char16_t *strchr16(const char16_t *s, int c) { for (;; ++s) { - if ((*s & 65535) == (c & 65535)) return (char16_t *)s; - if (!*s) return (char16_t *)0; + if ((*s & 65535) == (c & 65535)) + return (char16_t *)s; + if (!*s) + return (char16_t *)0; } } diff --git a/libc/str/strchrnul16.c b/libc/str/strchrnul16.c index 158b2d54d..34704d8c8 100644 --- a/libc/str/strchrnul16.c +++ b/libc/str/strchrnul16.c @@ -23,7 +23,9 @@ */ char16_t *strchrnul16(const char16_t *s, int c) { for (;; ++s) { - if ((*s & 65535) == (c & 65535)) return (char16_t *)s; - if (!*s) return (char16_t *)s; + if ((*s & 65535) == (c & 65535)) + return (char16_t *)s; + if (!*s) + return (char16_t *)s; } } diff --git a/libc/str/strcmp16.c b/libc/str/strcmp16.c index 2dcb145b4..7fd4ab7f3 100644 --- a/libc/str/strcmp16.c +++ b/libc/str/strcmp16.c @@ -28,6 +28,7 @@ */ int strcmp16(const char16_t *l, const char16_t *r) { size_t i = 0; - while (l[i] == r[i] && r[i]) ++i; + while (l[i] == r[i] && r[i]) + ++i; return l[i] - r[i]; } diff --git a/libc/str/strlen16.c b/libc/str/strlen16.c index cb9fe11c8..0d8ccacf7 100644 --- a/libc/str/strlen16.c +++ b/libc/str/strlen16.c @@ -35,12 +35,14 @@ __vex size_t strlen16(const char16_t *s) { unsigned m, k = (uintptr_t)s & 15; const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16); m = __builtin_ia32_pmovmskb128(*p == z) >> k << k; - while (!m) m = __builtin_ia32_pmovmskb128(*++p == z); + while (!m) + m = __builtin_ia32_pmovmskb128(*++p == z); n = (const char16_t *)p + (__builtin_ctzl(m) >> 1) - s; return n; #else size_t n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; #endif } diff --git a/libc/str/strncasecmp.c b/libc/str/strncasecmp.c index ccdc0e2e0..419b7eec8 100644 --- a/libc/str/strncasecmp.c +++ b/libc/str/strncasecmp.c @@ -30,7 +30,8 @@ int strncasecmp(const char *a, const char *b, size_t n) { int x, y; size_t i = 0; - if (!n-- || a == b) return 0; + if (!n-- || a == b) + return 0; while ((x = kToLower[a[i] & 0xff]) == (y = kToLower[b[i] & 0xff]) && b[i] && i < n) { ++i; diff --git a/libc/str/strncasecmp16.c b/libc/str/strncasecmp16.c index 7b7657024..4d39f6bea 100644 --- a/libc/str/strncasecmp16.c +++ b/libc/str/strncasecmp16.c @@ -29,7 +29,9 @@ int strncasecmp16(const char16_t *a, const char16_t *b, size_t n) { int x, y; size_t i = 0; - if (!n-- || a == b) return 0; - while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) ++i; + if (!n-- || a == b) + return 0; + while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) + ++i; return x - y; } diff --git a/libc/str/strncat16.c b/libc/str/strncat16.c index 21867be5a..266b5fdf2 100644 --- a/libc/str/strncat16.c +++ b/libc/str/strncat16.c @@ -33,7 +33,8 @@ char16_t *strncat16(char16_t *d, const char16_t *s, size_t n) { size_t i; char16_t *r = d; d += strlen16(d); - for (i = 0; i < n && s[i]; ++i) d[i] = s[i]; + for (i = 0; i < n && s[i]; ++i) + d[i] = s[i]; d[i] = 0; return r; } diff --git a/libc/str/strncmp16.c b/libc/str/strncmp16.c index e14ea6063..d1cc1eb7c 100644 --- a/libc/str/strncmp16.c +++ b/libc/str/strncmp16.c @@ -28,7 +28,9 @@ */ int strncmp16(const char16_t *a, const char16_t *b, size_t n) { size_t i = 0; - if (!n-- || a == b) return 0; - while (i < n && a[i] == b[i] && b[i]) ++i; + if (!n-- || a == b) + return 0; + while (i < n && a[i] == b[i] && b[i]) + ++i; return a[i] - b[i]; } diff --git a/libc/str/strncpy.c b/libc/str/strncpy.c index 1cdf70d74..26ac33e02 100644 --- a/libc/str/strncpy.c +++ b/libc/str/strncpy.c @@ -38,8 +38,10 @@ char *strncpy(char *dst, const char *src, size_t dstlen) { size_t srclen, cpylen, zerlen; srclen = strlen(src); cpylen = MIN(srclen, dstlen); - if (cpylen) memcpy(dst, src, cpylen); + if (cpylen) + memcpy(dst, src, cpylen); zerlen = dstlen - cpylen; - if (zerlen) bzero(dst + cpylen, zerlen); + if (zerlen) + bzero(dst + cpylen, zerlen); return dst; } diff --git a/libc/str/strnlen16.c b/libc/str/strnlen16.c index cc422eb12..d55fc3f29 100644 --- a/libc/str/strnlen16.c +++ b/libc/str/strnlen16.c @@ -30,7 +30,8 @@ size_t strnlen16(const char16_t *s, size_t n) { size_t i; for (i = 0;; ++i) { - if (i == n || !s[i]) break; + if (i == n || !s[i]) + break; } unassert(i == n || (i < n && !s[i])); return i; diff --git a/libc/str/strnlen_s.c b/libc/str/strnlen_s.c index c95d88b41..b8d3e8a46 100644 --- a/libc/str/strnlen_s.c +++ b/libc/str/strnlen_s.c @@ -46,13 +46,16 @@ static size_t strnlen_s_x64(const char *s, size_t n, size_t i) { */ size_t strnlen_s(const char *s, size_t n) { size_t i; - if (!s) return 0; + if (!s) + return 0; for (i = 0; (uintptr_t)(s + i) & 7; ++i) { - if (i == n || !s[i]) return i; + if (i == n || !s[i]) + return i; } i = strnlen_s_x64(s, n, i); for (;; ++i) { - if (i == n || !s[i]) break; + if (i == n || !s[i]) + break; } unassert(i == n || (i < n && !s[i])); return i; diff --git a/libc/str/strnwidth.c b/libc/str/strnwidth.c index f95decb7f..0e39fc70a 100644 --- a/libc/str/strnwidth.c +++ b/libc/str/strnwidth.c @@ -64,7 +64,8 @@ int strnwidth(const char *s, size_t n, size_t o) { case kUtf8: if (ThomPikeCont(c)) { w = ThomPikeMerge(w, c); - if (--r) break; + if (--r) + break; } l += MAX(0, wcwidth(w)); t = kAscii; diff --git a/libc/str/strstr.c b/libc/str/strstr.c index b428851b0..6557ac91a 100644 --- a/libc/str/strstr.c +++ b/libc/str/strstr.c @@ -40,7 +40,8 @@ __vex char *strstr(const char *haystack, const char *needle) { unsigned k, m; const xmm_t *p; xmm_t v, n, z = {0}; - if (haystack == needle || !*needle) return (char *)haystack; + if (haystack == needle || !*needle) + return (char *)haystack; n = (xmm_t){*needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle, *needle}; @@ -57,23 +58,32 @@ __vex char *strstr(const char *haystack, const char *needle) { } haystack = (const char *)p + __builtin_ctzl(m); for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; #else size_t i; - if (haystack == needle || !*needle) return (void *)haystack; + if (haystack == needle || !*needle) + return (void *)haystack; for (;;) { for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; #endif diff --git a/libc/str/strstr16.c b/libc/str/strstr16.c index b34598e2f..aac0f8e3e 100644 --- a/libc/str/strstr16.c +++ b/libc/str/strstr16.c @@ -31,12 +31,16 @@ char16_t *strstr16(const char16_t *haystack, const char16_t *needle) { size_t i; for (;;) { for (i = 0;;) { - if (!needle[i]) return (/*unconst*/ char16_t *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ char16_t *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; ++i; } - if (!*haystack++) break; + if (!*haystack++) + break; } return NULL; } diff --git a/libc/str/towctrans.c b/libc/str/towctrans.c index 5d2d2483a..87f1a87bc 100644 --- a/libc/str/towctrans.c +++ b/libc/str/towctrans.c @@ -19,7 +19,9 @@ #include "libc/str/str.h" wint_t towctrans(wint_t c, wctrans_t t) { - if (t == (wctrans_t)1) return towupper(c); - if (t == (wctrans_t)2) return towlower(c); + if (t == (wctrans_t)1) + return towupper(c); + if (t == (wctrans_t)2) + return towlower(c); return c; } diff --git a/libc/str/tprecode16to8.c b/libc/str/tprecode16to8.c index fa1895f6b..9bea83682 100644 --- a/libc/str/tprecode16to8.c +++ b/libc/str/tprecode16to8.c @@ -37,7 +37,8 @@ static axdx_t tprecode16to8_sse2(char *dst, size_t dstsize, const char16_t *src, pcmpgtw(v2, v1, vz); pcmpgtw(v3, v1, kDel16); pandn((void *)v2, (void *)v3, (void *)v2); - if (pmovmskb((void *)v2) != 0xFFFF) break; + if (pmovmskb((void *)v2) != 0xFFFF) + break; packsswb((void *)v1, v1, v1); memcpy(dst + r.ax, v1, 8); r.ax += 8; @@ -70,10 +71,13 @@ axdx_t tprecode16to8(char *dst, size_t dstsize, const char16_t *src) { r = tprecode16to8_sse2(dst, dstsize, src, r); } #endif - if (!(x = src[r.dx++])) break; - if (IsUtf16Cont(x)) continue; + if (!(x = src[r.dx++])) + break; + if (IsUtf16Cont(x)) + continue; if (!IsUcs2(x)) { - if (!(y = src[r.dx++])) break; + if (!(y = src[r.dx++])) + break; x = MergeUtf16(x, y); } w = tpenc(x); diff --git a/libc/str/tprecode8to16.c b/libc/str/tprecode8to16.c index 6ece0f1b5..d823f3163 100644 --- a/libc/str/tprecode8to16.c +++ b/libc/str/tprecode8to16.c @@ -32,7 +32,8 @@ static inline axdx_t tprecode8to16_sse2(char16_t *dst, size_t dstsize, while (r.ax + 16 < dstsize) { memcpy(v1, src + r.dx, 16); pcmpgtb((int8_t *)v2, (int8_t *)v1, (int8_t *)vz); - if (pmovmskb(v2) != 0xFFFF) break; + if (pmovmskb(v2) != 0xFFFF) + break; punpcklbw(v2, v1, vz); punpckhbw(v1, v1, vz); memcpy(dst + r.ax + 0, v2, 16); @@ -73,8 +74,10 @@ axdx_t tprecode8to16(char16_t *dst, size_t dstsize, const char *src) { a = ThomPikeByte(x); n = ThomPikeLen(x) - 1; for (i = 0;;) { - if (!(b = src[r.dx + i] & 0377)) break; - if (!ThomPikeCont(b)) break; + if (!(b = src[r.dx + i] & 0377)) + break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++i == n) { r.dx += i; @@ -83,7 +86,8 @@ axdx_t tprecode8to16(char16_t *dst, size_t dstsize, const char *src) { } } } - if (!x) break; + if (!x) + break; w = EncodeUtf16(x); while (w && r.ax + 1 < dstsize) { dst[r.ax++] = w; diff --git a/libc/str/wcrtomb.c b/libc/str/wcrtomb.c index 0a8f6b155..1596c63e6 100644 --- a/libc/str/wcrtomb.c +++ b/libc/str/wcrtomb.c @@ -32,7 +32,8 @@ __static_yoink("musl_libc_notice"); size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) { - if (!s) return 1; + if (!s) + return 1; if ((unsigned)wc < 0x80) { *s = wc; return 1; diff --git a/libc/str/wcscasecmp.c b/libc/str/wcscasecmp.c index d9c060759..8f32d77cc 100644 --- a/libc/str/wcscasecmp.c +++ b/libc/str/wcscasecmp.c @@ -29,7 +29,9 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b) { size_t i = 0; unsigned x, y; - if (a == b) return 0; - while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i]) ++i; + if (a == b) + return 0; + while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i]) + ++i; return x - y; } diff --git a/libc/str/wcschr.c b/libc/str/wcschr.c index acb05c808..d63aa2a77 100644 --- a/libc/str/wcschr.c +++ b/libc/str/wcschr.c @@ -23,7 +23,9 @@ */ wchar_t *wcschr(const wchar_t *s, wchar_t c) { for (;; ++s) { - if (*s == c) return (wchar_t *)s; - if (!*s) return 0; + if (*s == c) + return (wchar_t *)s; + if (!*s) + return 0; } } diff --git a/libc/str/wcschrnul.c b/libc/str/wcschrnul.c index 19b553e59..4161a513d 100644 --- a/libc/str/wcschrnul.c +++ b/libc/str/wcschrnul.c @@ -20,7 +20,9 @@ wchar_t *wcschrnul(const wchar_t *s, wchar_t c) { for (;; ++s) { - if (*s == c) return (wchar_t *)s; - if (!*s) return (wchar_t *)s; + if (*s == c) + return (wchar_t *)s; + if (!*s) + return (wchar_t *)s; } } diff --git a/libc/str/wcscmp.c b/libc/str/wcscmp.c index 0661245ee..3a36e3f22 100644 --- a/libc/str/wcscmp.c +++ b/libc/str/wcscmp.c @@ -28,8 +28,10 @@ */ int wcscmp(const wchar_t *a, const wchar_t *b) { size_t i = 0; - if (a == b) return 0; - while (a[i] == b[i] && b[i]) ++i; + if (a == b) + return 0; + while (a[i] == b[i] && b[i]) + ++i; return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i]; } diff --git a/libc/str/wcsendswith.c b/libc/str/wcsendswith.c index 2257c0b82..0dbba86ac 100644 --- a/libc/str/wcsendswith.c +++ b/libc/str/wcsendswith.c @@ -28,6 +28,7 @@ bool32 wcsendswith(const wchar_t *s, const wchar_t *suffix) { size_t n, m; n = wcslen(s); m = wcslen(suffix); - if (m > n) return false; + if (m > n) + return false; return memcmp(s + n - m, suffix, m * sizeof(wchar_t)) == 0; } diff --git a/libc/str/wcslen.c b/libc/str/wcslen.c index 9dbbfcbee..b1f86bd1c 100644 --- a/libc/str/wcslen.c +++ b/libc/str/wcslen.c @@ -35,12 +35,14 @@ __vex size_t wcslen(const wchar_t *s) { unsigned m, k = (uintptr_t)s & 15; const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16); m = __builtin_ia32_pmovmskb128(*p == z) >> k << k; - while (!m) m = __builtin_ia32_pmovmskb128(*++p == z); + while (!m) + m = __builtin_ia32_pmovmskb128(*++p == z); n = (const wchar_t *)p + (__builtin_ctzl(m) >> 2) - s; return n; #else size_t n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; #endif } diff --git a/libc/str/wcsncasecmp.c b/libc/str/wcsncasecmp.c index 658492481..b98b4baaa 100644 --- a/libc/str/wcsncasecmp.c +++ b/libc/str/wcsncasecmp.c @@ -29,7 +29,9 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { size_t i = 0; unsigned x, y; - if (!n-- || a == b) return 0; - while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) ++i; + if (!n-- || a == b) + return 0; + while ((x = towlower(a[i])) == (y = towlower(b[i])) && b[i] && i < n) + ++i; return x - y; } diff --git a/libc/str/wcsncat.c b/libc/str/wcsncat.c index e7a6ffd60..6e7c7ea92 100644 --- a/libc/str/wcsncat.c +++ b/libc/str/wcsncat.c @@ -33,7 +33,8 @@ wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) { size_t i; wchar_t *r = d; d += wcslen(d); - for (i = 0; i < n && s[i]; ++i) d[i] = s[i]; + for (i = 0; i < n && s[i]; ++i) + d[i] = s[i]; d[i] = 0; return r; } diff --git a/libc/str/wcsncmp.c b/libc/str/wcsncmp.c index b41304727..b576af3ad 100644 --- a/libc/str/wcsncmp.c +++ b/libc/str/wcsncmp.c @@ -28,7 +28,9 @@ */ int wcsncmp(const wchar_t *a, const wchar_t *b, size_t n) { size_t i = 0; - if (!n-- || a == b) return 0; - while (i < n && a[i] == b[i] && b[i]) ++i; + if (!n-- || a == b) + return 0; + while (i < n && a[i] == b[i] && b[i]) + ++i; return (int)a[i] < (int)b[i] ? -1 : (int)a[i] > (int)b[i]; } diff --git a/libc/str/wcsnlen_s.c b/libc/str/wcsnlen_s.c index 75a8f60da..70e8f9f02 100644 --- a/libc/str/wcsnlen_s.c +++ b/libc/str/wcsnlen_s.c @@ -27,6 +27,7 @@ * @asyncsignalsafe */ size_t wcsnlen_s(const wchar_t *s, size_t n) { - if (!s) return 0; + if (!s) + return 0; return wcsnlen(s, n); } diff --git a/libc/str/wcsnrtombs.c b/libc/str/wcsnrtombs.c index 4486ce579..549a706f9 100644 --- a/libc/str/wcsnrtombs.c +++ b/libc/str/wcsnrtombs.c @@ -35,7 +35,8 @@ size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t *st) { const wchar_t *ws = *wcs; size_t cnt = 0; - if (!dst) n = 0; + if (!dst) + n = 0; while (ws && wn) { char tmp[MB_LEN_MAX]; size_t l = wcrtomb(n < MB_LEN_MAX ? tmp : dst, *ws, 0); @@ -45,7 +46,8 @@ size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, } if (dst) { if (n < MB_LEN_MAX) { - if (l > n) break; + if (l > n) + break; memcpy(dst, tmp, l); } dst += l; @@ -59,6 +61,7 @@ size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, wn--; cnt += l; } - if (dst) *wcs = ws; + if (dst) + *wcs = ws; return cnt; } diff --git a/libc/str/wcsrtombs.c b/libc/str/wcsrtombs.c index f1ad160e9..70d115684 100644 --- a/libc/str/wcsrtombs.c +++ b/libc/str/wcsrtombs.c @@ -39,7 +39,8 @@ size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) { for (n = 0, ws2 = *ws; *ws2; ws2++) { if (*ws2 >= 0x80u) { l = wcrtomb(buf, *ws2, 0); - if (!(l + 1)) return -1; + if (!(l + 1)) + return -1; n += l; } else n++; @@ -54,7 +55,8 @@ size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) { return N - n; } l = wcrtomb(s, **ws, 0); - if (!(l + 1)) return -1; + if (!(l + 1)) + return -1; s += l; n -= l; } else { @@ -71,8 +73,10 @@ size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) { return N - n; } l = wcrtomb(buf, **ws, 0); - if (!(l + 1)) return -1; - if (l > n) return N - n; + if (!(l + 1)) + return -1; + if (l > n) + return N - n; wcrtomb(s, **ws, 0); s += l; n -= l; diff --git a/libc/str/wcsstartswith.c b/libc/str/wcsstartswith.c index f85883a53..0aecfdff9 100644 --- a/libc/str/wcsstartswith.c +++ b/libc/str/wcsstartswith.c @@ -26,8 +26,11 @@ */ bool32 wcsstartswith(const wchar_t *s, const wchar_t *prefix) { for (;;) { - if (!*prefix) return true; - if (!*s) return false; - if (*s++ != *prefix++) return false; + if (!*prefix) + return true; + if (!*s) + return false; + if (*s++ != *prefix++) + return false; } } diff --git a/libc/str/wcsstr.c b/libc/str/wcsstr.c index 886b71d3e..1867ecd93 100644 --- a/libc/str/wcsstr.c +++ b/libc/str/wcsstr.c @@ -31,12 +31,16 @@ wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) { size_t i; for (;;) { for (i = 0;;) { - if (!needle[i]) return (/*unconst*/ wchar_t *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ wchar_t *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; ++i; } - if (!*haystack++) break; + if (!*haystack++) + break; } return NULL; } diff --git a/libc/str/wctob.c b/libc/str/wctob.c index bd5ff66b6..4fba0c5fc 100644 --- a/libc/str/wctob.c +++ b/libc/str/wctob.c @@ -32,7 +32,9 @@ __static_yoink("musl_libc_notice"); int wctob(wint_t c) { - if (c < 128U) return c; - if (MB_CUR_MAX == 1 && IS_CODEUNIT(c)) return (unsigned char)c; + if (c < 128U) + return c; + if (MB_CUR_MAX == 1 && IS_CODEUNIT(c)) + return (unsigned char)c; return EOF; } diff --git a/libc/str/wctomb.c b/libc/str/wctomb.c index 2c00c3352..e2ca942d1 100644 --- a/libc/str/wctomb.c +++ b/libc/str/wctomb.c @@ -20,6 +20,7 @@ #include "libc/str/str.h" int wctomb(char *s, wchar_t wc) { - if (!s) return 0; + if (!s) + return 0; return wcrtomb(s, wc, 0); } diff --git a/libc/str/wctrans.c b/libc/str/wctrans.c index f2cff2c86..2fa75a817 100644 --- a/libc/str/wctrans.c +++ b/libc/str/wctrans.c @@ -19,7 +19,9 @@ #include "libc/str/str.h" wctrans_t wctrans(const char *s) { - if (!strcmp(s, "toupper")) return (wctrans_t)1; - if (!strcmp(s, "tolower")) return (wctrans_t)2; + if (!strcmp(s, "toupper")) + return (wctrans_t)1; + if (!strcmp(s, "tolower")) + return (wctrans_t)2; return 0; } diff --git a/libc/str/wcwidth.c b/libc/str/wcwidth.c index 1ce4dc2ce..093133c2e 100644 --- a/libc/str/wcwidth.c +++ b/libc/str/wcwidth.c @@ -26,15 +26,19 @@ */ int wcwidth(wchar_t c) { int res; - if (LIKELY(32 <= c && c < 127)) return 1; + if (LIKELY(32 <= c && c < 127)) + return 1; if (VERY_UNLIKELY((uint32_t)c >= 0x100000)) { - if ((uint32_t)c <= 0x10FFFD) return 1; + if ((uint32_t)c <= 0x10FFFD) + return 1; return -1; } res = _wcwidth_osx(c); if (VERY_UNLIKELY(!res)) { - if (!c) return 0; - if (iswcntrl(c)) return -1; + if (!c) + return 0; + if (iswcntrl(c)) + return -1; } return res; } diff --git a/libc/str/wmemcpy.c b/libc/str/wmemcpy.c index 5d376eb72..a9f265ddc 100644 --- a/libc/str/wmemcpy.c +++ b/libc/str/wmemcpy.c @@ -21,6 +21,7 @@ wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) { size_t bytes; - if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1; + if (ckd_mul(&bytes, count, sizeof(wchar_t))) + bytes = -1; return memcpy(dest, src, bytes); } diff --git a/libc/str/wmemmove.c b/libc/str/wmemmove.c index 58b95cd30..b59ac3008 100644 --- a/libc/str/wmemmove.c +++ b/libc/str/wmemmove.c @@ -21,6 +21,7 @@ wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count) { size_t bytes; - if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1; + if (ckd_mul(&bytes, count, sizeof(wchar_t))) + bytes = -1; return memmove(dest, src, bytes); } diff --git a/libc/str/wmempcpy.c b/libc/str/wmempcpy.c index 8b69d541a..a860ed60d 100644 --- a/libc/str/wmempcpy.c +++ b/libc/str/wmempcpy.c @@ -21,6 +21,7 @@ wchar_t *wmempcpy(wchar_t *dest, const wchar_t *src, size_t count) { size_t bytes; - if (ckd_mul(&bytes, count, sizeof(wchar_t))) bytes = -1; + if (ckd_mul(&bytes, count, sizeof(wchar_t))) + bytes = -1; return mempcpy(dest, src, bytes); } diff --git a/libc/testlib/almostequallongdouble.c b/libc/testlib/almostequallongdouble.c index dc53ad847..2db17007b 100644 --- a/libc/testlib/almostequallongdouble.c +++ b/libc/testlib/almostequallongdouble.c @@ -23,6 +23,7 @@ bool testlib_almostequallongdouble(long double x, long double y) { /* TODO(jart): This algorithm has to be binary. */ - if (isnan(x) || isnan(y)) return false; + if (isnan(x) || isnan(y)) + return false; return fabsl(x - y) <= EPSILON; } diff --git a/libc/testlib/benchrunner.c b/libc/testlib/benchrunner.c index cdb9a6b56..f99c1a80f 100644 --- a/libc/testlib/benchrunner.c +++ b/libc/testlib/benchrunner.c @@ -54,7 +54,8 @@ void testlib_benchwarmup(void) { void EnableCruiseControlForCool(void) { int fd, micros = 10; - if (!IsLinux()) return; + if (!IsLinux()) + return; BLOCK_CANCELATION; if ((fd = __sys_openat(AT_FDCWD, "/dev/cpu_dma_latency", O_WRONLY, 0)) != -1) { diff --git a/libc/testlib/binequals.c b/libc/testlib/binequals.c index 589015200..f56000a38 100644 --- a/libc/testlib/binequals.c +++ b/libc/testlib/binequals.c @@ -30,11 +30,15 @@ bool testlib_binequals(const char16_t *want, const void *got, size_t n) { size_t i; const unsigned char *p = (const unsigned char *)got; - if (!got) return false; + if (!got) + return false; for (i = 0; i < n; ++i) { - if (!want[i]) break; - if (i == n) break; - if (want[i] != kCp437[p[i]]) return false; + if (!want[i]) + break; + if (i == n) + break; + if (want[i] != kCp437[p[i]]) + return false; } return true; } diff --git a/libc/testlib/contains.c b/libc/testlib/contains.c index 155071309..ea7a00576 100644 --- a/libc/testlib/contains.c +++ b/libc/testlib/contains.c @@ -20,8 +20,10 @@ #include "libc/testlib/testlib.h" bool testlib_contains(size_t cw, const void *s, const void *needle) { - if (s == needle) return true; - if (!s || !needle) return false; + if (s == needle) + return true; + if (!s || !needle) + return false; return sizeof(cw) == sizeof(char16_t) ? !!strstr16(s, needle) : !!strstr(s, needle); } diff --git a/libc/testlib/endswith.c b/libc/testlib/endswith.c index b513116cf..7da23e47d 100644 --- a/libc/testlib/endswith.c +++ b/libc/testlib/endswith.c @@ -20,8 +20,10 @@ #include "libc/testlib/testlib.h" bool testlib_endswith(size_t cw, const void *s, const void *suffix) { - if (s == suffix) return true; - if (!s || !suffix) return false; + if (s == suffix) + return true; + if (!s || !suffix) + return false; return cw == sizeof(wchar_t) ? wcsendswith(s, suffix) : cw == sizeof(char16_t) ? endswith16(s, suffix) : endswith(s, suffix); diff --git a/libc/testlib/formatbinaryasglyphs.c b/libc/testlib/formatbinaryasglyphs.c index ed9e448db..a7e9fba39 100644 --- a/libc/testlib/formatbinaryasglyphs.c +++ b/libc/testlib/formatbinaryasglyphs.c @@ -22,7 +22,8 @@ void testlib_formatbinaryasglyphs(const char16_t *want, const void *got, size_t n, char **out_v1, char **out_v2) { - if (n == -1ul) n = strlen16(want); + if (n == -1ul) + n = strlen16(want); *out_v1 = xasprintf("%`#.*hs", n, want); *out_v2 = xasprintf(" %`'#.*s", n, got); } diff --git a/libc/testlib/formatbinaryashex.c b/libc/testlib/formatbinaryashex.c index b7fba1ee6..339be9c44 100644 --- a/libc/testlib/formatbinaryashex.c +++ b/libc/testlib/formatbinaryashex.c @@ -26,7 +26,8 @@ void testlib_formatbinaryashex(const char *want, const void *got, size_t n, size_t i; uint8_t b; char *gothex; - if (n == -1ul) n = strlen(want) / 2; + if (n == -1ul) + n = strlen(want) / 2; gothex = xmalloc(n * 2 + 1); gothex[n * 2] = '\0'; for (i = 0; i < n; ++i) { diff --git a/libc/testlib/formatstr.c b/libc/testlib/formatstr.c index 401bac739..be7ffc145 100644 --- a/libc/testlib/formatstr.c +++ b/libc/testlib/formatstr.c @@ -60,12 +60,14 @@ static int AppendWide(wint_t x, int i, int j) { */ char *testlib_formatstr(size_t cw, const void *p, int n) { int i, j = 0; - if (!p) return "NULL"; + if (!p) + return "NULL"; i = atomic_fetch_add(&bufi, 1) % STRS; switch (cw) { case 1: { const char *s = p; - if (n < 0) n = s ? strlen(s) : 0; + if (n < 0) + n = s ? strlen(s) : 0; const char *se = s + n; APPEND('"'); while (s < se) { @@ -75,13 +77,15 @@ char *testlib_formatstr(size_t cw, const void *p, int n) { } case 2: { const char16_t *s = p; - if (n < 0) n = s ? strlen16(s) : 0; + if (n < 0) + n = s ? strlen16(s) : 0; const char16_t *se = s + n; APPEND('u'); APPEND('"'); while (s < se) { wint_t x = *s++ & 0xffff; - if (IsUtf16Cont(x)) continue; + if (IsUtf16Cont(x)) + continue; if (!IsUcs2(x) && s < se) { wint_t y = *s++ & 0xffff; x = MergeUtf16(x, y); @@ -92,7 +96,8 @@ char *testlib_formatstr(size_t cw, const void *p, int n) { } case 4: { const wchar_t *s = p; - if (n < 0) n = s ? wcslen(s) : 0; + if (n < 0) + n = s ? wcslen(s) : 0; const wchar_t *se = s + n; APPEND('L'); APPEND('"'); diff --git a/libc/testlib/hexequals.c b/libc/testlib/hexequals.c index 39c5b8d07..a4f8b5cf9 100644 --- a/libc/testlib/hexequals.c +++ b/libc/testlib/hexequals.c @@ -29,10 +29,13 @@ bool testlib_hexequals(const char *want, const void *got, size_t n) { size_t i; const unsigned char *p = (const unsigned char *)got; - if (!got) return false; + if (!got) + return false; for (i = 0; i < n; ++i) { - if (!want[i * 2]) break; - if (i == n) break; + if (!want[i * 2]) + break; + if (i == n) + break; if (p[i] != (kHexToInt[want[i * 2 + 0] & 255] * 16 + kHexToInt[want[i * 2 + 1] & 255])) { return false; diff --git a/libc/testlib/startswith.c b/libc/testlib/startswith.c index c1a5c179b..b24fdcdfd 100644 --- a/libc/testlib/startswith.c +++ b/libc/testlib/startswith.c @@ -20,8 +20,10 @@ #include "libc/testlib/testlib.h" bool testlib_startswith(size_t cw, const void *s, const void *prefix) { - if (s == prefix) return true; - if (!s || !prefix) return false; + if (s == prefix) + return true; + if (!s || !prefix) + return false; return cw == sizeof(wchar_t) ? wcsstartswith(s, prefix) : cw == sizeof(char16_t) ? startswith16(s, prefix) : startswith(s, prefix); diff --git a/libc/testlib/strcaseequals.c b/libc/testlib/strcaseequals.c index 1a120365b..e273e0e22 100644 --- a/libc/testlib/strcaseequals.c +++ b/libc/testlib/strcaseequals.c @@ -26,8 +26,10 @@ bool testlib_strcaseequals(size_t cw, const void *s1, const void *s2) { bool testlib_strncaseequals(size_t cw, const void *s1, const void *s2, size_t n) { - if (s1 == s2) return true; - if (!s1 || !s2) return false; + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; return (cw == sizeof(wchar_t) ? wcsncasecmp(s1, s2, n) : cw == sizeof(char16_t) ? strncasecmp16(s1, s2, n) : strncasecmp(s1, s2, n)) == 0; diff --git a/libc/testlib/strequals.c b/libc/testlib/strequals.c index 655750e75..ca8bb71af 100644 --- a/libc/testlib/strequals.c +++ b/libc/testlib/strequals.c @@ -25,8 +25,10 @@ bool testlib_strequals(size_t cw, const void *s1, const void *s2) { } bool testlib_strnequals(size_t cw, const void *s1, const void *s2, size_t n) { - if (s1 == s2) return true; - if (!s1 || !s2) return false; + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; return (cw == sizeof(wchar_t) ? wcsncmp(s1, s2, n) : cw == sizeof(char16_t) ? strncmp16(s1, s2, n) : strncmp(s1, s2, n)) == 0; diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index da218f162..e4704bdae 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -110,7 +110,8 @@ dontasan int main(int argc, char *argv[]) { errno = 0; STRACE(""); STRACE("# setting up once"); - if (!IsWindows()) sys_getpid(); + if (!IsWindows()) + sys_getpid(); testlib_clearxmmregisters(); if (_weaken(SetUpOnce)) { _weaken(SetUpOnce)(); diff --git a/libc/testlib/testrunner.c b/libc/testlib/testrunner.c index 6f432253b..f77738c05 100644 --- a/libc/testlib/testrunner.c +++ b/libc/testlib/testrunner.c @@ -53,8 +53,10 @@ void testlib_error_enter(const char *file, const char *func) { ftrace_enabled(-1); strace_enabled(-1); pthread_mutex_lock(&testlib_error_lock); - if (!IsWindows()) sys_getpid(); /* make strace easier to read */ - if (!IsWindows()) sys_getpid(); + if (!IsWindows()) + sys_getpid(); /* make strace easier to read */ + if (!IsWindows()) + sys_getpid(); if (g_testlib_shoulddebugbreak) { DebugBreak(); } @@ -106,18 +108,23 @@ void testlib_runtestcases(const testfn_t *start, const testfn_t *end, a->setup(fn); } } - if (_weaken(SetUp)) _weaken(SetUp)(); + if (_weaken(SetUp)) + _weaken(SetUp)(); errno = 0; - if (IsWindows()) SetLastError(0); - if (!IsWindows()) sys_getpid(); - if (warmup) warmup(); + if (IsWindows()) + SetLastError(0); + if (!IsWindows()) + sys_getpid(); + if (warmup) + warmup(); testlib_clearxmmregisters(); STRACE(""); STRACE("# running test %t on %s@%s", fn, user, host); (*fn)(); STRACE(""); STRACE("# tearing down %t", fn); - if (!IsWindows()) sys_getpid(); + if (!IsWindows()) + sys_getpid(); if (_weaken(TearDown)) { _weaken(TearDown)(); } diff --git a/libc/thread/__cxa_thread_atexit_impl.c b/libc/thread/__cxa_thread_atexit_impl.c index 151adf59a..3c0326cfb 100644 --- a/libc/thread/__cxa_thread_atexit_impl.c +++ b/libc/thread/__cxa_thread_atexit_impl.c @@ -38,7 +38,8 @@ void __cxa_thread_finalize(void) { int __cxa_thread_atexit_impl(void *fun, void *arg, void *dso_symbol) { struct Dtor *dtor; - if (!(dtor = malloc(sizeof(struct Dtor)))) return -1; + if (!(dtor = malloc(sizeof(struct Dtor)))) + return -1; dtor->fun = fun; dtor->arg = arg; dtor->next = __cxa_thread_atexit_list; diff --git a/libc/thread/mktls.c b/libc/thread/mktls.c index 35d83b64c..93919f051 100644 --- a/libc/thread/mktls.c +++ b/libc/thread/mktls.c @@ -92,7 +92,8 @@ static char *_mktls_above(struct CosmoTib **out_tib) { hiz = ROUNDUP(sizeof(*tib) + 2 * sizeof(void *), I(_tls_align)); siz = hiz + I(_tls_size); mem = memalign(TLS_ALIGNMENT, siz); - if (!mem) return 0; + if (!mem) + return 0; // poison memory between tdata and tbss if (IsAsan()) { diff --git a/libc/thread/pthread_atfork.c b/libc/thread/pthread_atfork.c index 49b579020..71adf7339 100644 --- a/libc/thread/pthread_atfork.c +++ b/libc/thread/pthread_atfork.c @@ -52,12 +52,15 @@ extern pthread_spinlock_t _pthread_lock_obj; static void _pthread_onfork(int i) { struct AtFork *a; unassert(0 <= i && i <= 2); - if (!i) pthread_spin_lock(&_atforks.lock); + if (!i) + pthread_spin_lock(&_atforks.lock); for (a = _atforks.list; a; a = a->p[!i]) { - if (a->f[i]) a->f[i](); + if (a->f[i]) + a->f[i](); _atforks.list = a; } - if (i) pthread_spin_unlock(&_atforks.lock); + if (i) + pthread_spin_unlock(&_atforks.lock); } void _pthread_onfork_prepare(void) { @@ -99,14 +102,16 @@ static struct AtFork *_pthread_atfork_alloc(void) { int _pthread_atfork(atfork_f prepare, atfork_f parent, atfork_f child) { int rc; struct AtFork *a; - if (!(a = _pthread_atfork_alloc())) return ENOMEM; + if (!(a = _pthread_atfork_alloc())) + return ENOMEM; a->f[0] = prepare; a->f[1] = parent; a->f[2] = child; pthread_spin_lock(&_atforks.lock); a->p[0] = 0; a->p[1] = _atforks.list; - if (_atforks.list) _atforks.list->p[0] = a; + if (_atforks.list) + _atforks.list->p[0] = a; _atforks.list = a; pthread_spin_unlock(&_atforks.lock); rc = 0; diff --git a/libc/thread/pthread_attr_getsigmask_np.c b/libc/thread/pthread_attr_getsigmask_np.c index 35b87fd55..d8fef2126 100644 --- a/libc/thread/pthread_attr_getsigmask_np.c +++ b/libc/thread/pthread_attr_getsigmask_np.c @@ -31,7 +31,9 @@ errno_t pthread_attr_getsigmask_np(const pthread_attr_t *attr, sigset_t *sigmask) { _Static_assert(sizeof(attr->__sigmask) == sizeof(*sigmask), ""); - if (!attr->__havesigmask) return PTHREAD_ATTR_NO_SIGMASK_NP; - if (sigmask) *sigmask = attr->__sigmask; + if (!attr->__havesigmask) + return PTHREAD_ATTR_NO_SIGMASK_NP; + if (sigmask) + *sigmask = attr->__sigmask; return 0; } diff --git a/libc/thread/pthread_attr_setguardsize.c b/libc/thread/pthread_attr_setguardsize.c index 00f0a50d6..2905a7605 100644 --- a/libc/thread/pthread_attr_setguardsize.c +++ b/libc/thread/pthread_attr_setguardsize.c @@ -36,7 +36,8 @@ * @raise EINVAL if `guardsize` is zero */ errno_t pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize) { - if (!guardsize) return EINVAL; + if (!guardsize) + return EINVAL; attr->__guardsize = guardsize; return 0; } diff --git a/libc/thread/pthread_attr_setstacksize.c b/libc/thread/pthread_attr_setstacksize.c index 4bc329cac..f2ccb0c99 100644 --- a/libc/thread/pthread_attr_setstacksize.c +++ b/libc/thread/pthread_attr_setstacksize.c @@ -27,7 +27,8 @@ * @raise EINVAL if `stacksize` is less than `PTHREAD_STACK_MIN` */ errno_t pthread_attr_setstacksize(pthread_attr_t *a, size_t stacksize) { - if (stacksize < PTHREAD_STACK_MIN) return EINVAL; + if (stacksize < PTHREAD_STACK_MIN) + return EINVAL; a->__stacksize = stacksize; return 0; } diff --git a/libc/thread/pthread_barrier_init.c b/libc/thread/pthread_barrier_init.c index 90ebf70cf..43770caa2 100644 --- a/libc/thread/pthread_barrier_init.c +++ b/libc/thread/pthread_barrier_init.c @@ -34,8 +34,10 @@ errno_t pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count) { nsync_counter c; - if (!count) return EINVAL; - if (!(c = nsync_counter_new(count))) return ENOMEM; + if (!count) + return EINVAL; + if (!(c = nsync_counter_new(count))) + return ENOMEM; *barrier = (pthread_barrier_t){._nsync = c}; return 0; } diff --git a/libc/thread/pthread_cancel.c b/libc/thread/pthread_cancel.c index 002d994bc..bc9dfd79e 100644 --- a/libc/thread/pthread_cancel.c +++ b/libc/thread/pthread_cancel.c @@ -66,10 +66,14 @@ static void _pthread_cancel_sig(int sig, siginfo_t *si, void *arg) { // check thread runtime state is initialized and cancelled struct PosixThread *pt; - if (!__tls_enabled) return; - if (!(pt = _pthread_self())) return; - if (pt->pt_flags & PT_NOCANCEL) return; - if (!atomic_load_explicit(&pt->pt_canceled, memory_order_acquire)) return; + if (!__tls_enabled) + return; + if (!(pt = _pthread_self())) + return; + if (pt->pt_flags & PT_NOCANCEL) + return; + if (!atomic_load_explicit(&pt->pt_canceled, memory_order_acquire)) + return; // in asynchronous mode the asynchronous signal calls exit if (pt->pt_flags & PT_ASYNC) { @@ -137,7 +141,8 @@ static errno_t _pthread_cancel_single(struct PosixThread *pt) { // send the cancelation signal errno_t err; err = pthread_kill((pthread_t)pt, SIGTHR); - if (err == ESRCH) err = 0; + if (err == ESRCH) + err = 0; return err; } @@ -369,9 +374,12 @@ errno_t pthread_cancel(pthread_t thread) { */ void pthread_testcancel(void) { struct PosixThread *pt; - if (!__tls_enabled) return; - if (!(pt = _pthread_self())) return; - if (pt->pt_flags & PT_NOCANCEL) return; + if (!__tls_enabled) + return; + if (!(pt = _pthread_self())) + return; + if (pt->pt_flags & PT_NOCANCEL) + return; if ((!(pt->pt_flags & PT_MASKED) || (pt->pt_flags & PT_ASYNC)) && atomic_load_explicit(&pt->pt_canceled, memory_order_acquire)) { pthread_exit(PTHREAD_CANCELED); @@ -396,10 +404,14 @@ void pthread_testcancel(void) { */ errno_t pthread_testcancel_np(void) { struct PosixThread *pt; - if (!__tls_enabled) return 0; - if (!(pt = _pthread_self())) return 0; - if (pt->pt_flags & PT_NOCANCEL) return 0; - if (!atomic_load_explicit(&pt->pt_canceled, memory_order_acquire)) return 0; + if (!__tls_enabled) + return 0; + if (!(pt = _pthread_self())) + return 0; + if (pt->pt_flags & PT_NOCANCEL) + return 0; + if (!atomic_load_explicit(&pt->pt_canceled, memory_order_acquire)) + return 0; if (!(pt->pt_flags & PT_MASKED) || (pt->pt_flags & PT_ASYNC)) { pthread_exit(PTHREAD_CANCELED); } else { diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index d259e8923..b59d74845 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -66,7 +66,8 @@ __static_yoink("_pthread_atfork"); void _pthread_free(struct PosixThread *pt, bool isfork) { unassert(dll_is_alone(&pt->list) && &pt->list != _pthread_list); - if (pt->pt_flags & PT_STATIC) return; + if (pt->pt_flags & PT_STATIC) + return; if (pt->pt_flags & PT_OWNSTACK) { unassert(!munmap(pt->pt_attr.__stackaddr, pt->pt_attr.__stacksize)); } @@ -94,7 +95,8 @@ StartOver: for (e = dll_last(_pthread_list); e; e = dll_prev(_pthread_list, e)) { pt = POSIXTHREAD_CONTAINER(e); status = atomic_load_explicit(&pt->pt_status, memory_order_acquire); - if (status != kPosixThreadZombie) break; + if (status != kPosixThreadZombie) + break; if (!atomic_load_explicit(&pt->tib->tib_tid, memory_order_acquire)) { dll_remove(&_pthread_list, e); _pthread_unlock(); @@ -316,8 +318,10 @@ static errno_t pthread_create_impl(pthread_t *thread, } static const char *DescribeHandle(char buf[12], errno_t err, pthread_t *th) { - if (err) return "n/a"; - if (!th) return "NULL"; + if (err) + return "n/a"; + if (!th) + return "NULL"; FormatInt32(buf, _pthread_tid((struct PosixThread *)*th)); return buf; } diff --git a/libc/thread/pthread_getname_np.c b/libc/thread/pthread_getname_np.c index eaa3d14bd..cca44d59d 100644 --- a/libc/thread/pthread_getname_np.c +++ b/libc/thread/pthread_getname_np.c @@ -36,7 +36,8 @@ static errno_t pthread_getname_impl(struct PosixThread *pt, char *name, int e, fd, rc, tid, len; tid = _pthread_tid(pt); - if (!size) return 0; + if (!size) + return 0; bzero(name, size); e = errno; diff --git a/libc/thread/pthread_key_create.c b/libc/thread/pthread_key_create.c index ae005b988..1f04da7a8 100644 --- a/libc/thread/pthread_key_create.c +++ b/libc/thread/pthread_key_create.c @@ -45,7 +45,8 @@ int pthread_key_create(pthread_key_t *key, pthread_key_dtor dtor) { int i; pthread_key_dtor expect; - if (!dtor) dtor = (pthread_key_dtor)-1; + if (!dtor) + dtor = (pthread_key_dtor)-1; for (i = 0; i < PTHREAD_KEYS_MAX; ++i) { if (!(expect = atomic_load_explicit(_pthread_key_dtor + i, memory_order_acquire)) && diff --git a/libc/thread/pthread_setcanceltype.c b/libc/thread/pthread_setcanceltype.c index 44c5d0a78..48290d5cf 100644 --- a/libc/thread/pthread_setcanceltype.c +++ b/libc/thread/pthread_setcanceltype.c @@ -27,10 +27,14 @@ #include "libc/thread/tls.h" static const char *DescribeCancelType(char buf[12], int err, int *t) { - if (err) return "n/a"; - if (!t) return "NULL"; - if (*t == PTHREAD_CANCEL_DEFERRED) return "PTHREAD_CANCEL_DEFERRED"; - if (*t == PTHREAD_CANCEL_ASYNCHRONOUS) return "PTHREAD_CANCEL_ASYNCHRONOUS"; + if (err) + return "n/a"; + if (!t) + return "NULL"; + if (*t == PTHREAD_CANCEL_DEFERRED) + return "PTHREAD_CANCEL_DEFERRED"; + if (*t == PTHREAD_CANCEL_ASYNCHRONOUS) + return "PTHREAD_CANCEL_ASYNCHRONOUS"; FormatInt32(buf, *t); return buf; } diff --git a/libc/thread/pthread_timedjoin_np.c b/libc/thread/pthread_timedjoin_np.c index f1a1e56a5..db5baae7a 100644 --- a/libc/thread/pthread_timedjoin_np.c +++ b/libc/thread/pthread_timedjoin_np.c @@ -33,8 +33,10 @@ static const char *DescribeReturnValue(char buf[30], int err, void **value) { char *p = buf; - if (!value) return "NULL"; - if (err) return "[n/a]"; + if (!value) + return "NULL"; + if (err) + return "[n/a]"; *p++ = '['; p = FormatHex64(p, (uintptr_t)*value, 1); *p++ = ']'; diff --git a/libc/thread/sem_destroy.c b/libc/thread/sem_destroy.c index 7c4b8e088..fb0e3c356 100644 --- a/libc/thread/sem_destroy.c +++ b/libc/thread/sem_destroy.c @@ -42,10 +42,12 @@ int sem_destroy(sem_t *sem) { int waiters; npassert(sem->sem_magic != SEM_MAGIC_NAMED); - if (sem->sem_magic != SEM_MAGIC_UNNAMED) return einval(); + if (sem->sem_magic != SEM_MAGIC_UNNAMED) + return einval(); waiters = atomic_load_explicit(&sem->sem_waiters, memory_order_relaxed); unassert(waiters >= 0); - if (waiters) return ebusy(); + if (waiters) + return ebusy(); atomic_store_explicit(&sem->sem_value, INT_MIN, memory_order_relaxed); return 0; } diff --git a/libc/thread/sem_init.c b/libc/thread/sem_init.c index 77c1dfac7..e86f18313 100644 --- a/libc/thread/sem_init.c +++ b/libc/thread/sem_init.c @@ -37,7 +37,8 @@ * @raise EINVAL if `value` exceeds `SEM_VALUE_MAX` */ int sem_init(sem_t *sem, int pshared, unsigned value) { - if (value > SEM_VALUE_MAX) return einval(); + if (value > SEM_VALUE_MAX) + return einval(); sem->sem_magic = SEM_MAGIC_UNNAMED; atomic_store_explicit(&sem->sem_value, value, memory_order_relaxed); sem->sem_pshared = !!pshared; diff --git a/libc/thread/sem_timedwait.c b/libc/thread/sem_timedwait.c index cde1ef2b0..2ffcbf5ee 100644 --- a/libc/thread/sem_timedwait.c +++ b/libc/thread/sem_timedwait.c @@ -35,7 +35,8 @@ static void sem_delay(int n) { volatile int i; - for (i = 0; i != 1 << n; i++) donothing; + for (i = 0; i != 1 << n; i++) + donothing; } static void sem_timedwait_cleanup(void *arg) { diff --git a/libc/thread/sem_trywait.c b/libc/thread/sem_trywait.c index 56584ac7c..96a07bf4d 100644 --- a/libc/thread/sem_trywait.c +++ b/libc/thread/sem_trywait.c @@ -47,8 +47,10 @@ int sem_trywait(sem_t *sem) { v = atomic_load_explicit(&sem->sem_value, memory_order_relaxed); do { unassert(v > INT_MIN); - if (!v) return eagain(); - if (v < 0) return einval(); + if (!v) + return eagain(); + if (v < 0) + return einval(); } while (!atomic_compare_exchange_weak_explicit( &sem->sem_value, &v, v - 1, memory_order_acquire, memory_order_relaxed)); return 0; diff --git a/libc/time/strptime.c b/libc/time/strptime.c index 63d9020ac..351c3d4d9 100644 --- a/libc/time/strptime.c +++ b/libc/time/strptime.c @@ -50,7 +50,8 @@ char *strptime(const char *s, const char *f, struct tm *tm) { continue; } f++; - if (*f == '+') f++; + if (*f == '+') + f++; if (isdigit(*f)) { char *new_f; w = strtoul(f, &new_f, 10); @@ -87,11 +88,13 @@ char *strptime(const char *s, const char *f, struct tm *tm) { goto symbolic_range; case 'c': s = strptime(s, "%a %b %e %T %Y", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'C': dest = ¢ury; - if (w < 0) w = 2; + if (w < 0) + w = 2; want_century |= 2; goto numeric_digits; case 'd': @@ -102,7 +105,8 @@ char *strptime(const char *s, const char *f, struct tm *tm) { goto numeric_range; case 'D': s = strptime(s, "%m/%d/%y", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'H': dest = &tm->tm_hour; @@ -154,11 +158,13 @@ char *strptime(const char *s, const char *f, struct tm *tm) { return 0; case 'r': s = strptime(s, "%I:%M:%S %p", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'R': s = strptime(s, "%H:%M", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'S': dest = &tm->tm_sec; @@ -167,7 +173,8 @@ char *strptime(const char *s, const char *f, struct tm *tm) { goto numeric_range; case 'T': s = strptime(s, "%H:%M:%S", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'U': case 'W': @@ -183,11 +190,13 @@ char *strptime(const char *s, const char *f, struct tm *tm) { goto numeric_range; case 'x': s = strptime(s, "%y-%m-%d", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'X': s = strptime(s, "%H:%M:%S", tm); - if (!s) return 0; + if (!s) + return 0; break; case 'y': dest = &relyear; @@ -196,22 +205,26 @@ char *strptime(const char *s, const char *f, struct tm *tm) { goto numeric_digits; case 'Y': dest = &tm->tm_year; - if (w < 0) w = 4; + if (w < 0) + w = 4; adj = 1900; want_century = 0; goto numeric_digits; case '%': - if (*s++ != '%') return 0; + if (*s++ != '%') + return 0; break; default: return 0; numeric_range: - if (!isdigit(*s)) return 0; + if (!isdigit(*s)) + return 0; *dest = 0; for (i = 1; i <= min + range && isdigit(*s); i *= 10) { *dest = *dest * 10 + *s++ - '0'; } - if (*dest - min >= (unsigned)range) return 0; + if (*dest - min >= (unsigned)range) + return 0; *dest -= adj; switch ((char *)dest - (char *)tm) { case offsetof(struct tm, tm_yday):; @@ -223,10 +236,12 @@ char *strptime(const char *s, const char *f, struct tm *tm) { s++; else if (*s == '-') neg = 1, s++; - if (!isdigit(*s)) return 0; + if (!isdigit(*s)) + return 0; for (*dest = i = 0; i < w && isdigit(*s); i++) *dest = *dest * 10 + *s++ - '0'; - if (neg) *dest = -*dest; + if (neg) + *dest = -*dest; *dest -= adj; goto update; symbolic_range: @@ -239,7 +254,8 @@ char *strptime(const char *s, const char *f, struct tm *tm) { break; } } - if (i == range) return 0; + if (i == range) + return 0; goto update; update: // FIXME diff --git a/libc/vga/readv-vga.c b/libc/vga/readv-vga.c index daf585641..3f746e729 100644 --- a/libc/vga/readv-vga.c +++ b/libc/vga/readv-vga.c @@ -47,11 +47,14 @@ ssize_t sys_readv_vga(struct Fd *fd, const struct iovec *iov, int iovlen) { void *input = iov[i].iov_base; size_t len = iov[i].iov_len; res = _TtyRead(&_vga_tty, input, len); - if (res < 0) break; + if (res < 0) + break; redd += res; - if (redd != len) return redd; + if (redd != len) + return redd; } - if (!redd) return res; + if (!redd) + return res; return redd; } diff --git a/libc/vga/tty.greg.c b/libc/vga/tty.greg.c index 85bef6bb1..4f84a240e 100644 --- a/libc/vga/tty.greg.c +++ b/libc/vga/tty.greg.c @@ -71,7 +71,8 @@ static void SetXsFb(struct Tty *tty, unsigned short xsfb) { static bool SetWcs(struct Tty *tty, unsigned init_flags) { #ifdef VGA_USE_WCS struct DirectMap dm; - if (!(init_flags & kTtyAllocWcs)) return false; + if (!(init_flags & kTtyAllocWcs)) + return false; dm = sys_mmap_metal(NULL, Yn(tty) * Xn(tty) * sizeof(wchar_t), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -200,11 +201,14 @@ void _StartTty(struct Tty *tty, unsigned char type, unsigned short yp, tty->yc = yc; tty->xc = xc; tty->fb = fb; - if (starty >= yn) starty = yn - 1; - if (startx >= xn) startx = xn - 1; + if (starty >= yn) + starty = yn - 1; + if (startx >= xn) + startx = xn - 1; tty->y = starty; tty->x = startx; - if ((init_flags & kTtyKlog) != 0) init_flags &= ~kTtyAllocWcs; + if ((init_flags & kTtyKlog) != 0) + init_flags &= ~kTtyAllocWcs; tty->xs = xs; TtySetType(tty, type, init_flags); if (SetWcs(tty, init_flags)) { @@ -212,7 +216,8 @@ void _StartTty(struct Tty *tty, unsigned char type, unsigned short yp, size_t n = (size_t)yn * xn, i; if (type == PC_VIDEO_TEXT) { struct VgaTextCharCell *ccs = fb; - for (i = 0; i < n; ++i) wcs[i] = bing(ccs[i].ch, 0); + for (i = 0; i < n; ++i) + wcs[i] = bing(ccs[i].ch, 0); } else wmemset(wcs, L' ', n); } @@ -334,9 +339,12 @@ static void TtySetCodepage(struct Tty *tty, char id) { static uint8_t TtyGetTextColor(TtyCanvasColor color) { uint8_t r = color.bgr.r, g = color.bgr.g, b = color.bgr.b; uint8_t hue = 0, max = MAX(MAX(r, g), b); - if (r > max / 2) hue |= 4; - if (g > max / 2) hue |= 2; - if (b > max / 2) hue |= 1; + if (r > max / 2) + hue |= 4; + if (g > max / 2) + hue |= 2; + if (b > max / 2) + hue |= 1; if (hue == 7 && max <= 0x55) hue = 8; else if (max > 0xaa) @@ -367,9 +375,11 @@ static uint8_t TtyGetTextAttr(struct Tty *tty) { * simplistic than what Linux does, but should be enough. */ attr &= ~0x80; - if ((tty->pr & kTtyBlink) != 0) attr |= 0x80; + if ((tty->pr & kTtyBlink) != 0) + attr |= 0x80; #endif - if ((tty->pr & kTtyBold) != 0) attr |= 0x08; + if ((tty->pr & kTtyBold) != 0) + attr |= 0x08; return attr; } @@ -381,7 +391,8 @@ static void TtyTextDrawChar(struct Tty *tty, size_t y, size_t x, wchar_t wc) { struct VgaTextCharCell *ccs = (struct VgaTextCharCell *)tty->canvas; size_t i = tty->y * Xn(tty) + tty->x; int c = unbing(wc); - if (c == -1) c = 0xFE; + if (c == -1) + c = 0xFE; ccs[i] = (struct VgaTextCharCell){c, attr}; } @@ -390,7 +401,8 @@ static void TtyTextEraseLineCells(struct Tty *tty, size_t dsty, size_t dstx, uint8_t attr = TtyGetTextAttr(tty); struct VgaTextCharCell *ccs = (struct VgaTextCharCell *)tty->canvas; size_t dst = dsty * Xn(tty) + dstx, i; - for (i = 0; i < n; ++i) ccs[dst + i] = (struct VgaTextCharCell){' ', attr}; + for (i = 0; i < n; ++i) + ccs[dst + i] = (struct VgaTextCharCell){' ', attr}; } void _TtyEraseLineCells(struct Tty *tty, size_t dsty, size_t dstx, size_t n) { @@ -423,7 +435,8 @@ void _TtyMoveLineCells(struct Tty *tty, size_t dsty, size_t dstx, size_t srcy, size_t xn = Xn(tty); size_t dst = dsty * xn + dstx, src = srcy * xn + srcx; tty->movelinecells(tty, dsty, dstx, srcy, srcx, n); - if (Wcs(tty)) wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n); + if (Wcs(tty)) + wmemmove(Wcs(tty) + dst, Wcs(tty) + src, n); } void _TtyMoveLines(struct Tty *tty, size_t dsty, size_t srcy, size_t n) { @@ -435,7 +448,8 @@ void _TtyMoveLines(struct Tty *tty, size_t dsty, size_t srcy, size_t n) { ++srcy; } } else if (dsty > srcy) { - while (n-- != 0) _TtyMoveLineCells(tty, dsty + n, 0, srcy + n, 0, xn); + while (n-- != 0) + _TtyMoveLineCells(tty, dsty + n, 0, srcy + n, 0, xn); } } @@ -520,12 +534,14 @@ static void TtyAdvance(struct Tty *tty) { } static void TtyWriteGlyph(struct Tty *tty, wint_t wc, int w) { - if (w < 1) wc = L' ', w = 1; + if (w < 1) + wc = L' ', w = 1; if ((tty->conf & kTtyRedzone) || tty->x + w > Xn(tty)) { TtyAdvance(tty); } tty->drawchar(tty, tty->y, tty->x, wc); - if (Wcs(tty)) Wcs(tty)[tty->y * Xn(tty) + tty->x] = wc; + if (Wcs(tty)) + Wcs(tty)[tty->y * Xn(tty) + tty->x] = wc; if ((tty->x += w) >= Xn(tty)) { tty->x = Xn(tty) - 1; tty->conf |= kTtyRedzone; @@ -556,14 +572,17 @@ static void TtyWriteTab(struct Tty *tty) { int TtyAtoi(const char *s, const char **e) { int i; - for (i = 0; isdigit(*s); ++s) i *= 10, i += *s - '0'; - if (e) *e = s; + for (i = 0; isdigit(*s); ++s) + i *= 10, i += *s - '0'; + if (e) + *e = s; return i; } static int TtyGetMoveParam(struct Tty *tty) { int x = TtyAtoi(tty->esc.s, NULL); - if (x < 1) x = 1; + if (x < 1) + x = 1; return x; } @@ -571,7 +590,8 @@ static void TtySetCursorPosition(struct Tty *tty) { int row, col; const char *s = tty->esc.s; row = max(1, TtyAtoi(s, &s)); - if (*s == ';') ++s; + if (*s == ';') + ++s; col = max(1, TtyAtoi(s, &s)); _TtySetY(tty, row - 1); _TtySetX(tty, col - 1); @@ -593,12 +613,14 @@ static void TtyMoveCursor(struct Tty *tty, int dy, int dx) { static void TtyScrollUp(struct Tty *tty) { int n = TtyGetMoveParam(tty); - while (n--) TtyScroll(tty); + while (n--) + TtyScroll(tty); } static void TtyScrollDown(struct Tty *tty) { int n = TtyGetMoveParam(tty); - while (n--) TtyReverse(tty); + while (n--) + TtyReverse(tty); } static void TtySetCursorStatus(struct Tty *tty, bool status) { @@ -1110,8 +1132,10 @@ static void TtyCsi(struct Tty *tty) { static void TtyScreenAlignmentDisplay(struct Tty *tty) { size_t yn = Yn(tty), xn = Xn(tty), y, x; for (y = 0; y < yn; ++y) - for (x = 0; x < xn; ++x) tty->drawchar(tty, y, x, 'E'); - if (Wcs(tty)) wmemset(Wcs(tty), L'E', yn * xn); + for (x = 0; x < xn; ++x) + tty->drawchar(tty, y, x, 'E'); + if (Wcs(tty)) + wmemset(Wcs(tty), L'E', yn * xn); } static void TtyEscHash(struct Tty *tty) { @@ -1212,7 +1236,8 @@ static void TtyUpdate(struct Tty *tty) { if (tty->type == PC_VIDEO_TEXT) { unsigned char start = tty->yc - 2, end = tty->yc - 1; unsigned short pos = tty->y * Xn(tty) + tty->x; - if ((tty->conf & kTtyNocursor)) start |= 1 << 5; + if ((tty->conf & kTtyNocursor)) + start |= 1 << 5; outb(CRTPORT, 0x0A); outb(CRTPORT + 1, start); outb(CRTPORT, 0x0B); @@ -1251,7 +1276,8 @@ ssize_t _TtyWrite(struct Tty *tty, const void *data, size_t n) { case kTtyUtf8: if (ThomPikeCont(p[i])) { tty->u8 = ThomPikeMerge(tty->u8, p[i]); - if (--tty->n8) break; + if (--tty->n8) + break; } wc = tty->u8; if ((0x00 <= wc && wc <= 0x1F) || (0x7F <= wc && wc <= 0x9F)) { diff --git a/libc/vga/vga-init.greg.c b/libc/vga/vga-init.greg.c index f147334d5..2c055e630 100644 --- a/libc/vga/vga-init.greg.c +++ b/libc/vga/vga-init.greg.c @@ -91,7 +91,8 @@ void uvprintf(const char *fmt, va_list v) { char *buf = alloca(size); CheckLargeStackAllocation(buf, size); size_t count = kvsnprintf(buf, size, fmt, v); - if (count >= size) count = size - 1; + if (count >= size) + count = size - 1; _TtyWrite(&_vga_tty, buf, count); _klog_serial(buf, count); } diff --git a/libc/vga/writev-vga.c b/libc/vga/writev-vga.c index 2cbbda83b..1c6d35e1e 100644 --- a/libc/vga/writev-vga.c +++ b/libc/vga/writev-vga.c @@ -39,11 +39,14 @@ ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) { void *output = iov[i].iov_base; size_t len = iov[i].iov_len; res = _TtyWrite(&_vga_tty, output, len); - if (res < 0) break; + if (res < 0) + break; wrote += res; - if (res != len) return wrote; + if (res != len) + return wrote; } - if (!wrote) return res; + if (!wrote) + return res; return wrote; } diff --git a/libc/x/unbingbuf.c b/libc/x/unbingbuf.c index d10b7f56c..e08874679 100644 --- a/libc/x/unbingbuf.c +++ b/libc/x/unbingbuf.c @@ -45,6 +45,7 @@ void *unbingbuf(void *buf, size_t size, const char16_t *glyphs, int fill) { *p = (b = unbing(*glyphs)) & 0xff; /* DCHECK_NE(-1, b, "%`'hc ∉ IBMCP437\n", *glyphs); */ } - if (fill != -1) memset(p, fill, pe - p); + if (fill != -1) + memset(p, fill, pe - p); return buf; } diff --git a/libc/x/utf16to32.c b/libc/x/utf16to32.c index d6ea02664..23784b367 100644 --- a/libc/x/utf16to32.c +++ b/libc/x/utf16to32.c @@ -32,8 +32,10 @@ wchar_t *utf16to32(const char16_t *p, size_t n, size_t *z) { wint_t x, y; wchar_t *r, *q; const char16_t *e; - if (z) *z = 0; - if (n == -1) n = p ? strlen16(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen16(p) : 0; if ((q = r = malloc(n * 4 + 8 + 1))) { for (e = p + n; p < e;) { x = *p++ & 0xffff; @@ -47,9 +49,11 @@ wchar_t *utf16to32(const char16_t *p, size_t n, size_t *z) { } *q++ = x; } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, (q - r) * sizeof(*r)))) r = q; + if ((q = realloc(r, (q - r) * sizeof(*r)))) + r = q; } return r; } diff --git a/libc/x/utf16to8.c b/libc/x/utf16to8.c index ba29cd1bd..219c2e2a9 100644 --- a/libc/x/utf16to8.c +++ b/libc/x/utf16to8.c @@ -46,8 +46,10 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) { wint_t x, y; const char16_t *e; int16_t v1[8], v2[8], v3[8], vz[8]; - if (z) *z = 0; - if (n == -1) n = p ? strlen16(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen16(p) : 0; if ((q = r = malloc(n * 4 + 8 + 1))) { for (e = p + n; p < e;) { if (p + 8 < e) { /* 17x ascii */ @@ -57,7 +59,8 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) { pcmpgtw(v2, v1, vz); pcmpgtw(v3, v1, kDel16); pandn((void *)v2, (void *)v3, (void *)v2); - if (pmovmskb((void *)v2) != 0xFFFF) break; + if (pmovmskb((void *)v2) != 0xFFFF) + break; packsswb((void *)v1, v1, v1); memcpy(q, v1, 8); p += 8; @@ -82,9 +85,11 @@ char *utf16to8(const char16_t *p, size_t n, size_t *z) { q += 1; } } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, (q - r) * 1))) r = q; + if ((q = realloc(r, (q - r) * 1))) + r = q; } return r; } diff --git a/libc/x/utf32to8.c b/libc/x/utf32to8.c index 9aabca571..d3089bff0 100644 --- a/libc/x/utf32to8.c +++ b/libc/x/utf32to8.c @@ -32,8 +32,10 @@ char *utf32to8(const wchar_t *p, size_t n, size_t *z) { wint_t x; uint64_t w; char *r, *q; - if (z) *z = 0; - if (n == -1) n = p ? wcslen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? wcslen(p) : 0; if ((q = r = malloc(n * 6 + 1))) { for (i = 0; i < n; ++i) { x = p[i]; @@ -42,9 +44,11 @@ char *utf32to8(const wchar_t *p, size_t n, size_t *z) { *q++ = w; } while ((w >>= 8)); } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; } diff --git a/libc/x/utf8to16.c b/libc/x/utf8to16.c index 8626787a5..aea0aee62 100644 --- a/libc/x/utf8to16.c +++ b/libc/x/utf8to16.c @@ -34,8 +34,10 @@ char16_t *utf8to16(const char *p, size_t n, size_t *z) { wint_t x, a, b; char16_t *r, *q; unsigned m, j, w; - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc((n + 16) * sizeof(char16_t) * 2 + sizeof(char16_t)))) { for (i = 0; i < n;) { #if defined(__SSE2__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) && \ @@ -66,7 +68,8 @@ char16_t *utf8to16(const char *p, size_t n, size_t *z) { if (i + m <= n) { for (j = 0;;) { b = p[i + j] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++j == m) { x = a; @@ -78,11 +81,14 @@ char16_t *utf8to16(const char *p, size_t n, size_t *z) { } w = EncodeUtf16(x); *q++ = w; - if ((w >>= 16)) *q++ = w; + if ((w >>= 16)) + *q++ = w; } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, (q - r) * sizeof(char16_t)))) r = q; + if ((q = realloc(r, (q - r) * sizeof(char16_t)))) + r = q; } return r; } diff --git a/libc/x/utf8to32.c b/libc/x/utf8to32.c index 0d8687f72..f1a8568cc 100644 --- a/libc/x/utf8to32.c +++ b/libc/x/utf8to32.c @@ -42,8 +42,10 @@ wchar_t *utf8to32(const char *p, size_t n, size_t *z) { wint_t x, a, b; wchar_t *r, *q; uint8_t v1[16], v2[16], v3[16], v4[16], vz[16]; - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc(n * sizeof(wchar_t) + sizeof(wchar_t)))) { for (i = 0; i < n;) { if (!((uintptr_t)(p + i) & 15) && i + 16 < n) { @@ -52,7 +54,8 @@ wchar_t *utf8to32(const char *p, size_t n, size_t *z) { do { memcpy(v1, p + i, 16); pcmpgtb((int8_t *)v2, (int8_t *)v1, (int8_t *)vz); - if (pmovmskb(v2) != 0xFFFF) break; + if (pmovmskb(v2) != 0xFFFF) + break; punpcklbw(v3, v1, vz); punpckhbw(v1, v1, vz); punpcklwd((void *)v4, (void *)v3, (void *)vz); @@ -74,7 +77,8 @@ wchar_t *utf8to32(const char *p, size_t n, size_t *z) { if (i + m <= n) { for (j = 0;;) { b = p[i + j] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++j == m) { x = a; @@ -86,9 +90,11 @@ wchar_t *utf8to32(const char *p, size_t n, size_t *z) { } *q++ = x; } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, (q - r) * sizeof(wchar_t)))) r = q; + if ((q = realloc(r, (q - r) * sizeof(wchar_t)))) + r = q; } return r; } diff --git a/libc/x/xbarf.c b/libc/x/xbarf.c index c3a44da4c..38d87f005 100644 --- a/libc/x/xbarf.c +++ b/libc/x/xbarf.c @@ -37,7 +37,8 @@ int xbarf(const char *path, const void *data, size_t size) { size_t i, wrote; res = 0; p = data; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644)) != -1) { if (ftruncate(fd, size) != -1) { if (size > 2 * 1024 * 1024) { diff --git a/libc/x/xcalloc.c b/libc/x/xcalloc.c index 97c6a6599..31e1367fe 100644 --- a/libc/x/xcalloc.c +++ b/libc/x/xcalloc.c @@ -24,6 +24,7 @@ */ void *xcalloc(size_t count, size_t size) { void *res = calloc(count, size); - if (!res) xdie(); + if (!res) + xdie(); return res; } diff --git a/libc/x/xdie.c b/libc/x/xdie.c index f737ec5e8..9e6a9a3ba 100644 --- a/libc/x/xdie.c +++ b/libc/x/xdie.c @@ -22,6 +22,7 @@ #include "libc/x/x.h" void xdie(void) { - if (_weaken(__die)) __die(); + if (_weaken(__die)) + __die(); abort(); } diff --git a/libc/x/xfixpath.c b/libc/x/xfixpath.c index 25b15ed6a..da2a86584 100644 --- a/libc/x/xfixpath.c +++ b/libc/x/xfixpath.c @@ -36,7 +36,8 @@ void xfixpath(void) { // turn backslash into slash for (p = path; *p; ++p) { - if (*p == '\\') *p = '/'; + if (*p == '\\') + *p = '/'; } // turn c:/... into /c/... @@ -54,7 +55,8 @@ void xfixpath(void) { // turn semicolon into colon for (p = path; *p; ++p) { - if (*p == ';') *p = ':'; + if (*p == ';') + *p = ':'; } setenv("PATH", path, true); diff --git a/libc/x/xload.c b/libc/x/xload.c index 2b0f8b84a..334b73c95 100644 --- a/libc/x/xload.c +++ b/libc/x/xload.c @@ -42,9 +42,12 @@ */ void *xload(_Atomic(void *) *a, const void *p, size_t n, size_t m) { void *r, *z; - if ((r = atomic_load_explicit(a, memory_order_acquire))) return r; - if (!(r = malloc(m))) return 0; - if (__inflate(r, m, p, n)) return 0; + if ((r = atomic_load_explicit(a, memory_order_acquire))) + return r; + if (!(r = malloc(m))) + return 0; + if (__inflate(r, m, p, n)) + return 0; z = 0; if (!atomic_compare_exchange_strong_explicit(a, &z, r, memory_order_release, memory_order_relaxed)) { diff --git a/libc/x/xmalloc.c b/libc/x/xmalloc.c index cf55e4c5b..d4baed8e0 100644 --- a/libc/x/xmalloc.c +++ b/libc/x/xmalloc.c @@ -24,6 +24,7 @@ */ void *xmalloc(size_t bytes) { void *res = malloc(bytes); - if (!res) xdie(); + if (!res) + xdie(); return res; } diff --git a/libc/x/xmemalign.c b/libc/x/xmemalign.c index 9a27fae96..2bf2194cb 100644 --- a/libc/x/xmemalign.c +++ b/libc/x/xmemalign.c @@ -24,6 +24,7 @@ */ void *xmemalign(size_t alignment, size_t bytes) { void *res = memalign(alignment, bytes); - if (!res) xdie(); + if (!res) + xdie(); return res; } diff --git a/libc/x/xmemalignzero.c b/libc/x/xmemalignzero.c index ef7b3f224..2e6b38ce4 100644 --- a/libc/x/xmemalignzero.c +++ b/libc/x/xmemalignzero.c @@ -26,7 +26,8 @@ void *xmemalignzero(size_t alignment, size_t bytes) { void *p; p = memalign(alignment, bytes); - if (!p) xdie(); + if (!p) + xdie(); bzero(p, bytes); return p; } diff --git a/libc/x/xrealloc.c b/libc/x/xrealloc.c index 877d4df5e..e6f029594 100644 --- a/libc/x/xrealloc.c +++ b/libc/x/xrealloc.c @@ -37,6 +37,7 @@ void *xrealloc(void *p, size_t n) { void *q; q = realloc(p, n); - if (!q && !(p && !n)) xdie(); + if (!q && !(p && !n)) + xdie(); return q; } diff --git a/libc/x/xstrdup.c b/libc/x/xstrdup.c index d51468ca3..5564ddd68 100644 --- a/libc/x/xstrdup.c +++ b/libc/x/xstrdup.c @@ -27,6 +27,7 @@ char *xstrdup(const char *s) { size_t len = strlen(s); char *s2 = malloc(len + 1); - if (UNLIKELY(!s2)) xdie(); + if (UNLIKELY(!s2)) + xdie(); return memcpy(s2, s, len + 1); } diff --git a/libc/x/xstrmul.c b/libc/x/xstrmul.c index 50d87df95..7167c1e83 100644 --- a/libc/x/xstrmul.c +++ b/libc/x/xstrmul.c @@ -28,7 +28,8 @@ char *xstrmul(const char *s, size_t n) { size_t i, m; m = strlen(s); p = xcalloc(n + 1, m); - for (i = 0; i < n; ++i) memcpy(p + i * m, s, m); + for (i = 0; i < n; ++i) + memcpy(p + i * m, s, m); p[i * m] = '\0'; return p; } diff --git a/libc/x/xstrndup.c b/libc/x/xstrndup.c index 8f8ba5ab2..2def02294 100644 --- a/libc/x/xstrndup.c +++ b/libc/x/xstrndup.c @@ -29,6 +29,7 @@ */ char *xstrndup(const char *s, size_t n) { void *res = strndup(s, n); - if (!res) xdie(); + if (!res) + xdie(); return res; } diff --git a/libc/x/xvalloc.c b/libc/x/xvalloc.c index 8470a58f0..f84c64366 100644 --- a/libc/x/xvalloc.c +++ b/libc/x/xvalloc.c @@ -24,6 +24,7 @@ */ void *xvalloc(size_t size) { void *res = valloc(size); - if (!res) xdie(); + if (!res) + xdie(); return res; } diff --git a/libc/x/xvasprintf.c b/libc/x/xvasprintf.c index a24e31e42..786e0a676 100644 --- a/libc/x/xvasprintf.c +++ b/libc/x/xvasprintf.c @@ -28,6 +28,7 @@ */ char *xvasprintf(const char *fmt, va_list va) { char *buf; - if (vasprintf(&buf, fmt, va) == -1) xdie(); + if (vasprintf(&buf, fmt, va) == -1) + xdie(); return buf; } diff --git a/net/http/base32.c b/net/http/base32.c index 6e7963d38..c9a3af12f 100644 --- a/net/http/base32.c +++ b/net/http/base32.c @@ -25,7 +25,8 @@ const char base32def[] = "0123456789abcdefghjkmnpqrstvwxyz"; int tobits(int b) { int bits = 0; - while (b && (b >>= 1)) bits++; + while (b && (b >>= 1)) + bits++; return bits; } @@ -48,7 +49,8 @@ char *EncodeBase32(const char *s, size_t sl, const char *a, size_t al, size_t *ol) { size_t count = 0; char *r = NULL; - if (sl == -1) sl = s ? strlen(s) : 0; + if (sl == -1) + sl = s ? strlen(s) : 0; if (al == 0) { a = base32def; al = sizeof(base32def) / sizeof(a[0]); @@ -78,7 +80,8 @@ char *EncodeBase32(const char *s, size_t sl, const char *a, size_t al, } r[count] = '\0'; } - if (ol) *ol = r ? count : 0; + if (ol) + *ol = r ? count : 0; return r; } @@ -119,7 +122,8 @@ char *DecodeBase32(const char *s, size_t sl, const char *a, size_t al, size_t *ol) { size_t count = 0; char *r = NULL; - if (sl == -1) sl = s ? strlen(s) : 0; + if (sl == -1) + sl = s ? strlen(s) : 0; if (al == 0) { a = base32def; al = sizeof(base32def) / sizeof(a[0]); @@ -138,12 +142,15 @@ char *DecodeBase32(const char *s, size_t sl, const char *a, size_t al, map = kBase32cust; memset(map, -1, 256); // populate the map based on alphabet - for (int i = 0; i < al; i++) map[a[i] & 0xff] = i; + for (int i = 0; i < al; i++) + map[a[i] & 0xff] = i; } while (count < n && *s) { signed char m = map[*s++ & 0xff]; - if (m == -2) continue; - if (m == -1) break; + if (m == -2) + continue; + if (m == -1) + break; buffer <<= bl; buffer |= m; bitsLeft += bl; @@ -154,6 +161,7 @@ char *DecodeBase32(const char *s, size_t sl, const char *a, size_t al, } r[count] = '\0'; } - if (ol) *ol = r ? count : 0; + if (ol) + *ol = r ? count : 0; return r; } diff --git a/net/http/categorizeip.c b/net/http/categorizeip.c index b144346f2..d42235015 100644 --- a/net/http/categorizeip.c +++ b/net/http/categorizeip.c @@ -26,25 +26,44 @@ */ int CategorizeIp(uint32_t x) { int a; - if (IsLoopbackIp(x)) return kIpLoopback; - if (IsPrivateIp(x)) return kIpPrivate; - if (IsMulticastIp(x)) return kIpMulticast; - if (IsAnonymousIp(x)) return kIpAnonymous; /* order matters */ - if (IsTestnetIp(x)) return kIpTestnet; /* order matters */ - if (IsAfrinicIp(x)) return kIpAfrinic; - if (IsLacnicIp(x)) return kIpLacnic; - if (IsApnicIp(x)) return kIpApnic; - if (IsArinIp(x)) return kIpArin; - if (IsRipeIp(x)) return kIpRipe; - if (IsDodIp(x)) return kIpDod; + if (IsLoopbackIp(x)) + return kIpLoopback; + if (IsPrivateIp(x)) + return kIpPrivate; + if (IsMulticastIp(x)) + return kIpMulticast; + if (IsAnonymousIp(x)) + return kIpAnonymous; /* order matters */ + if (IsTestnetIp(x)) + return kIpTestnet; /* order matters */ + if (IsAfrinicIp(x)) + return kIpAfrinic; + if (IsLacnicIp(x)) + return kIpLacnic; + if (IsApnicIp(x)) + return kIpApnic; + if (IsArinIp(x)) + return kIpArin; + if (IsRipeIp(x)) + return kIpRipe; + if (IsDodIp(x)) + return kIpDod; a = (x & 0xff000000) >> 24; - if (a == 12) return kIpAtt; - if (a == 17) return kIpApple; - if (a == 19) return kIpFord; - if (a == 38) return kIpCogent; - if (a == 48) return kIpPrudential; - if (a == 56) return kIpUsps; - if (a == 73) return kIpComcast; - if (a >= 240) return kIpFuture; + if (a == 12) + return kIpAtt; + if (a == 17) + return kIpApple; + if (a == 19) + return kIpFord; + if (a == 38) + return kIpCogent; + if (a == 48) + return kIpPrudential; + if (a == 56) + return kIpUsps; + if (a == 73) + return kIpComcast; + if (a >= 240) + return kIpFuture; return kIpUnknown; } diff --git a/net/http/decodebase64.c b/net/http/decodebase64.c index c775f5924..a9b19288a 100644 --- a/net/http/decodebase64.c +++ b/net/http/decodebase64.c @@ -58,22 +58,27 @@ char *DecodeBase64(const char *data, size_t size, size_t *out_size) { char *r, *q; int a, b, c, d, w; const char *p, *pe; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; if ((r = malloc(ROUNDUP(size, 4) / 4 * 3 + 1))) { q = r; p = data; pe = p + size; for (;;) { do { - if (p == pe) goto Done; + if (p == pe) + goto Done; a = kBase64[*p++ & 0xff]; } while (a == -1); - if (a == -2) continue; + if (a == -2) + continue; do { - if (p == pe) goto Done; + if (p == pe) + goto Done; b = kBase64[*p++ & 0xff]; } while (b == -1); - if (b == -2) continue; + if (b == -2) + continue; do { c = p < pe ? kBase64[*p++ & 0xff] : -2; } while (c == -1); @@ -81,16 +86,21 @@ char *DecodeBase64(const char *data, size_t size, size_t *out_size) { d = p < pe ? kBase64[*p++ & 0xff] : -2; } while (d == -1); w = a << 18 | b << 12; - if (c != -2) w |= c << 6; - if (d != -2) w |= d; + if (c != -2) + w |= c << 6; + if (d != -2) + w |= d; *q++ = (w & 0xFF0000) >> 020; - if (c != -2) *q++ = (w & 0x00FF00) >> 010; - if (d != -2) *q++ = (w & 0x0000FF) >> 000; + if (c != -2) + *q++ = (w & 0x00FF00) >> 010; + if (d != -2) + *q++ = (w & 0x0000FF) >> 000; } Done: n = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } else { n = 0; } diff --git a/net/http/decodelatin1.c b/net/http/decodelatin1.c index 7bc8daecd..4799d8a9d 100644 --- a/net/http/decodelatin1.c +++ b/net/http/decodelatin1.c @@ -35,15 +35,18 @@ char *DecodeLatin1(const char *p, size_t n, size_t *z) { size_t i; char *r, *q; int8_t v1[16], v2[16], vz[16]; - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc(n * 2 + 1))) { for (i = 0; i < n;) { bzero(vz, 16); /* 3x speedup for ASCII */ while (i + 16 < n) { memcpy(v1, p + i, 16); pcmpgtb(v2, v1, vz); - if (pmovmskb((void *)v2) != 0xFFFF) break; + if (pmovmskb((void *)v2) != 0xFFFF) + break; memcpy(q, v1, 16); q += 16; i += 16; @@ -56,9 +59,11 @@ char *DecodeLatin1(const char *p, size_t n, size_t *z) { *q++ = 0200 | (c & 077); } } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; } diff --git a/net/http/encodebase64.c b/net/http/encodebase64.c index f8acf2d71..aac16e72b 100644 --- a/net/http/encodebase64.c +++ b/net/http/encodebase64.c @@ -35,14 +35,18 @@ char *EncodeBase64(const char *data, size_t size, size_t *out_size) { unsigned w; char *r, *q; const unsigned char *p, *pe; - if (size == -1) size = data ? strlen(data) : 0; - if ((n = size) % 3) n += 3 - size % 3; + if (size == -1) + size = data ? strlen(data) : 0; + if ((n = size) % 3) + n += 3 - size % 3; n /= 3, n *= 4; if ((r = malloc(n + 1))) { for (q = r, p = (void *)data, pe = p + size; p < pe; p += 3) { w = p[0] << 020; - if (p + 1 < pe) w |= p[1] << 010; - if (p + 2 < pe) w |= p[2] << 000; + if (p + 1 < pe) + w |= p[1] << 010; + if (p + 2 < pe) + w |= p[2] << 000; *q++ = CHARS[(w >> 18) & 077]; *q++ = CHARS[(w >> 12) & 077]; *q++ = p + 1 < pe ? CHARS[(w >> 6) & 077] : '='; diff --git a/net/http/encodehttpheadervalue.c b/net/http/encodehttpheadervalue.c index 37c5881ef..90f334926 100644 --- a/net/http/encodehttpheadervalue.c +++ b/net/http/encodehttpheadervalue.c @@ -45,7 +45,8 @@ char *EncodeHttpHeaderValue(const char *data, size_t size, size_t *out_size) { size_t n; char *r, *q; const char *p, *e; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; if ((r = malloc(size + 1))) { t = 0; q = r; @@ -77,10 +78,12 @@ char *EncodeHttpHeaderValue(const char *data, size_t size, size_t *out_size) { return NULL; } } - while (q > r && (q[-1] == ' ' || q[-1] == '\t')) --q; + while (q > r && (q[-1] == ' ' || q[-1] == '\t')) + --q; n = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } else { n = 0; } diff --git a/net/http/encodelatin1.c b/net/http/encodelatin1.c index 4222de6b6..4d6798ec7 100644 --- a/net/http/encodelatin1.c +++ b/net/http/encodelatin1.c @@ -41,11 +41,15 @@ char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) { char t[256]; char *r, *q; bzero(t, sizeof(t)); - if (f & kControlC0) memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1; - if (f & kControlC1) memset(t + 0x80, 1, 0xA0 - 0x80); + if (f & kControlC0) + memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1; + if (f & kControlC1) + memset(t + 0x80, 1, 0xA0 - 0x80); t['\t'] = t['\r'] = t['\n'] = t['\v'] = !!(f & kControlWs); - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc(n + 1))) { for (i = 0; i < n;) { c = p[i++] & 0xff; @@ -61,9 +65,11 @@ char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) { } *q++ = c; } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; Invalid: diff --git a/net/http/encodeurl.c b/net/http/encodeurl.c index 06ccb93e4..acb7e09d3 100644 --- a/net/http/encodeurl.c +++ b/net/http/encodeurl.c @@ -55,8 +55,10 @@ static size_t DimensionUrl(struct Url *h) { static bool NeedsSquareBrackets(struct Url *h) { int c; size_t i; - if (!memchr(h->host.p, ':', h->host.n)) return false; - if (h->pass.p) return true; + if (!memchr(h->host.p, ':', h->host.n)) + return false; + if (h->pass.p) + return true; if (h->host.n >= 4 && h->host.p[0] == 'v' && h->host.p[2] == '.' && kHexToInt[h->host.p[1] & 0xFF] != -1) { for (i = 3; i < h->host.n; ++i) { @@ -122,7 +124,8 @@ char *EncodeUrl(struct Url *h, size_t *z) { if (h->params.p) { *p++ = '?'; for (i = 0; i < h->params.n; ++i) { - if (i) *p++ = '&'; + if (i) + *p++ = '&'; p = EscapeUrlView(p, &h->params.p[i].key, kEscapeParam); if (h->params.p[i].val.p) { *p++ = '='; @@ -136,10 +139,12 @@ char *EncodeUrl(struct Url *h, size_t *z) { } n = p - m; *p++ = '\0'; - if ((p = realloc(m, p - m))) m = p; + if ((p = realloc(m, p - m))) + m = p; } else { n = 0; } - if (z) *z = n; + if (z) + *z = n; return m; } diff --git a/net/http/escapehtml.c b/net/http/escapehtml.c index d198e500b..a90acb995 100644 --- a/net/http/escapehtml.c +++ b/net/http/escapehtml.c @@ -33,8 +33,10 @@ char *EscapeHtml(const char *p, size_t n, size_t *z) { int c; size_t i; char *q, *r; - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc(n * 6 + 1))) { for (i = 0; i < n; ++i) { switch ((c = p[i])) { @@ -82,9 +84,11 @@ char *EscapeHtml(const char *p, size_t n, size_t *z) { break; } } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; } diff --git a/net/http/escapejsstringliteral.c b/net/http/escapejsstringliteral.c index d768e2f42..ad7d4f558 100644 --- a/net/http/escapejsstringliteral.c +++ b/net/http/escapejsstringliteral.c @@ -64,8 +64,10 @@ char *EscapeJsStringLiteral(char **r, size_t *y, const char *p, size_t n, uint64_t w; size_t i, j, m; wint_t x, a, b; - if (z) *z = 0; // TODO(jart): why is this here? - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; // TODO(jart): why is this here? + if (n == -1) + n = p ? strlen(p) : 0; q = *r; i = n * 8 + 6 + 1; // only need *6 but *8 is faster if (i > *y) { @@ -83,7 +85,8 @@ char *EscapeJsStringLiteral(char **r, size_t *y, const char *p, size_t n, if (i + m <= n) { for (j = 0;;) { b = p[i + j] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++j == m) { x = a; @@ -148,7 +151,8 @@ char *EscapeJsStringLiteral(char **r, size_t *y, const char *p, size_t n, __builtin_unreachable(); } } - if (z) *z = q - *r; + if (z) + *z = q - *r; *q++ = '\0'; } return *r; diff --git a/net/http/escapeurl.c b/net/http/escapeurl.c index f0888085b..8833b08c2 100644 --- a/net/http/escapeurl.c +++ b/net/http/escapeurl.c @@ -42,14 +42,18 @@ char *EscapeUrl(const char *p, size_t n, size_t *z, const char T[256]) { char *r, *q; struct UrlView v; - if (n == -1) n = p ? strlen(p) : 0; - if (z) *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; + if (z) + *z = 0; if ((q = r = malloc(n * 6 + 1))) { v.p = (char *)p, v.n = n; q = EscapeUrlView(r, &v, T); - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; } diff --git a/net/http/findcontenttype.c b/net/http/findcontenttype.c index 8437a4b3f..fc4f826f7 100644 --- a/net/http/findcontenttype.c +++ b/net/http/findcontenttype.c @@ -138,7 +138,8 @@ static const char *BisectContentType(uint64_t ext) { const char *FindContentType(const char *p, size_t n) { int c; uint64_t w; - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; for (w = 0; n--;) { c = p[n] & 255; if (c == '.') { diff --git a/net/http/hascontrolcodes.c b/net/http/hascontrolcodes.c index 9bde21547..8e3741493 100644 --- a/net/http/hascontrolcodes.c +++ b/net/http/hascontrolcodes.c @@ -35,10 +35,13 @@ ssize_t HasControlCodes(const char *p, size_t n, int f) { wint_t x, a, b; size_t i, j, m, g; bzero(t, sizeof(t)); - if (f & kControlC0) memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1; - if (f & kControlC1) memset(t + 0x80, 1, 0xA0 - 0x80); + if (f & kControlC0) + memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1; + if (f & kControlC1) + memset(t + 0x80, 1, 0xA0 - 0x80); t['\t'] = t['\r'] = t['\n'] = t['\v'] = !!(f & kControlWs); - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; for (i = 0; i < n;) { g = i; x = p[i++] & 0xff; @@ -48,7 +51,8 @@ ssize_t HasControlCodes(const char *p, size_t n, int f) { if (i + m <= n) { for (j = 0;;) { b = p[i + j] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++j == m) { x = a; diff --git a/net/http/headerhassubstring.c b/net/http/headerhassubstring.c index 7af8ebbc6..3d96db17a 100644 --- a/net/http/headerhassubstring.c +++ b/net/http/headerhassubstring.c @@ -34,7 +34,8 @@ bool HeaderHas(struct HttpMessage *m, const char *b, int h, const char *s, size_t n) { size_t i; unassert(0 <= h && h < kHttpHeadersMax); - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; if (m->headers[h].a) { if (memmem(b + m->headers[h].a, m->headers[h].b - m->headers[h].a, s, n)) { return true; diff --git a/net/http/indentlines.c b/net/http/indentlines.c index 81d90ebdd..365816f7e 100644 --- a/net/http/indentlines.c +++ b/net/http/indentlines.c @@ -34,7 +34,8 @@ char *IndentLines(const char *p, size_t n, size_t *z, size_t j) { char *r, *q; const char *l; size_t t, m, a; - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; r = 0; t = 0; do { @@ -49,7 +50,8 @@ char *IndentLines(const char *p, size_t n, size_t *z, size_t j) { r = q; } else { free(r); - if (z) *z = 0; + if (z) + *z = 0; return 0; } memset(r + t, ' ', a); @@ -58,7 +60,8 @@ char *IndentLines(const char *p, size_t n, size_t *z, size_t j) { p += m; n -= m; } while (l); - if (z) *z = t; + if (z) + *z = t; r[t] = '\0'; return r; } diff --git a/net/http/isacceptablehost.c b/net/http/isacceptablehost.c index 9b7c13c6a..f8dc7feed 100644 --- a/net/http/isacceptablehost.c +++ b/net/http/isacceptablehost.c @@ -54,8 +54,10 @@ extern const char kHostChars[256]; // -_0-9A-Za-z bool IsAcceptableHost(const char *s, size_t n) { size_t i; int c, b, j; - if (n == -1) n = s ? strlen(s) : 0; - if (!n) return true; + if (n == -1) + n = s ? strlen(s) : 0; + if (!n) + return true; if (n > DNS_NAME_MAX) { return false; } diff --git a/net/http/isacceptablepath.c b/net/http/isacceptablepath.c index 2c1bef544..df9d6d578 100644 --- a/net/http/isacceptablepath.c +++ b/net/http/isacceptablepath.c @@ -40,7 +40,8 @@ bool IsAcceptablePath(const char *data, size_t size) { const char *p, *e; int x, y, a, b, t, i, n; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; t = 0; y = '/'; p = data; @@ -53,7 +54,8 @@ bool IsAcceptablePath(const char *data, size_t size) { if (p + n <= e) { for (i = 0;;) { b = p[i] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++i == n) { x = a; @@ -68,10 +70,10 @@ bool IsAcceptablePath(const char *data, size_t size) { } if (y == '/') { if (x == '.' && // allow /.well-known/ in the first position - (p - data > 2 || - size < 13 || - memcmp(data, "/.well-known/", 13) != 0)) return false; - if (x == '/' && t) return false; + (p - data > 2 || size < 13 || memcmp(data, "/.well-known/", 13) != 0)) + return false; + if (x == '/' && t) + return false; } y = x; t = 1; diff --git a/net/http/isacceptableport.c b/net/http/isacceptableport.c index e7eac3539..f0028b2ca 100644 --- a/net/http/isacceptableport.c +++ b/net/http/isacceptableport.c @@ -39,7 +39,8 @@ bool IsAcceptablePort(const char *s, size_t n) { int p, c; size_t i; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; for (p = i = 0; i < n; ++i) { c = s[i] & 255; if ('0' <= c && c <= '9') { diff --git a/net/http/ismimetype.c b/net/http/ismimetype.c index f8070976c..a810a0585 100644 --- a/net/http/ismimetype.c +++ b/net/http/ismimetype.c @@ -25,10 +25,13 @@ */ bool IsMimeType(const char *t, size_t n, const char *s) { size_t i; - if (n == -1) n = t ? strlen(t) : 0; + if (n == -1) + n = t ? strlen(t) : 0; for (i = 0; i < n; ++i) { - if (!s[i]) return !kHttpToken[t[i] & 0xFF]; - if (kToLower[s[i] & 0xFF] != kToLower[t[i] & 0xFF]) return false; + if (!s[i]) + return !kHttpToken[t[i] & 0xFF]; + if (kToLower[s[i] & 0xFF] != kToLower[t[i] & 0xFF]) + return false; } return !s[i]; } diff --git a/net/http/isnocompressext.c b/net/http/isnocompressext.c index e5670f83d..ac26542b9 100644 --- a/net/http/isnocompressext.c +++ b/net/http/isnocompressext.c @@ -58,12 +58,15 @@ static bool BisectNoCompressExts(uint64_t ext) { bool IsNoCompressExt(const char *p, size_t n) { int c, i; uint64_t w; - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; if (n) { for (i = w = 0; n--;) { c = p[n] & 255; - if (c == '.') break; - if (++i > 8) return false; + if (c == '.') + break; + if (++i > 8) + return false; w <<= 8; w |= kToLower[c]; } diff --git a/net/http/isreasonablepath.c b/net/http/isreasonablepath.c index 1a0d7e1d8..bbe7487b5 100644 --- a/net/http/isreasonablepath.c +++ b/net/http/isreasonablepath.c @@ -29,7 +29,8 @@ bool IsReasonablePath(const char *data, size_t size) { const char *p, *e; int x, y, z, a, b, i, n; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; z = '/'; y = '/'; x = '/'; @@ -43,7 +44,8 @@ bool IsReasonablePath(const char *data, size_t size) { if (p + n <= e) { for (i = 0;;) { b = p[i] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++i == n) { x = a; @@ -56,12 +58,16 @@ bool IsReasonablePath(const char *data, size_t size) { if (x == '\\') { x = '/'; } - if (z == '/' && y == '.' && x == '/') return false; - if (z == '/' && y == '.' && x == '.') return false; + if (z == '/' && y == '.' && x == '/') + return false; + if (z == '/' && y == '.' && x == '.') + return false; z = y; y = x; } - if (y == '/' && x == '.') return false; - if (z == '/' && y == '.' && x == '.') return false; + if (y == '/' && x == '.') + return false; + if (z == '/' && y == '.' && x == '.') + return false; return true; } diff --git a/net/http/isvalidcookievalue.c b/net/http/isvalidcookievalue.c index 657e095cf..240c7895c 100644 --- a/net/http/isvalidcookievalue.c +++ b/net/http/isvalidcookievalue.c @@ -33,7 +33,8 @@ static inline bool IsCookieOctet(unsigned char i) { */ bool IsValidCookieValue(const char *s, size_t n) { size_t i; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; for (i = 0; i < n; ++i) { if (!IsCookieOctet(s[i])) { return false; diff --git a/net/http/isvalidhttptoken.c b/net/http/isvalidhttptoken.c index 8dafd45a0..01ec456d0 100644 --- a/net/http/isvalidhttptoken.c +++ b/net/http/isvalidhttptoken.c @@ -26,8 +26,10 @@ */ bool IsValidHttpToken(const char *s, size_t n) { size_t i; - if (!n) return false; - if (n == -1) n = s ? strlen(s) : 0; + if (!n) + return false; + if (n == -1) + n = s ? strlen(s) : 0; for (i = 0; i < n; ++i) { if (!kHttpToken[s[i] & 0xff]) { return false; diff --git a/net/http/parsecidr.c b/net/http/parsecidr.c index 549edb528..01ede3523 100644 --- a/net/http/parsecidr.c +++ b/net/http/parsecidr.c @@ -38,7 +38,8 @@ struct Cidr ParseCidr(const char *s, size_t n) { size_t i; const char *p; struct Cidr c; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; if ((p = strchr(s, '/'))) { if ((c.addr = ParseIp(s, (i = p - s))) != -1) { c.cidr = 0; diff --git a/net/http/parsecontentlength.c b/net/http/parsecontentlength.c index 9b7ed8300..47856e4cd 100644 --- a/net/http/parsecontentlength.c +++ b/net/http/parsecontentlength.c @@ -30,14 +30,19 @@ int64_t ParseContentLength(const char *s, size_t n) { size_t i; int64_t r; - if (n == -1) n = s ? strlen(s) : 0; - if (!n) return -1; + if (n == -1) + n = s ? strlen(s) : 0; + if (!n) + return -1; for (r = i = 0; i < n; ++i) { - if (s[i] == ',' && i > 0) break; - if (!isdigit(s[i])) return -1; + if (s[i] == ',' && i > 0) + break; + if (!isdigit(s[i])) + return -1; r *= 10; r += s[i] - '0'; - if (r >= MAXIMUM) return -1; + if (r >= MAXIMUM) + return -1; } return r; } diff --git a/net/http/parseforwarded.c b/net/http/parseforwarded.c index de826a5fe..0d3e746b3 100644 --- a/net/http/parseforwarded.c +++ b/net/http/parseforwarded.c @@ -40,12 +40,14 @@ int ParseForwarded(const char *s, size_t n, uint32_t *ip, uint16_t *port) { size_t i; char *r; uint32_t x; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; if (n) { t = x = i = 0; if ((r = memrchr(s, ',', n))) { i = r - s; - if ((s[++i] & 255) == ' ') ++i; // skip optional space + if ((s[++i] & 255) == ' ') + ++i; // skip optional space } do { c = s[i++] & 255; @@ -82,8 +84,10 @@ int ParseForwarded(const char *s, size_t n, uint32_t *ip, uint16_t *port) { } } } - if (ip) *ip = x; - if (port) *port = t; + if (ip) + *ip = x; + if (port) + *port = t; return 0; } else { return -1; diff --git a/net/http/parsehttpdatetime.c b/net/http/parsehttpdatetime.c index d95395f80..7d5343466 100644 --- a/net/http/parsehttpdatetime.c +++ b/net/http/parsehttpdatetime.c @@ -42,8 +42,10 @@ static unsigned ParseMonth(const char *p) { */ int64_t ParseHttpDateTime(const char *p, size_t n) { unsigned year, month, day, hour, minute, second, yday, leap; - if (n == -1) n = p ? strlen(p) : 0; - if (n != 29) return 0; + if (n == -1) + n = p ? strlen(p) : 0; + if (n != 29) + return 0; day = (p[5] - '0') * 10 + (p[6] - '0') - 1; month = ParseMonth(p + 8); year = (p[12] - '0') * 1000 + (p[13] - '0') * 100 + (p[14] - '0') * 10 + diff --git a/net/http/parsehttpmessage.c b/net/http/parsehttpmessage.c index b95869d69..47f3483f4 100644 --- a/net/http/parsehttpmessage.c +++ b/net/http/parsehttpmessage.c @@ -91,8 +91,10 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { c = p[r->i] & 0xff; switch (r->t) { case kHttpStateStart: - if (c == '\r' || c == '\n') break; // RFC7230 § 3.5 - if (!kHttpToken[c]) return ebadmsg(); + if (c == '\r' || c == '\n') + break; // RFC7230 § 3.5 + if (!kHttpToken[c]) + return ebadmsg(); if (r->type == kHttpRequest) { r->t = kHttpStateMethod; r->method = kToUpper[c]; @@ -114,14 +116,16 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { c = kToUpper[c]; r->method |= (uint64_t)c << r->a; r->a += 8; - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; case kHttpStateUri: for (;;) { if (c == ' ' || c == '\r' || c == '\n') { - if (r->i == r->a) return ebadmsg(); + if (r->i == r->a) + return ebadmsg(); r->uri.a = r->a; r->uri.b = r->i; if (c == ' ') { @@ -135,7 +139,8 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { } else if (c < 0x20 || (0x7F <= c && c < 0xA0)) { return ebadmsg(); } - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; @@ -158,7 +163,8 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { case kHttpStateStatus: for (;;) { if (c == ' ' || c == '\r' || c == '\n') { - if (r->status < 100) return ebadmsg(); + if (r->status < 100) + return ebadmsg(); if (c == ' ') { r->a = r->i + 1; r->t = kHttpStateMessage; @@ -169,11 +175,13 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { } else if ('0' <= c && c <= '9') { r->status *= 10; r->status += c - '0'; - if (r->status > 999) return ebadmsg(); + if (r->status > 999) + return ebadmsg(); } else { return ebadmsg(); } - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; @@ -187,12 +195,14 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { } else if (c < 0x20 || (0x7F <= c && c < 0xA0)) { return ebadmsg(); } - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; case kHttpStateCr: - if (c != '\n') return ebadmsg(); + if (c != '\n') + return ebadmsg(); r->t = kHttpStateLf1; break; case kHttpStateLf1: @@ -218,12 +228,14 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { } else if (!kHttpToken[c]) { return ebadmsg(); } - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; case kHttpStateColon: - if (c == ' ' || c == '\t') break; + if (c == ' ' || c == '\t') + break; r->a = r->i; r->t = kHttpStateValue; // fallthrough @@ -231,7 +243,8 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { for (;;) { if (c == '\r' || c == '\n') { i = r->i; - while (i > r->a && (p[i - 1] == ' ' || p[i - 1] == '\t')) --i; + while (i > r->a && (p[i - 1] == ' ' || p[i - 1] == '\t')) + --i; if ((h = GetHttpHeader(p + r->k.a, r->k.b - r->k.a)) != -1 && (!r->headers[h].a || !kHttpRepeatable[h])) { r->headers[h].a = r->a; @@ -265,7 +278,8 @@ int ParseHttpMessage(struct HttpMessage *r, const char *p, size_t n) { } else if ((c < 0x20 && c != '\t') || (0x7F <= c && c < 0xA0)) { return ebadmsg(); } - if (++r->i == n) break; + if (++r->i == n) + break; c = p[r->i] & 0xff; } break; diff --git a/net/http/parsehttpmethod.c b/net/http/parsehttpmethod.c index 6354eb397..bb71041d4 100644 --- a/net/http/parsehttpmethod.c +++ b/net/http/parsehttpmethod.c @@ -31,11 +31,14 @@ uint64_t ParseHttpMethod(const char *str, size_t len) { int s = 0; uint64_t w = 0; - if (len == -1) len = str ? strlen(str) : 0; + if (len == -1) + len = str ? strlen(str) : 0; for (size_t i = 0; i < len; ++i) { int c = kToUpper[str[i] & 255]; - if (!kHttpToken[c]) return 0; - if (s == 64) return 0; + if (!kHttpToken[c]) + return 0; + if (s == 64) + return 0; w |= (uint64_t)c << s; s += 8; } diff --git a/net/http/parsehttprange.c b/net/http/parsehttprange.c index 57d9a19c2..80aa738b7 100644 --- a/net/http/parsehttprange.c +++ b/net/http/parsehttprange.c @@ -38,23 +38,30 @@ bool ParseHttpRange(const char *p, size_t n, long resourcelength, long start, length, ending; *out_start = 0; *out_length = 0; - if (memchr(p, ',', n)) return false; - if (n < 7 || memcmp(p, "bytes=", 6) != 0) return false; + if (memchr(p, ',', n)) + return false; + if (n < 7 || memcmp(p, "bytes=", 6) != 0) + return false; p += 6, n -= 6; if (n && *p == '-') { ++p, --n; length = 0; while (n && '0' <= *p && *p <= '9') { - if (ckd_mul(&length, length, 10)) return false; - if (ckd_add(&length, length, *p - '0')) return false; + if (ckd_mul(&length, length, 10)) + return false; + if (ckd_add(&length, length, *p - '0')) + return false; ++p, --n; } - if (ckd_sub(&start, resourcelength, length)) return false; + if (ckd_sub(&start, resourcelength, length)) + return false; } else { start = 0; while (n && '0' <= *p && *p <= '9') { - if (ckd_mul(&start, start, 10)) return false; - if (ckd_add(&start, start, *p - '0')) return false; + if (ckd_mul(&start, start, 10)) + return false; + if (ckd_add(&start, start, *p - '0')) + return false; ++p, --n; } if (n && *p == '-') { @@ -64,22 +71,31 @@ bool ParseHttpRange(const char *p, size_t n, long resourcelength, } else { length = 0; while (n && '0' <= *p && *p <= '9') { - if (ckd_mul(&length, length, 10)) return false; - if (ckd_add(&length, length, *p - '0')) return false; + if (ckd_mul(&length, length, 10)) + return false; + if (ckd_add(&length, length, *p - '0')) + return false; ++p, --n; } - if (ckd_add(&length, length, 1)) return false; - if (ckd_sub(&length, length, start)) return false; + if (ckd_add(&length, length, 1)) + return false; + if (ckd_sub(&length, length, start)) + return false; } } else if (ckd_sub(&length, resourcelength, start)) { return false; } } - if (n) return false; - if (start < 0) return false; - if (length < 1) return false; - if (start > resourcelength) return false; - if (ckd_add(&ending, start, length)) return false; + if (n) + return false; + if (start < 0) + return false; + if (length < 1) + return false; + if (start > resourcelength) + return false; + if (ckd_add(&ending, start, length)) + return false; if (ending > resourcelength) { length = resourcelength - start; } diff --git a/net/http/parseip.c b/net/http/parseip.c index 136602998..700f49044 100644 --- a/net/http/parseip.c +++ b/net/http/parseip.c @@ -32,8 +32,10 @@ int64_t ParseIp(const char *s, size_t n) { size_t i; unsigned b, x; bool dotted = false; - if (n == -1) n = s ? strlen(s) : 0; - if (!n) return -1; + if (n == -1) + n = s ? strlen(s) : 0; + if (!n) + return -1; for (b = x = j = i = 0; i < n; ++i) { c = s[i] & 255; if (isdigit(c)) { @@ -43,7 +45,8 @@ int64_t ParseIp(const char *s, size_t n) { return -1; } } else if (c == '.') { - if (b > 255) return -1; + if (b > 255) + return -1; dotted = true; x <<= 8; x |= b; diff --git a/net/http/parseurl.c b/net/http/parseurl.c index dffa46e39..c967f4543 100644 --- a/net/http/parseurl.c +++ b/net/http/parseurl.c @@ -204,7 +204,8 @@ static void ParsePath(struct UrlParser *u, struct UrlView *h) { static void ParseQuery(struct UrlParser *u, struct UrlParams *h) { bool t = false; - if (!h->p) h->p = malloc(0); + if (!h->p) + h->p = malloc(0); while (u->i < u->n) { u->c = u->s[u->i++] & 255; if (u->c == '#') { @@ -285,7 +286,8 @@ static void ParseFragment(struct UrlParser *u, struct UrlView *h) { char *ParseUrl(const char *s, size_t n, struct Url *h, int f) { char *m; struct UrlParser u; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; u.i = 0; u.c = 0; u.s = s; @@ -294,10 +296,14 @@ char *ParseUrl(const char *s, size_t n, struct Url *h, int f) { bzero(h, sizeof(*h)); if ((m = malloc((f & kUrlLatin1) ? u.n * 2 : u.n))) { u.q = u.p = m; - if (ParseScheme(&u, h)) ParseAuthority(&u, h); - if (u.c != '#' && u.c != '?') ParsePath(&u, &h->path); - if (u.c == '?') ParseQuery(&u, &h->params); - if (u.c == '#') ParseFragment(&u, &h->fragment); + if (ParseScheme(&u, h)) + ParseAuthority(&u, h); + if (u.c != '#' && u.c != '?') + ParsePath(&u, &h->path); + if (u.c == '?') + ParseQuery(&u, &h->params); + if (u.c == '#') + ParseFragment(&u, &h->fragment); } return m; } @@ -325,7 +331,8 @@ char *ParseUrl(const char *s, size_t n, struct Url *h, int f) { char *ParseParams(const char *s, size_t n, struct UrlParams *h) { char *m; struct UrlParser u; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; u.i = 0; u.s = s; u.n = n; @@ -365,7 +372,8 @@ char *ParseParams(const char *s, size_t n, struct UrlParams *h) { char *ParseHost(const char *s, size_t n, struct Url *h) { char *m; struct UrlParser u; - if (n == -1) n = s ? strlen(s) : 0; + if (n == -1) + n = s ? strlen(s) : 0; u.i = 0; u.c = 0; u.s = s; diff --git a/net/http/tokenbucket.c b/net/http/tokenbucket.c index c3e71701a..f97675fdf 100644 --- a/net/http/tokenbucket.c +++ b/net/http/tokenbucket.c @@ -37,7 +37,8 @@ void ReplenishTokens(atomic_uint_fast64_t *w, size_t n) { for (size_t i = 0; i < n; ++i) { uint64_t a = atomic_load_explicit(w + i, memory_order_relaxed); - if (a == 0x7f7f7f7f7f7f7f7f) continue; + if (a == 0x7f7f7f7f7f7f7f7f) + continue; uint64_t b = 0x8080808080808080; uint64_t c = 0x7f7f7f7f7f7f7f7f ^ a; uint64_t d = ((((c >> 1 | b) - c) & b) ^ b) >> 7; @@ -75,7 +76,8 @@ void ReplenishTokens(atomic_uint_fast64_t *w, size_t n) { int AcquireToken(atomic_schar *b, uint32_t x, int c) { uint32_t i = x >> (32 - c); int t = atomic_load_explicit(b + i, memory_order_relaxed); - if (t <= 0) return t; + if (t <= 0) + return t; return atomic_fetch_add_explicit(b + i, -1, memory_order_relaxed); } diff --git a/net/http/unchunk.c b/net/http/unchunk.c index 95e068b68..d3fe94bfe 100644 --- a/net/http/unchunk.c +++ b/net/http/unchunk.c @@ -37,14 +37,16 @@ ssize_t Unchunk(struct HttpUnchunker *u, char *p, size_t n, size_t *l) { c = p[u->i++] & 255; switch (u->t) { case kHttpStateChunkStart: - if ((u->m = kHexToInt[c]) == -1) return ebadmsg(); + if ((u->m = kHexToInt[c]) == -1) + return ebadmsg(); u->t = kHttpStateChunkSize; break; case kHttpStateChunkSize: if ((h = kHexToInt[c]) != -1) { u->m *= 16; u->m += h; - if (u->m >= 0x0000010000000000) return ebadmsg(); + if (u->m >= 0x0000010000000000) + return ebadmsg(); break; } u->t = kHttpStateChunkExt; @@ -58,7 +60,8 @@ ssize_t Unchunk(struct HttpUnchunker *u, char *p, size_t n, size_t *l) { } /* fallthrough */ case kHttpStateChunkLf1: - if (c != '\n') return ebadmsg(); + if (c != '\n') + return ebadmsg(); u->t = u->m ? kHttpStateChunk : kHttpStateTrailerStart; break; case kHttpStateChunk: @@ -68,7 +71,8 @@ ssize_t Unchunk(struct HttpUnchunker *u, char *p, size_t n, size_t *l) { u->i += s; u->j += s; u->m -= s; - if (!u->m) u->t = kHttpStateChunkCr2; + if (!u->m) + u->t = kHttpStateChunkCr2; break; case kHttpStateChunkCr2: if (c == '\r') { @@ -77,7 +81,8 @@ ssize_t Unchunk(struct HttpUnchunker *u, char *p, size_t n, size_t *l) { } /* fallthrough */ case kHttpStateChunkLf2: - if (c != '\n') return ebadmsg(); + if (c != '\n') + return ebadmsg(); u->t = kHttpStateChunkStart; break; case kHttpStateTrailerStart: @@ -98,14 +103,18 @@ ssize_t Unchunk(struct HttpUnchunker *u, char *p, size_t n, size_t *l) { } /* fallthrough */ case kHttpStateTrailerLf1: - if (c != '\n') return ebadmsg(); + if (c != '\n') + return ebadmsg(); u->t = kHttpStateTrailerStart; break; case kHttpStateTrailerLf2: - if (c != '\n') return ebadmsg(); + if (c != '\n') + return ebadmsg(); Finished: - if (l) *l = u->j; - if (u->j < n) p[u->j] = 0; + if (l) + *l = u->j; + if (u->j < n) + p[u->j] = 0; return u->i; break; default: diff --git a/net/http/underlong.c b/net/http/underlong.c index 4edc53b79..a48e7f48c 100644 --- a/net/http/underlong.c +++ b/net/http/underlong.c @@ -41,15 +41,18 @@ char *Underlong(const char *p, size_t n, size_t *z) { size_t i, j, m; wint_t x, a, b; int8_t v1[16], v2[16], vz[16]; - if (z) *z = 0; - if (n == -1) n = p ? strlen(p) : 0; + if (z) + *z = 0; + if (n == -1) + n = p ? strlen(p) : 0; if ((q = r = malloc(n * 2 + 1))) { for (i = 0; i < n;) { bzero(vz, 16); /* 50x speedup for ASCII */ while (i + 16 < n) { memcpy(v1, p + i, 16); pcmpgtb(v2, v1, vz); - if (pmovmskb((void *)v2) != 0xFFFF) break; + if (pmovmskb((void *)v2) != 0xFFFF) + break; memcpy(q, v1, 16); q += 16; i += 16; @@ -61,7 +64,8 @@ char *Underlong(const char *p, size_t n, size_t *z) { if (i + m <= n) { for (j = 0;;) { b = p[i + j] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++j == m) { x = a; @@ -76,9 +80,11 @@ char *Underlong(const char *p, size_t n, size_t *z) { *q++ = w; } while ((w >>= 8)); } - if (z) *z = q - r; + if (z) + *z = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } return r; } diff --git a/net/http/visualizecontrolcodes.c b/net/http/visualizecontrolcodes.c index b8f93be7a..84ecaa681 100644 --- a/net/http/visualizecontrolcodes.c +++ b/net/http/visualizecontrolcodes.c @@ -43,7 +43,8 @@ char *VisualizeControlCodes(const char *data, size_t size, size_t *out_size) { unsigned i, n; wint_t x, a, b; const char *p, *e; - if (size == -1) size = data ? strlen(data) : 0; + if (size == -1) + size = data ? strlen(data) : 0; if ((r = malloc(size * 6 + 1))) { q = r; p = data; @@ -56,7 +57,8 @@ char *VisualizeControlCodes(const char *data, size_t size, size_t *out_size) { if (p + n <= e) { for (i = 0;;) { b = p[i] & 0xff; - if (!ThomPikeCont(b)) break; + if (!ThomPikeCont(b)) + break; a = ThomPikeMerge(a, b); if (++i == n) { x = a; @@ -116,7 +118,8 @@ char *VisualizeControlCodes(const char *data, size_t size, size_t *out_size) { } n = q - r; *q++ = '\0'; - if ((q = realloc(r, q - r))) r = q; + if ((q = realloc(r, q - r))) + r = q; } else { n = 0; } diff --git a/net/https/describesslverifyfailure.c b/net/https/describesslverifyfailure.c index d691e8284..46e0056ab 100644 --- a/net/https/describesslverifyfailure.c +++ b/net/https/describesslverifyfailure.c @@ -54,7 +54,8 @@ char *DescribeSslVerifyFailure(int flags) { p = malloc(1024); q = stpcpy(p, "verify failed"); for (i = 0; i < ARRAYLEN(kSslVerifyStrings); ++i) { - if (!(flags & kSslVerifyStrings[i].code)) continue; + if (!(flags & kSslVerifyStrings[i].code)) + continue; q = stpcpy(stpcpy(q, " "), kSslVerifyStrings[i].str); } return p; diff --git a/net/https/finishcertificate.c b/net/https/finishcertificate.c index 22949810b..0bf931a8b 100644 --- a/net/https/finishcertificate.c +++ b/net/https/finishcertificate.c @@ -28,10 +28,12 @@ struct Cert FinishCertificate(struct Cert *ca, mbedtls_x509write_cert *wcert, mbedtls_x509_crt *cert; p = malloc((n = FRAMESIZE)); i = mbedtls_x509write_crt_der(wcert, p, n, GenerateHardRandom, 0); - if (i < 0) FATALF("write key (grep -0x%04x)", -i); + if (i < 0) + FATALF("write key (grep -0x%04x)", -i); cert = calloc(1, sizeof(mbedtls_x509_crt)); mbedtls_x509_crt_parse(cert, p + n - i, i); - if (ca) cert->next = ca->cert; + if (ca) + cert->next = ca->cert; mbedtls_x509write_crt_free(wcert); free(p); if ((rc = mbedtls_pk_check_pair(&cert->pk, key))) { diff --git a/net/turfwar/blackholed.c b/net/turfwar/blackholed.c index 776267a02..eb30b8550 100644 --- a/net/turfwar/blackholed.c +++ b/net/turfwar/blackholed.c @@ -145,8 +145,10 @@ struct SortedInts g_whitelisted; static wontreturn void ShowUsage(int fd, int rc) { write(fd, USAGE, sizeof(USAGE) - 1); - if (IsLinux()) write(fd, LINUX_DOCS, sizeof(LINUX_DOCS) - 1); - if (IsBsd()) write(fd, BSD_DOCS, sizeof(BSD_DOCS) - 1); + if (IsLinux()) + write(fd, LINUX_DOCS, sizeof(LINUX_DOCS) - 1); + if (IsBsd()) + write(fd, BSD_DOCS, sizeof(BSD_DOCS) - 1); _Exit(rc); } @@ -288,8 +290,10 @@ void FindFirewall(void) { } void OpenLog(void) { - if (!g_logname) return; - if (!g_daemonize) return; + if (!g_logname) + return; + if (!g_daemonize) + return; if ((g_logfd = open(g_logname, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) { kprintf("error: open(%#s) failed: %s\n", g_logname, strerror(errno)); ShowUsage(2, 5); @@ -314,11 +318,13 @@ void UseLog(void) { void UninterruptibleSleep(int ms) { struct timespec ts = timespec_add(timespec_real(), timespec_frommillis(ms)); - while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0)) errno = 0; + while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0)) + errno = 0; } void Unlink(const char *path) { - if (!path) return; + if (!path) + return; if (!unlink(path)) { LOG("deleted %s", path); } else { @@ -333,7 +339,8 @@ void WritePid(void) { ssize_t rc; int fd, pid; char buf[12] = {0}; - if (!g_pidname) return; + if (!g_pidname) + return; if ((fd = open(g_pidname, O_RDWR | O_CREAT, 0644)) == -1) { LOG("error: open(%#s) failed: %s", g_pidname, strerror(errno)); _Exit(4); diff --git a/net/turfwar/turfwar.c b/net/turfwar/turfwar.c index ff0b650c1..6f89d7212 100644 --- a/net/turfwar/turfwar.c +++ b/net/turfwar/turfwar.c @@ -388,22 +388,26 @@ struct timespec WaitFor(int millis) { // helper functions for check macro implementation bool CheckMem(const char *file, int line, void *ptr) { - if (ptr) return true; + if (ptr) + return true; kprintf("%s:%d: %P: out of memory: %s\n", file, line, strerror(errno)); return false; } bool CheckSys(const char *file, int line, long rc) { - if (rc != -1) return true; + if (rc != -1) + return true; kprintf("%s:%d: %P: %s\n", file, line, strerror(errno)); return false; } bool CheckSql(const char *file, int line, int rc) { - if (rc == SQLITE_OK) return true; + if (rc == SQLITE_OK) + return true; kprintf("%s:%d: %P: %s\n", file, line, sqlite3_errstr(rc)); return false; } bool CheckDb(const char *file, int line, int rc, sqlite3 *db) { - if (rc == SQLITE_OK) return true; + if (rc == SQLITE_OK) + return true; kprintf("%s:%d: %P: %s: %s\n", file, line, sqlite3_errstr(rc), sqlite3_errmsg(db)); return false; @@ -417,16 +421,20 @@ int DbOpen(const char *path, sqlite3 **db) { int i, rc; char sql[128]; rc = sqlite3_open(path, db); - if (rc != SQLITE_OK) return rc; + if (rc != SQLITE_OK) + return rc; if (!IsWindows() && !IsOpenbsd()) { ksnprintf(sql, sizeof(sql), "PRAGMA mmap_size=%ld", GetTotalRam()); rc = sqlite3_exec(*db, sql, 0, 0, 0); - if (rc != SQLITE_OK) return rc; + if (rc != SQLITE_OK) + return rc; } for (i = 0; i < 7; ++i) { rc = sqlite3_exec(*db, "PRAGMA journal_mode=WAL", 0, 0, 0); - if (rc == SQLITE_OK) break; - if (rc != SQLITE_BUSY) return rc; + if (rc == SQLITE_OK) + break; + if (rc != SQLITE_BUSY) + return rc; usleep(1000L << i); } return sqlite3_exec(*db, "PRAGMA synchronous=NORMAL", 0, 0, 0); @@ -436,9 +444,12 @@ int DbStep(sqlite3_stmt *stmt) { int i, rc; for (i = 0; i < 12; ++i) { rc = sqlite3_step(stmt); - if (rc == SQLITE_ROW) break; - if (rc == SQLITE_DONE) break; - if (rc != SQLITE_BUSY) return rc; + if (rc == SQLITE_ROW) + break; + if (rc == SQLITE_DONE) + break; + if (rc != SQLITE_BUSY) + return rc; usleep(1000L << i); } return rc; @@ -465,9 +476,12 @@ bool Blackhole(uint32_t ip) { // validates name registration validity bool IsValidNick(const char *s, size_t n) { size_t i; - if (n == -1) n = strlen(s); - if (!n) return false; - if (n > NICK_MAX) return false; + if (n == -1) + n = strlen(s); + if (!n) + return false; + if (n > NICK_MAX) + return false; for (i = 0; i < n; ++i) { if (!(isalnum(s[i]) || // s[i] == '@' || // @@ -533,9 +547,11 @@ bool AddClient(struct Clients *q, const struct Client *v, nsync_time dead) { } if (q->count != ARRAYLEN(q->data)) { int i = q->pos + q->count; - if (ARRAYLEN(q->data) <= i) i -= ARRAYLEN(q->data); + if (ARRAYLEN(q->data) <= i) + i -= ARRAYLEN(q->data); memcpy(q->data + i, v, sizeof(*v)); - if (!q->count) wake = true; + if (!q->count) + wake = true; q->count++; added = true; } @@ -587,9 +603,11 @@ bool AddClaim(struct Claims *q, const struct Claim *v, nsync_time dead) { } if (q->count != ARRAYLEN(q->data)) { int i = q->pos + q->count; - if (ARRAYLEN(q->data) <= i) i -= ARRAYLEN(q->data); + if (ARRAYLEN(q->data) <= i) + i -= ARRAYLEN(q->data); memcpy(q->data + i, v, sizeof(*v)); - if (!q->count) wake = true; + if (!q->count) + wake = true; q->count++; added = true; } @@ -1025,7 +1043,8 @@ void *HttpWorker(void *arg) { ksnprintf(cashbuf, sizeof(cashbuf), "max-age=%d, must-revalidate", a->cash); p = stpcpy(p, cashbuf); - if (comp) p = stpcpy(p, "\r\nContent-Encoding: gzip"); + if (comp) + p = stpcpy(p, "\r\nContent-Encoding: gzip"); p = stpcpy(p, "\r\nContent-Length: "); d = comp ? a->gzip : a->data; p = FormatInt32(p, d.n); @@ -1082,7 +1101,8 @@ void *HttpWorker(void *arg) { } else if (UrlStartsWith("/claim")) { // ip:name registration endpoint ++g_claimrequests; - if (ipv6) goto Ipv6Warning; + if (ipv6) + goto Ipv6Warning; struct Claim v = {.ip = ip, .created = g_nowish.ts.tv_sec}; if (GetNick(inbuf, msg, &v)) { if (AddClaim(&g_claims, &v, @@ -1308,7 +1328,8 @@ bool ReloadAsset(struct Asset *a) { CHECK_MEM((data.p = malloc(st.st_size))); CHECK_SYS((rc = read(fd, data.p, st.st_size))); data.n = st.st_size; - if (rc != st.st_size) goto OnError; + if (rc != st.st_size) + goto OnError; CHECK_MEM((gzip = Gzip(data)).p); //!//!//!//!//!//!//!//!//!//!//!//!//!/ nsync_mu_lock(&a->lock); @@ -1469,12 +1490,15 @@ bool GenerateScore(struct Asset *out, long secs, long cash) { // otherwise.. you can use --strace to see the fcntl bloodbath CHECK_SQL(sqlite3_exec(db, "BEGIN TRANSACTION", 0, 0, 0)); while ((rc = DbStep(stmt)) != SQLITE_DONE) { - if (rc != SQLITE_ROW) CHECK_DB(rc); + if (rc != SQLITE_ROW) + CHECK_DB(rc); strlcpy(name2, (void *)sqlite3_column_text(stmt, 0), sizeof(name2)); - if (!IsValidNick(name2, -1)) continue; + if (!IsValidNick(name2, -1)) + continue; if (strcmp(name1, name2)) { // name changed - if (namestate) CHECK_SYS(appends(&a.data.p, "],\n")); + if (namestate) + CHECK_SYS(appends(&a.data.p, "],\n")); namestate = true; CHECK_SYS(appendf( &a.data.p, "\"%s\":[\n", @@ -1487,7 +1511,8 @@ bool GenerateScore(struct Asset *out, long secs, long cash) { sqlite3_column_int64(stmt, 2))); } CHECK_SQL(sqlite3_exec(db, "END TRANSACTION", 0, 0, 0)); - if (namestate) CHECK_SYS(appends(&a.data.p, "]\n")); + if (namestate) + CHECK_SYS(appends(&a.data.p, "]\n")); CHECK_SYS(appends(&a.data.p, "}}\n")); CHECK_DB(sqlite3_finalize(stmt)); CHECK_SQL(sqlite3_close(db)); @@ -1540,7 +1565,8 @@ bool GeneratePlot(struct Asset *out, long block, long cash) { mask = area - 1; clump = 32 - bsr(area) - 8; while ((rc = DbStep(stmt)) != SQLITE_DONE) { - if (rc != SQLITE_ROW) CHECK_DB(rc); + if (rc != SQLITE_ROW) + CHECK_DB(rc); ip = sqlite3_column_int64(stmt, 0); i = (ip >> clump) & mask; y = g_hilbert[i][0]; @@ -1700,8 +1726,10 @@ StartOver: CHECK_SYS(appends(&t.data.p, "\"recent\":[\n")); CHECK_SQL(sqlite3_exec(db, "BEGIN TRANSACTION", 0, 0, 0)); for (once = false; (rc = DbStep(stmt)) != SQLITE_DONE; once = true) { - if (rc != SQLITE_ROW) CHECK_SQL(rc); - if (once) CHECK_SYS(appends(&t.data.p, ",\n")); + if (rc != SQLITE_ROW) + CHECK_SQL(rc); + if (once) + CHECK_SYS(appends(&t.data.p, ",\n")); CHECK_SYS( appendf(&t.data.p, "[%ld,\"%s\",%ld]", sqlite3_column_int64(stmt, 0), EscapeJsStringLiteral( @@ -1939,9 +1967,11 @@ int main(int argc, char *argv[]) { // the power to serve if (g_daemonize) { - if (fork() > 0) _Exit(0); + if (fork() > 0) + _Exit(0); setsid(); - if (fork() > 0) _Exit(0); + if (fork() > 0) + _Exit(0); umask(0); if (closefrom(0)) for (int i = 0; i < 256; ++i) // diff --git a/test/libc/calls/access_test.c b/test/libc/calls/access_test.c index 1766ff0d5..72bfbb3ea 100644 --- a/test/libc/calls/access_test.c +++ b/test/libc/calls/access_test.c @@ -34,7 +34,8 @@ void SetUpOnce(void) { } TEST(access, efault) { - if (IsWindows() || !IsAsan()) return; // not possible + if (IsWindows() || !IsAsan()) + return; // not possible ASSERT_SYS(EFAULT, -1, access((void *)77, F_OK)); } @@ -61,7 +62,8 @@ TEST(access, test) { } TEST(access, testRequestWriteOnReadOnly_returnsEaccess) { - if (1) return; // TODO(jart): maybe we need root to help? + if (1) + return; // TODO(jart): maybe we need root to help? ASSERT_SYS(ENOENT, -1, access("file", F_OK)); ASSERT_SYS(0, 0, close(creat("file", 0444))); ASSERT_SYS(0, 0, access("file", F_OK)); diff --git a/test/libc/calls/cachestat_test.c b/test/libc/calls/cachestat_test.c index 22316cdff..a24b6e490 100644 --- a/test/libc/calls/cachestat_test.c +++ b/test/libc/calls/cachestat_test.c @@ -93,7 +93,8 @@ TEST(cachestat, testCachestatSyncNoDirty) { "total number of evicted pages is off."); struct statfs statfs; ASSERT_SYS(0, 0, fstatfs(3, &statfs)); - if (statfs.f_type == TMPFS_MAGIC) goto done; + if (statfs.f_type == TMPFS_MAGIC) + goto done; ASSERT_SYS(0, 0, fsync(3)); ASSERT_SYS(0, 0, cachestat(3, &range, &cs, 0)); EXPECT_EQ(0, cs.nr_dirty, diff --git a/test/libc/calls/chdir_test.c b/test/libc/calls/chdir_test.c index f41db6354..93c5f359b 100644 --- a/test/libc/calls/chdir_test.c +++ b/test/libc/calls/chdir_test.c @@ -29,7 +29,8 @@ void SetUpOnce(void) { TEST(chdir, efault) { ASSERT_SYS(EFAULT, -1, chdir(0)); - if (IsWindows() || !IsAsan()) return; // not possible + if (IsWindows() || !IsAsan()) + return; // not possible ASSERT_SYS(EFAULT, -1, chdir((void *)77)); } diff --git a/test/libc/calls/clock_getres_test.c b/test/libc/calls/clock_getres_test.c index 2f7db7881..2497816be 100644 --- a/test/libc/calls/clock_getres_test.c +++ b/test/libc/calls/clock_getres_test.c @@ -40,14 +40,16 @@ TEST(clock_getres, realtimeFastHasMillisecondPrecisionOrBetter) { } TEST(clock_getres, realtimeCoarseHasMillisecondPrecisionOrBetter) { - if (clock_getres(CLOCK_REALTIME_COARSE, &ts)) return; + if (clock_getres(CLOCK_REALTIME_COARSE, &ts)) + return; EXPECT_EQ(0, ts.tv_sec); EXPECT_LT(ts.tv_nsec, 100000000); EXPECT_GT(ts.tv_nsec, 0); } TEST(clock_getres, realtimePreciseHasMillisecondPrecisionOrBetter) { - if (clock_getres(CLOCK_REALTIME_PRECISE, &ts)) return; + if (clock_getres(CLOCK_REALTIME_PRECISE, &ts)) + return; EXPECT_EQ(0, ts.tv_sec); EXPECT_LT(ts.tv_nsec, 100000000); EXPECT_GT(ts.tv_nsec, 0); @@ -68,14 +70,16 @@ TEST(clock_getres, monotonicFastHasMillisecondPrecisionOrBetter) { } TEST(clock_getres, monotonicCoarseHasMillisecondPrecisionOrBetter) { - if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts)) return; + if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts)) + return; EXPECT_EQ(0, ts.tv_sec); EXPECT_LT(ts.tv_nsec, 100000000); EXPECT_GT(ts.tv_nsec, 0); } TEST(clock_getres, monotonicPreciseHasMillisecondPrecisionOrBetter) { - if (clock_getres(CLOCK_MONOTONIC_PRECISE, &ts)) return; + if (clock_getres(CLOCK_MONOTONIC_PRECISE, &ts)) + return; EXPECT_EQ(0, ts.tv_sec); EXPECT_LT(ts.tv_nsec, 100000000); EXPECT_GT(ts.tv_nsec, 0); diff --git a/test/libc/calls/closefrom_test.c b/test/libc/calls/closefrom_test.c index 9991b22d9..fe77ba652 100644 --- a/test/libc/calls/closefrom_test.c +++ b/test/libc/calls/closefrom_test.c @@ -70,6 +70,7 @@ TEST(close_range, test) { } TEST(close_range, ignoresNonexistantRanges) { - if (!IsLinux() && !IsFreebsd()) return; + if (!IsLinux() && !IsFreebsd()) + return; EXPECT_SYS(0, 0, close_range(-2, -1, 0)); } diff --git a/test/libc/calls/commandv_test.c b/test/libc/calls/commandv_test.c index 0014315d3..a86aaa43c 100644 --- a/test/libc/calls/commandv_test.c +++ b/test/libc/calls/commandv_test.c @@ -100,7 +100,8 @@ TEST(commandv, test_DirPaths_wontConsiderDirectoriesExecutable2) { } TEST(commandv, test_nonExecutableFile_willEacces) { - if (IsWindows()) return; // TODO: fixme + if (IsWindows()) + return; // TODO: fixme setenv("PATH", "foo", true); EXPECT_SYS(0, 0, mkdir("foo", 0755)); EXPECT_SYS(0, 0, touch("foo/bar", 0400)); diff --git a/test/libc/calls/copy_file_range_test.c b/test/libc/calls/copy_file_range_test.c index cfca0f830..0d88450de 100644 --- a/test/libc/calls/copy_file_range_test.c +++ b/test/libc/calls/copy_file_range_test.c @@ -94,19 +94,23 @@ bool HasCopyFileRange(void) { } TEST(copy_file_range, badFd) { - if (!HasCopyFileRange()) return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(EBADF, -1, copy_file_range(-1, 0, -1, 0, -1u, 0)); } TEST(copy_file_range, badFlags) { - if (!HasCopyFileRange()) return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(EINVAL, -1, copy_file_range(0, 0, 1, 0, -1u, -1)); } TEST(copy_file_range, differentFileSystems) { return; // TODO(jart): Why does this flake on GitHub Actions? - if (!IsLinux()) return; - if (!HasCopyFileRange()) return; + if (!IsLinux()) + return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(0, 3, open("/proc/stat", 0)); ASSERT_SYS(0, 4, creat("foo", 0644)); ASSERT_SYS(EXDEV, -1, copy_file_range(3, 0, 4, 0, -1u, 0)); @@ -117,7 +121,8 @@ TEST(copy_file_range, differentFileSystems) { TEST(copy_file_range, twoDifferentFiles) { char buf[16] = {0}; int64_t i = 1, o = 0; - if (!HasCopyFileRange()) return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644)); ASSERT_SYS(0, 4, open("bar", O_RDWR | O_CREAT | O_TRUNC, 0644)); ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0)); @@ -134,7 +139,8 @@ TEST(copy_file_range, twoDifferentFiles) { TEST(copy_file_range, sameFile_doesntChangeFilePointer) { char buf[16] = {0}; int64_t i = 1, o = 5; - if (!HasCopyFileRange()) return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644)); ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0)); ASSERT_SYS(0, 4, copy_file_range(3, &i, 3, &o, 4, 0)); @@ -148,7 +154,8 @@ TEST(copy_file_range, sameFile_doesntChangeFilePointer) { TEST(copy_file_range, overlappingRange) { int rc; int64_t i = 1, o = 2; - if (!HasCopyFileRange()) return; + if (!HasCopyFileRange()) + return; ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644)); ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0)); rc = copy_file_range(3, &i, 3, &o, 4, 0); diff --git a/test/libc/calls/devfd_test.c b/test/libc/calls/devfd_test.c index 68248c0b3..c5aec28a3 100644 --- a/test/libc/calls/devfd_test.c +++ b/test/libc/calls/devfd_test.c @@ -32,7 +32,8 @@ void SetUpOnce(void) { TEST(devfd, test) { // TODO: What is up with this mysterious ENOENT error? // The code appears like it should support this. - if (IsFreebsd()) return; + if (IsFreebsd()) + return; char buf[8] = {0}; struct stat st[2] = {0}; ASSERT_SYS(0, 0, xbarf("hello.txt", "bone", -1)); @@ -50,7 +51,8 @@ TEST(devfd, test) { TEST(devfd, not_DEV_FD_STAT_BROKEN) { // fstat() and stat() are inconsistent on bsd systems // with xnu it only appears to be st_dev that differs - if (IsBsd()) return; + if (IsBsd()) + return; char buf[8] = {0}; struct stat st[2] = {0}; ASSERT_SYS(0, 0, xbarf("hello.txt", "bone", -1)); diff --git a/test/libc/calls/fchmodat_test.c b/test/libc/calls/fchmodat_test.c index 02757563e..cb6d99d40 100644 --- a/test/libc/calls/fchmodat_test.c +++ b/test/libc/calls/fchmodat_test.c @@ -34,7 +34,8 @@ void SetUpOnce(void) { } TEST(fchmodat, testFchmodat) { - if (IsWindows()) return; // not advanced enough yet + if (IsWindows()) + return; // not advanced enough yet struct stat st; umask(022); ASSERT_SYS(0, 3, diff --git a/test/libc/calls/fcntl_test.c b/test/libc/calls/fcntl_test.c index a8f535624..84675e66a 100644 --- a/test/libc/calls/fcntl_test.c +++ b/test/libc/calls/fcntl_test.c @@ -139,8 +139,10 @@ void OnSig(int sig) { } TEST(posixAdvisoryLocks, twoProcesses) { - if (IsWindows()) return; // due to signals - if (IsNetbsd()) return; // TODO: why does sigusr1 kill runitd? + if (IsWindows()) + return; // due to signals + if (IsNetbsd()) + return; // TODO: why does sigusr1 kill runitd? int ws, pid; struct flock lock; diff --git a/test/libc/calls/ftruncate_test.c b/test/libc/calls/ftruncate_test.c index 70fc5e3bf..6d740f818 100644 --- a/test/libc/calls/ftruncate_test.c +++ b/test/libc/calls/ftruncate_test.c @@ -70,7 +70,8 @@ TEST(ftruncate, pipeFd_einval) { TEST(ftruncate, efbig) { // FreeBSD and RHEL7 return 0 (why??) - if (IsLinux() || IsFreebsd()) return; + if (IsLinux() || IsFreebsd()) + return; sighandler_t old = signal(SIGXFSZ, SIG_IGN); ASSERT_SYS(0, 3, creat("foo", 0755)); ASSERT_SYS(IsWindows() ? EINVAL : EFBIG, -1, ftruncate(3, INT64_MAX)); diff --git a/test/libc/calls/getcwd_test.c b/test/libc/calls/getcwd_test.c index 0c5a4194d..f9e8f22e3 100644 --- a/test/libc/calls/getcwd_test.c +++ b/test/libc/calls/getcwd_test.c @@ -33,7 +33,8 @@ void SetUpOnce(void) { } TEST(__getcwd, zero) { - if (IsQemuUser()) return; + if (IsQemuUser()) + return; ASSERT_SYS(ERANGE, -1, __getcwd(0, 0)); } @@ -83,7 +84,8 @@ TEST(getcwd, testNullBuf_allocatesResult) { } TEST(getcwd, testWindows_addsFunnyPrefix) { - if (!IsWindows()) return; + if (!IsWindows()) + return; char path[PATH_MAX]; ASSERT_NE(0, getcwd(path, sizeof(path))); path[1] = tolower(path[1]); diff --git a/test/libc/calls/getgroups_test.c b/test/libc/calls/getgroups_test.c index 6463ad5ab..7c221e899 100644 --- a/test/libc/calls/getgroups_test.c +++ b/test/libc/calls/getgroups_test.c @@ -23,9 +23,11 @@ TEST(getgroups, test) { int n; - if (IsWindows()) return; + if (IsWindows()) + return; uint32_t G[500]; EXPECT_GT((n = getgroups(ARRAYLEN(G), G)), 0); - if (getuid()) return; // this needs root + if (getuid()) + return; // this needs root EXPECT_SYS(0, 0, setgroups(n, G)); } diff --git a/test/libc/calls/getprogramexecutablename_test.c b/test/libc/calls/getprogramexecutablename_test.c index 671ca1add..cd5fb2a2b 100644 --- a/test/libc/calls/getprogramexecutablename_test.c +++ b/test/libc/calls/getprogramexecutablename_test.c @@ -103,7 +103,8 @@ TEST(GetProgramExecutableName, ofThisFile) { } TEST(GetProgramExecutableName, nullEnv) { - if (skiptests) return; + if (skiptests) + return; SPAWN(fork); execve(self, (char *[]){self, "Child", self, skiparg0 ? 0 : self, 0}, (char *[]){0}); @@ -112,7 +113,8 @@ TEST(GetProgramExecutableName, nullEnv) { } TEST(GetProramExecutableName, weirdArgv0NullEnv) { - if (skiptests) return; + if (skiptests) + return; SPAWN(fork); execve(self, (char *[]){"hello", "Child", self, skiparg0 ? 0 : "hello", 0}, (char *[]){0}); @@ -121,7 +123,8 @@ TEST(GetProramExecutableName, weirdArgv0NullEnv) { } TEST(GetProgramExecutableName, movedSelf) { - if (skiptests) return; + if (skiptests) + return; if (IsAarch64() && IsQemuUser()) { // clang-format off // TODO(mrdomino): fix: make -j8 m=aarch64 o/aarch64/test/libc/calls/getprogramexecutablename_test.ok diff --git a/test/libc/calls/getrandom_test.c b/test/libc/calls/getrandom_test.c index f3cfbc7ca..3e2386a7a 100644 --- a/test/libc/calls/getrandom_test.c +++ b/test/libc/calls/getrandom_test.c @@ -59,9 +59,11 @@ void *TortureWorker(void *arg) { ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &ss, 0)); ready = true; while (!done) { - if (!IsWindows()) pthread_kill(parent, SIGUSR1); + if (!IsWindows()) + pthread_kill(parent, SIGUSR1); usleep(1); - if (!IsWindows()) pthread_kill(parent, SIGUSR2); + if (!IsWindows()) + pthread_kill(parent, SIGUSR2); usleep(1); } return 0; @@ -78,9 +80,11 @@ TEST(getrandom, test) { if ((e = MeasureEntropy(buf, n)) < w) { fprintf(stderr, "error: entropy is suspect! got %g but want >=%g\n", e, w); for (i = 0; i < n;) { - if (!(i % 16)) fprintf(stderr, "%6x ", i); + if (!(i % 16)) + fprintf(stderr, "%6x ", i); fprintf(stderr, "%lc", kCp437[buf[i] & 255]); - if (!(++i % 16)) fprintf(stderr, "\n"); + if (!(++i % 16)) + fprintf(stderr, "\n"); } fprintf(stderr, "\n"); exit(1); @@ -100,7 +104,8 @@ TEST(getrandom, test2) { ASSERT_SYS(0, 0, sigaction(SIGUSR2, &sa, 0)); parent = pthread_self(); ASSERT_EQ(0, pthread_create(&child, 0, TortureWorker, 0)); - while (!ready) pthread_yield(); + while (!ready) + pthread_yield(); for (k = 0; k < 10; ++k) { ASSERT_SYS(0, 0, getrandom(0, 0, 0)); for (i = 0; i < n; i += m) { @@ -111,9 +116,11 @@ TEST(getrandom, test2) { if ((e = MeasureEntropy(buf, n)) < w) { fprintf(stderr, "error: entropy suspect! got %g but want >=%g\n", e, w); for (i = 0; i < n;) { - if (!(i % 16)) fprintf(stderr, "%6x ", i); + if (!(i % 16)) + fprintf(stderr, "%6x ", i); fprintf(stderr, "%lc", kCp437[buf[i] & 255]); - if (!(++i % 16)) fprintf(stderr, "\n"); + if (!(++i % 16)) + fprintf(stderr, "\n"); } fprintf(stderr, "\n"); done = true; @@ -123,7 +130,8 @@ TEST(getrandom, test2) { } done = true; ASSERT_EQ(0, pthread_join(child, 0)); - if (!IsWindows()) ASSERT_GT(gotsome, 0); + if (!IsWindows()) + ASSERT_GT(gotsome, 0); } /* JustReturnZero */ @@ -237,13 +245,15 @@ uint64_t SixthEditionLowByte(void) { uint64_t MobyDick(void) { static int i; - if ((i += 8) > kMobySize) i = 8; + if ((i += 8) > kMobySize) + i = 8; return READ64LE(kMoby + i); } uint64_t ExecutableImage(void) { static int i; - if ((i += 8) > _end - __executable_start) i = 8; + if ((i += 8) > _end - __executable_start) + i = 8; return READ64LE(__executable_start + i); } diff --git a/test/libc/calls/ioctl_test.c b/test/libc/calls/ioctl_test.c index 417be7519..0e3c38fd8 100644 --- a/test/libc/calls/ioctl_test.c +++ b/test/libc/calls/ioctl_test.c @@ -49,7 +49,8 @@ TEST(siocgifconf, test) { conf.ifc_len = n; ASSERT_NE(-1, ioctl(socketfd, SIOCGIFCONF, &conf)); for (ifr = (struct ifreq *)data; (char *)ifr < data + conf.ifc_len; ++ifr) { - if (ifr->ifr_addr.sa_family != AF_INET) continue; + if (ifr->ifr_addr.sa_family != AF_INET) + continue; ip = ntohl(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr); EXPECT_NE(-1, ioctl(socketfd, SIOCGIFNETMASK, ifr)); netmask = ntohl(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr); @@ -72,7 +73,8 @@ TEST(siocgifconf, test) { } TEST(siocgifconf, mkntenvblock_systemroot) { - if (__argc != 1) return; + if (__argc != 1) + return; SPAWN(fork); execve(GetProgramExecutableName(), (char *[]){GetProgramExecutableName(), "hi", NULL}, (char *[]){NULL}); diff --git a/test/libc/calls/lock_ofd_test.c b/test/libc/calls/lock_ofd_test.c index 1149fbeec..4b7081299 100644 --- a/test/libc/calls/lock_ofd_test.c +++ b/test/libc/calls/lock_ofd_test.c @@ -48,7 +48,8 @@ _Thread_local const char *kind; bool SupportsOfdLocks(void) { int e; bool r; - if (!IsLinux()) return false; + if (!IsLinux()) + return false; // F_OFD_* was introduced in linux 3.15 // getrandom() was introduced in linux 3.17 // testing for getrandom() should be a sure thing w/o creating an fd diff --git a/test/libc/calls/madvise_test.c b/test/libc/calls/madvise_test.c index d1eb03b5e..df18f103f 100644 --- a/test/libc/calls/madvise_test.c +++ b/test/libc/calls/madvise_test.c @@ -72,8 +72,10 @@ TEST(madvise, subPages) { TEST(madvise, misalign) { char *p; - if (!IsLinux()) return; // most platforms don't care - if (IsQemuUser()) return; // qemu claims to be linux but doesn't care + if (!IsLinux()) + return; // most platforms don't care + if (IsQemuUser()) + return; // qemu claims to be linux but doesn't care ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))); ASSERT_SYS(EINVAL, -1, madvise(p + 1, FRAMESIZE - 1, MADV_WILLNEED)); @@ -82,7 +84,8 @@ TEST(madvise, misalign) { TEST(madvise, badAdvice) { char *p; - if (IsAarch64() && IsQemuUser()) return; // qemu doesn't validate advice + if (IsAarch64() && IsQemuUser()) + return; // qemu doesn't validate advice ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))); ASSERT_SYS(EINVAL, -1, madvise(p, FRAMESIZE, 127)); @@ -90,8 +93,10 @@ TEST(madvise, badAdvice) { } TEST(madvise, missingMemory) { - if (!IsLinux()) return; // most platforms don't care - if (IsQemuUser()) return; // qemu claims to be linux but doesn't care + if (!IsLinux()) + return; // most platforms don't care + if (IsQemuUser()) + return; // qemu claims to be linux but doesn't care ASSERT_SYS(ENOMEM, -1, madvise((char *)0x83483838000, FRAMESIZE, MADV_WILLNEED)); } diff --git a/test/libc/calls/makedirs_test.c b/test/libc/calls/makedirs_test.c index 3c08e745f..1334be651 100644 --- a/test/libc/calls/makedirs_test.c +++ b/test/libc/calls/makedirs_test.c @@ -71,7 +71,9 @@ TEST(makedirs, test) { int i, n = 8; pthread_t *t = gc(malloc(sizeof(pthread_t) * n)); ASSERT_EQ(0, pthread_barrier_init(&barrier, 0, n)); - for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0)); - for (i = 0; i < n; ++i) EXPECT_EQ(0, pthread_join(t[i], 0)); + for (i = 0; i < n; ++i) + ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0)); + for (i = 0; i < n; ++i) + EXPECT_EQ(0, pthread_join(t[i], 0)); ASSERT_EQ(0, pthread_barrier_destroy(&barrier)); } diff --git a/test/libc/calls/mkdir_test.c b/test/libc/calls/mkdir_test.c index 9e278c4fe..3711b26fa 100644 --- a/test/libc/calls/mkdir_test.c +++ b/test/libc/calls/mkdir_test.c @@ -71,7 +71,8 @@ TEST(mkdir, enametoolong) { int i; size_t n = 2048; char *s = gc(calloc(1, n)); - for (i = 0; i < n - 1; ++i) s[i] = 'x'; + for (i = 0; i < n - 1; ++i) + s[i] = 'x'; s[i] = 0; EXPECT_SYS(ENAMETOOLONG, -1, mkdir(s, 0644)); } @@ -96,7 +97,8 @@ TEST(mkdirat, testRelativePath_opensRelativeToDirFd) { TEST(mkdir, longname) { int i; char *d, s[270] = {0}; - for (i = 0; i < sizeof(s) - 1; ++i) s[i] = 'x'; + for (i = 0; i < sizeof(s) - 1; ++i) + s[i] = 'x'; s[i] = 0; ASSERT_NE(NULL, (d = gc(getcwd(0, 0)))); memcpy(s, d, strlen(d)); diff --git a/test/libc/calls/open_test.c b/test/libc/calls/open_test.c index dcdec159f..4f1013a7b 100644 --- a/test/libc/calls/open_test.c +++ b/test/libc/calls/open_test.c @@ -47,7 +47,8 @@ void SetUpOnce(void) { TEST(open, efault) { ASSERT_SYS(EFAULT, -1, open(0, O_RDONLY)); - if (IsWindows() || !IsAsan()) return; // not possible + if (IsWindows() || !IsAsan()) + return; // not possible ASSERT_SYS(EFAULT, -1, open((void *)77, O_RDONLY)); } @@ -231,7 +232,8 @@ TEST(open, norm) { } TEST(open, longNormDot) { - if (IsWindows()) return; // todo: why won't long paths work on windows + if (IsWindows()) + return; // todo: why won't long paths work on windows #define NAME \ "funfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfu" \ "nfunfunfunfunfunfunnfunfunfunfunfunfunnfunfunfunfunfunfununfunfunfunfunfun" @@ -243,7 +245,8 @@ TEST(open, longNormDot) { } TEST(open, longNormDotDot) { - if (IsWindows()) return; // todo: why won't long paths work on windows + if (IsWindows()) + return; // todo: why won't long paths work on windows #define NAME \ "funfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfu" \ "nfunfunfunfunfunfunnfunfunfunfunfunfunnfunfunfunfunfunfununfunfunfunfunfun" @@ -258,7 +261,8 @@ TEST(open, longNormDotDot) { TEST(open, creat_directory) { ASSERT_SYS(ENOENT, -1, open("fun", O_WRONLY | O_DIRECTORY)); ASSERT_FALSE(fileexists("fun")); - if (1) return; // linux 5.15.122-0-lts creates file and returns error D: + if (1) + return; // linux 5.15.122-0-lts creates file and returns error D: ASSERT_SYS(ENOTDIR, -1, open("fun", O_CREAT | O_WRONLY | O_DIRECTORY, 0644)); ASSERT_TRUE(fileexists("fun")); } @@ -312,7 +316,8 @@ int CountFds(void) { } TEST(open, lotsOfFds) { - if (!IsWindows()) return; + if (!IsWindows()) + return; int i, n = 200; ASSERT_SYS(0, 0, xbarf("hello.txt", "hello", -1)); for (i = 3; i < n; ++i) { @@ -331,7 +336,8 @@ static int64_t GetInode(const char *path) { } TEST(open, drive) { - if (!IsWindows()) return; + if (!IsWindows()) + return; ASSERT_NE(GetInode("/"), GetInode(".")); ASSERT_EQ(GetInode("/"), GetInode("/c")); // sorry you have to run on c:/ ASSERT_EQ(GetInode("/"), GetInode("/c/")); @@ -430,7 +436,8 @@ TEST(open, creatRdonly) { } TEST(open, sequentialRandom_EINVAL) { - if (!IsWindows()) return; + if (!IsWindows()) + return; ASSERT_SYS( EINVAL, -1, open("foo", O_CREAT | O_TRUNC | O_RDWR | O_SEQUENTIAL | O_RANDOM, 0700)); @@ -442,7 +449,8 @@ TEST(open, sequentialRandom_EINVAL) { // timestamps of the file and the last data modification and last // file status change timestamps of the parent directory." -POSIX TEST(open, creatFile_touchesDirectory) { - if (1) return; // TODO(jart): explain the rare flakes + if (1) + return; // TODO(jart): explain the rare flakes struct stat st; struct timespec birth; ASSERT_SYS(0, 0, mkdir("dir", 0755)); diff --git a/test/libc/calls/openatemp_test.c b/test/libc/calls/openatemp_test.c index 4ebf17b90..5269910b2 100644 --- a/test/libc/calls/openatemp_test.c +++ b/test/libc/calls/openatemp_test.c @@ -50,7 +50,8 @@ TEST(openatemp, unlink) { } TEST(openatemp, mode) { - if (IsWindows()) return; + if (IsWindows()) + return; unsigned omask = umask(0); char path[] = "foo.XXXXXX"; ASSERT_SYS(0, 3, openatemp(AT_FDCWD, path, 0, 0, 0764)); diff --git a/test/libc/calls/openbsd_test.c b/test/libc/calls/openbsd_test.c index 5ab15decc..512ccae79 100644 --- a/test/libc/calls/openbsd_test.c +++ b/test/libc/calls/openbsd_test.c @@ -26,8 +26,10 @@ #include "libc/testlib/testlib.h" void CheckPlatform(void) { - if (IsOpenbsd()) return; // openbsd is ok - if (IsLinux() && __is_linux_2_6_23()) return; // non-ancient linux is ok + if (IsOpenbsd()) + return; // openbsd is ok + if (IsLinux() && __is_linux_2_6_23()) + return; // non-ancient linux is ok kprintf("skipping openbsd_test\n"); exit(0); } diff --git a/test/libc/calls/pipe_test.c b/test/libc/calls/pipe_test.c index c11df66af..fd89433c6 100644 --- a/test/libc/calls/pipe_test.c +++ b/test/libc/calls/pipe_test.c @@ -38,8 +38,10 @@ TEST(pipe, einval) { } TEST(pipe, ebadf) { - if (IsFreebsd()) return; // somehow succeeds - if (IsOpenbsd()) return; // somehow succeeds + if (IsFreebsd()) + return; // somehow succeeds + if (IsOpenbsd()) + return; // somehow succeeds EXPECT_SYS(0, 0, pipe(f)); EXPECT_SYS(EBADF, -1, write(f[0], "h", 1)); EXPECT_SYS(EBADF, -1, read(f[1], buf, 1)); @@ -48,8 +50,10 @@ TEST(pipe, ebadf) { } TEST(pipe, emfile) { - if (IsWindows()) return; // TODO - if (IsCygwin()) return; + if (IsWindows()) + return; // TODO + if (IsCygwin()) + return; ASSERT_NE(-1, (pid = fork())); if (!pid) { ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlim)); diff --git a/test/libc/calls/pledge2_test.c b/test/libc/calls/pledge2_test.c index 5bb0e1d52..e5d16dbea 100644 --- a/test/libc/calls/pledge2_test.c +++ b/test/libc/calls/pledge2_test.c @@ -41,7 +41,8 @@ void SetUp(void) { } TEST(pledge, testSoftError) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; SPAWN(fork); __pledge_mode = PLEDGE_PENALTY_RETURN_EPERM; ASSERT_SYS(0, 0, pledge("stdio", 0)); @@ -67,7 +68,8 @@ TEST(pledge, testKillProcessMode) { } TEST(pledge, testLogMessage_inSoftyMode) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; int fds[2]; char msg[256] = {0}; ASSERT_SYS(0, 0, pipe(fds)); diff --git a/test/libc/calls/pledge_test.c b/test/libc/calls/pledge_test.c index a9a160392..8bb59a845 100644 --- a/test/libc/calls/pledge_test.c +++ b/test/libc/calls/pledge_test.c @@ -103,7 +103,8 @@ TEST(pledge, default_allowsExit) { } TEST(pledge, execpromises_notok) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -134,7 +135,8 @@ TEST(pledge, tester) { } TEST(pledge, withThreadMemory) { - if (IsOpenbsd()) return; // openbsd doesn't allow it, wisely + if (IsOpenbsd()) + return; // openbsd doesn't allow it, wisely pthread_t worker; int job[2] = {2, 2}; // create workload ASSERT_EQ(0, pthread_create(&worker, 0, Enclave, job)); // create worker @@ -159,7 +161,8 @@ void *TgkillWorker(void *arg) { TEST(pledge, tgkill) { // https://github.com/jart/cosmopolitan/issues/628 - if (!IsLinux()) return; + if (!IsLinux()) + return; sigset_t mask; pthread_t worker; SPAWN(fork); @@ -176,7 +179,8 @@ TEST(pledge, tgkill) { } TEST(pledge, stdio_forbidsOpeningPasswd1) { - if (!IsLinux()) return; + if (!IsLinux()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -204,7 +208,8 @@ TEST(pledge, stdio_forbidsOpeningPasswd2) { } TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive1) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -223,7 +228,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive1) { } TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive2) { - if (!IsOpenbsd()) return; + if (!IsOpenbsd()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -237,7 +243,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive2) { } TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive3) { - if (!IsOpenbsd()) return; + if (!IsOpenbsd()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -252,7 +259,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive3) { } TEST(pledge, stdio_fcntl_allowsSomeFirstArgs) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; struct flock lk; ASSERT_NE(-1, (pid = fork())); @@ -275,7 +283,8 @@ TEST(pledge, stdio_fcntl_allowsSomeFirstArgs) { } TEST(pledge, stdioTty_sendtoRestricted_requiresNullAddr) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid, sv[2]; ASSERT_SYS(0, 0, socketpair(AF_UNIX, SOCK_STREAM, 0, sv)); ASSERT_NE(-1, (pid = fork())); @@ -303,7 +312,8 @@ TEST(pledge, stdioTty_sendtoRestricted_requiresNullAddr) { } TEST(pledge, unix_forbidsInetSockets) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -345,7 +355,8 @@ TEST(pledge, wpath_doesNotImplyRpath) { } TEST(pledge, inet_forbidsOtherSockets) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid, yes = 1; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -376,7 +387,8 @@ TEST(pledge, inet_forbidsOtherSockets) { } TEST(pledge, anet_forbidsUdpSocketsAndConnect) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -392,7 +404,8 @@ TEST(pledge, anet_forbidsUdpSocketsAndConnect) { } TEST(pledge, mmap) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf char *p; int ws, pid; ASSERT_NE(-1, (pid = fork())); @@ -413,7 +426,8 @@ TEST(pledge, mmap) { } TEST(pledge, mmapProtExec) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf char *p; int ws, pid; ASSERT_NE(-1, (pid = fork())); @@ -432,7 +446,8 @@ TEST(pledge, mmapProtExec) { } TEST(pledge, chmod_ignoresDangerBits) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_SYS(0, 3, creat("foo", 0644)); ASSERT_NE(-1, (pid = fork())); @@ -452,7 +467,8 @@ TEST(pledge, chmod_ignoresDangerBits) { } TEST(pledge, open_rpath) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_SYS(0, 0, touch("foo", 0644)); ASSERT_NE(-1, (pid = fork())); @@ -470,7 +486,8 @@ TEST(pledge, open_rpath) { } TEST(pledge, open_wpath) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_SYS(0, 0, touch("foo", 0644)); ASSERT_NE(-1, (pid = fork())); @@ -487,7 +504,8 @@ TEST(pledge, open_wpath) { } TEST(pledge, open_cpath) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; struct stat st; ASSERT_SYS(0, 0, touch("foo", 0644)); @@ -508,7 +526,8 @@ TEST(pledge, open_cpath) { } TEST(pledge, execpromises_ok) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -522,7 +541,8 @@ TEST(pledge, execpromises_ok) { } TEST(pledge, execpromises_notok1) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -536,7 +556,8 @@ TEST(pledge, execpromises_notok1) { } TEST(pledge, execpromises_reducesAtExecOnLinux) { - if (IsOpenbsd()) return; // b/c testing linux bpf + if (IsOpenbsd()) + return; // b/c testing linux bpf int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -550,8 +571,10 @@ TEST(pledge, execpromises_reducesAtExecOnLinux) { } TEST(pledge_openbsd, execpromisesIsNull_letsItDoAnything) { - if (IsOpenbsd()) return; // mimmutable() ugh - if (!IsOpenbsd()) return; + if (IsOpenbsd()) + return; // mimmutable() ugh + if (!IsOpenbsd()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -567,8 +590,10 @@ TEST(pledge_openbsd, execpromisesIsNull_letsItDoAnything) { } TEST(pledge_openbsd, execpromisesIsSuperset_letsItDoAnything) { - if (IsOpenbsd()) return; // mimmutable() ugh - if (!IsOpenbsd()) return; + if (IsOpenbsd()) + return; // mimmutable() ugh + if (!IsOpenbsd()) + return; int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -582,12 +607,14 @@ TEST(pledge_openbsd, execpromisesIsSuperset_letsItDoAnything) { } TEST(pledge_linux, execpromisesIsSuperset_notPossible) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; ASSERT_SYS(EINVAL, -1, pledge("stdio exec", "stdio inet exec")); } TEST(pledge_openbsd, execpromises_notok) { - if (IsOpenbsd()) return; // mimmutable() ugh + if (IsOpenbsd()) + return; // mimmutable() ugh int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { @@ -608,7 +635,8 @@ TEST(pledge_openbsd, execpromises_notok) { } TEST(pledge_openbsd, bigSyscalls) { - if (IsOpenbsd()) return; // testing lunix + if (IsOpenbsd()) + return; // testing lunix int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { diff --git a/test/libc/calls/poll_test.c b/test/libc/calls/poll_test.c index 97e7b2202..ee844762b 100644 --- a/test/libc/calls/poll_test.c +++ b/test/libc/calls/poll_test.c @@ -66,8 +66,10 @@ TEST(poll, allZero_doesNothingPrettyMuch) { } TEST(ppoll, weCanProveItChecksForSignals) { - if (IsXnu()) return; - if (IsNetbsd()) return; + if (IsXnu()) + return; + if (IsNetbsd()) + return; int pipefds[2]; sigset_t set, old; struct sigaction oldss; diff --git a/test/libc/calls/posix_fadvise_test.c b/test/libc/calls/posix_fadvise_test.c index 69e3c31ca..1da060333 100644 --- a/test/libc/calls/posix_fadvise_test.c +++ b/test/libc/calls/posix_fadvise_test.c @@ -31,7 +31,8 @@ void SetUpOnce(void) { } void SetUp(void) { - if (IsOpenbsd() || IsXnu()) exit(0); + if (IsOpenbsd() || IsXnu()) + exit(0); } TEST(fadvise, ebadf) { diff --git a/test/libc/calls/read_test.c b/test/libc/calls/read_test.c index 39e764d38..ce0a11bea 100644 --- a/test/libc/calls/read_test.c +++ b/test/libc/calls/read_test.c @@ -78,7 +78,8 @@ TEST(read_pipe, canBeInterruptedByAlarm) { TEST(read_directory, eisdir) { // TODO(jart): what - if (IsWindows() || IsFreebsd()) return; + if (IsWindows() || IsFreebsd()) + return; ASSERT_SYS(0, 0, mkdir("boop", 0755)); ASSERT_SYS(0, 3, open("boop", O_RDONLY | O_DIRECTORY)); ASSERT_SYS(EISDIR, -1, read(3, 0, 0)); @@ -102,7 +103,8 @@ void *GenerateData(void *arg) { for (;;) { usleep(223); int rc = write(fds[1], "hi", 2); - if (rc == -1 && errno == EPIPE) break; + if (rc == -1 && errno == EPIPE) + break; ASSERT_EQ(2, rc); } return 0; diff --git a/test/libc/calls/readlinkat_test.c b/test/libc/calls/readlinkat_test.c index 0d3d5a4a3..484db44b9 100644 --- a/test/libc/calls/readlinkat_test.c +++ b/test/libc/calls/readlinkat_test.c @@ -105,8 +105,10 @@ TEST(readlinkat, statReadsNameLength_countsUtf8Bytes) { TEST(readlinkat, realpathReturnsLongPath) { char buf[PATH_MAX]; - if (!IsWindows()) return; - if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return; + if (!IsWindows()) + return; + if (!startswith(getcwd(buf, PATH_MAX), "/c/")) + return; ASSERT_SYS(0, 0, touch("froot", 0644)); ASSERT_STARTSWITH("/c/", realpath("froot", buf)); } diff --git a/test/libc/calls/renameat_test.c b/test/libc/calls/renameat_test.c index ba8e3f9e6..507c55adc 100644 --- a/test/libc/calls/renameat_test.c +++ b/test/libc/calls/renameat_test.c @@ -90,13 +90,17 @@ TEST(rename, enotempty) { TEST(rename, moveIntoNonWritableDirectory_raisesEacces) { // old versions of linux allow this // new versions of linux report exdev?! - if (IsLinux()) return; + if (IsLinux()) + return; // netbsd and openbsd allow this - if (IsNetbsd() || IsOpenbsd()) return; + if (IsNetbsd() || IsOpenbsd()) + return; // windows doesn't really have permissions - if (IsWindows()) return; + if (IsWindows()) + return; // looks like a freebsd kernel bug - if (IsAarch64() && IsFreebsd()) return; + if (IsAarch64() && IsFreebsd()) + return; // posix specifies this behavior ASSERT_SYS(0, 0, mkdir("foo", 0111)); ASSERT_SYS(0, 0, touch("lol", 0644)); diff --git a/test/libc/calls/sched_setscheduler_test.c b/test/libc/calls/sched_setscheduler_test.c index 91ce0e541..3cc1e9315 100644 --- a/test/libc/calls/sched_setscheduler_test.c +++ b/test/libc/calls/sched_setscheduler_test.c @@ -65,7 +65,8 @@ TEST(sched_setscheduler, test) { } TEST(sched_setscheduler, testMidpoint) { - if (!CanTuneRealtimeSchedulers()) return; + if (!CanTuneRealtimeSchedulers()) + return; struct sched_param p = {(sched_get_priority_min(SCHED_FIFO) + sched_get_priority_max(SCHED_FIFO)) / 2}; diff --git a/test/libc/calls/setrlimit_test.c b/test/libc/calls/setrlimit_test.c index 744f835b5..aa8749575 100644 --- a/test/libc/calls/setrlimit_test.c +++ b/test/libc/calls/setrlimit_test.c @@ -61,9 +61,12 @@ TEST(setrlimit, testCpuLimit) { struct rlimit rlim; struct timespec start; double matrices[3][3][3]; - if (IsWindows()) return; // of course it doesn't work on windows - if (IsXnu()) return; // TODO(jart): it worked before - if (IsOpenbsd()) return; // TODO(jart): fix flake + if (IsWindows()) + return; // of course it doesn't work on windows + if (IsXnu()) + return; // TODO(jart): it worked before + if (IsOpenbsd()) + return; // TODO(jart): fix flake ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, xsigaction(SIGXCPU, OnSigxcpu, 0, 0, 0)); @@ -89,7 +92,8 @@ TEST(setrlimit, testFileSizeLimit) { char junkdata[512]; int i, fd, wstatus; struct rlimit rlim; - if (IsWindows()) return; /* of course it doesn't work on windows */ + if (IsWindows()) + return; /* of course it doesn't work on windows */ ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, xsigaction(SIGXFSZ, OnSigxfsz, 0, 0, 0)); @@ -125,8 +129,10 @@ TEST(setrlimit, testMemoryLimit) { char *p; bool gotsome; int i, wstatus; - if (IsXnu()) return; - if (IsAsan()) return; /* b/c we use sys_mmap */ + if (IsXnu()) + return; + if (IsAsan()) + return; /* b/c we use sys_mmap */ ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM)); @@ -156,10 +162,14 @@ TEST(setrlimit, testMemoryLimit) { TEST(setrlimit, testVirtualMemoryLimit) { char *p; int i, wstatus; - if (IsAsan()) return; - if (IsXnu()) return; /* doesn't work on darwin */ - if (IsOpenbsd()) return; /* unavailable on openbsd */ - if (IsWindows()) return; /* of course it doesn't work on windows */ + if (IsAsan()) + return; + if (IsXnu()) + return; /* doesn't work on darwin */ + if (IsOpenbsd()) + return; /* unavailable on openbsd */ + if (IsWindows()) + return; /* of course it doesn't work on windows */ ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, setrlimit(RLIMIT_AS, &(struct rlimit){MEM, MEM})); @@ -184,12 +194,18 @@ TEST(setrlimit, testVirtualMemoryLimit) { TEST(setrlimit, testDataMemoryLimit) { char *p; int i, wstatus; - if (IsAsan()) return; - if (IsXnu()) return; /* doesn't work on darwin */ - if (IsNetbsd()) return; /* doesn't work on netbsd */ - if (IsFreebsd()) return; /* doesn't work on freebsd */ - if (IsLinux()) return; /* doesn't work on gnu/systemd */ - if (IsWindows()) return; /* of course it doesn't work on windows */ + if (IsAsan()) + return; + if (IsXnu()) + return; /* doesn't work on darwin */ + if (IsNetbsd()) + return; /* doesn't work on netbsd */ + if (IsFreebsd()) + return; /* doesn't work on freebsd */ + if (IsLinux()) + return; /* doesn't work on gnu/systemd */ + if (IsWindows()) + return; /* of course it doesn't work on windows */ ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, setrlimit(RLIMIT_DATA, &(struct rlimit){MEM, MEM})); @@ -231,7 +247,8 @@ wontreturn void OnVfork(void *ctx) { TEST(setrlimit, isVforkSafe) { int ws; struct rlimit rlim[2]; - if (IsWindows()) return; /* of course it doesn't work on windows */ + if (IsWindows()) + return; /* of course it doesn't work on windows */ ASSERT_EQ(0, getrlimit(RLIMIT_CPU, rlim)); ASSERT_NE(-1, (ws = xvspawn(OnVfork, rlim, 0))); EXPECT_TRUE(WIFEXITED(ws)); diff --git a/test/libc/calls/shm_open_test.c b/test/libc/calls/shm_open_test.c index 255329df5..da7909fef 100644 --- a/test/libc/calls/shm_open_test.c +++ b/test/libc/calls/shm_open_test.c @@ -90,7 +90,8 @@ wontreturn void Bouncer(void) { wontreturn void Sender(void) { /* Wait for file to exist. */ - while (!*ready) donothing; + while (!*ready) + donothing; /* Open the existing shared memory object and map it into the caller's address space. */ diff --git a/test/libc/calls/sig_test.c b/test/libc/calls/sig_test.c index 1c33d87bf..080406d86 100644 --- a/test/libc/calls/sig_test.c +++ b/test/libc/calls/sig_test.c @@ -64,9 +64,11 @@ void *Worker(void *arg) { TEST(SetThreadContext, test) { pthread_t th; - if (!IsWindows()) return; + if (!IsWindows()) + return; ASSERT_EQ(0, pthread_create(&th, 0, Worker, 0)); - while (!ready) donothing; + while (!ready) + donothing; usleep(1000); int64_t hand = _pthread_syshand((struct PosixThread *)th); ASSERT_EQ(0, SuspendThread(hand)); diff --git a/test/libc/calls/sigaction_test.c b/test/libc/calls/sigaction_test.c index 33cfcdc3b..f093bd24b 100644 --- a/test/libc/calls/sigaction_test.c +++ b/test/libc/calls/sigaction_test.c @@ -124,7 +124,8 @@ TEST(sigaction, raise) { // test kill() TEST(sigaction, testPingPongParentChildWithSigint) { - if (IsNetbsd()) return; // TODO: what's up with runitd on netbsd? + if (IsNetbsd()) + return; // TODO: what's up with runitd on netbsd? int pid, status; sigset_t blockint, oldmask; struct sigaction oldint; @@ -244,8 +245,10 @@ TEST(sigaction, ignoringSignalDiscardsSignal) { } TEST(sigaction, autoZombieSlayer) { - if (IsWindows()) return; - if (IsCygwin()) return; + if (IsWindows()) + return; + if (IsCygwin()) + return; int pid; struct sigaction sa; // make sure we're starting in expected state @@ -253,7 +256,8 @@ TEST(sigaction, autoZombieSlayer) { ASSERT_EQ(SIG_DFL, sa.sa_handler); // verify child becomes zombie ASSERT_NE(-1, (pid = fork())); - if (!pid) _Exit(0); + if (!pid) + _Exit(0); ASSERT_SYS(0, pid, wait(0)); // enable automatic zombie slayer sa.sa_handler = SIG_IGN; @@ -262,17 +266,21 @@ TEST(sigaction, autoZombieSlayer) { ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, &sa)); // verify it works ASSERT_NE(-1, (pid = fork())); - if (!pid) _Exit(0); + if (!pid) + _Exit(0); // XXX: WSL does the wrong thing here. - if (__iswsl1()) usleep(10); + if (__iswsl1()) + usleep(10); ASSERT_SYS(ECHILD, -1, wait(0)); // clean up ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, 0)); } TEST(sigaction, enosys_returnsErrnoRatherThanSigsysByDefault) { - if (IsTiny()) return; // systemfive.S disables the fix w/ tiny - if (IsOpenbsd()) return; // TODO: Why does OpenBSD raise SIGABRT? + if (IsTiny()) + return; // systemfive.S disables the fix w/ tiny + if (IsOpenbsd()) + return; // TODO: Why does OpenBSD raise SIGABRT? ASSERT_SYS(ENOSYS, -1, sys_bogus()); } @@ -373,7 +381,8 @@ dontubsan dontasan int Segfault(char *p) { int (*pSegfault)(char *) = Segfault; TEST(sigaction, returnFromSegvHandler_loopsForever) { - if (IsXnu()) return; // seems busted + if (IsXnu()) + return; // seems busted segfaults = _mapshared(sizeof(*segfaults)); SPAWN(fork); signal(SIGSEGV, OnSegfault); diff --git a/test/libc/calls/sigtimedwait_test.c b/test/libc/calls/sigtimedwait_test.c index d6260f302..c45b735e3 100644 --- a/test/libc/calls/sigtimedwait_test.c +++ b/test/libc/calls/sigtimedwait_test.c @@ -30,10 +30,14 @@ #include "libc/testlib/testlib.h" void SetUp(void) { - if (IsXnu()) exit(0); - if (IsMetal()) exit(0); - if (IsWindows()) exit(0); - if (IsOpenbsd()) exit(0); + if (IsXnu()) + exit(0); + if (IsMetal()) + exit(0); + if (IsWindows()) + exit(0); + if (IsOpenbsd()) + exit(0); } TEST(sigtimedwait, nullSet_efault) { diff --git a/test/libc/calls/stackoverflow1_test.c b/test/libc/calls/stackoverflow1_test.c index 080e3b76d..88b6fff9d 100644 --- a/test/libc/calls/stackoverflow1_test.c +++ b/test/libc/calls/stackoverflow1_test.c @@ -91,7 +91,8 @@ int StackOverflow(int f(), int n) { int (*pStackOverflow)(int (*)(), int) = StackOverflow; TEST(stackoverflow, standardStack_altStack_process_longjmp) { - if (IsTiny()) return; // TODO(jart): why? + if (IsTiny()) + return; // TODO(jart): why? int jumpcode; if (!(jumpcode = setjmp(recover))) { diff --git a/test/libc/calls/timespec_test.c b/test/libc/calls/timespec_test.c index 0019d7c0c..930116d93 100644 --- a/test/libc/calls/timespec_test.c +++ b/test/libc/calls/timespec_test.c @@ -94,7 +94,8 @@ TEST(timeval_toseconds, test) { } static long mod(long x, long y) { - if (y == -1) return 0; + if (y == -1) + return 0; return x - y * (x / y - (x % y && (x ^ y) < 0)); } diff --git a/test/libc/calls/unlinkat_test.c b/test/libc/calls/unlinkat_test.c index eacf704d6..99511f48d 100644 --- a/test/libc/calls/unlinkat_test.c +++ b/test/libc/calls/unlinkat_test.c @@ -30,7 +30,8 @@ void SetUpOnce(void) { TEST(unlink, efault) { ASSERT_SYS(EFAULT, -1, unlink(0)); - if (IsWindows() || !IsAsan()) return; // not possible + if (IsWindows() || !IsAsan()) + return; // not possible ASSERT_SYS(EFAULT, -1, unlink((void *)77)); } diff --git a/test/libc/calls/unveil_test.c b/test/libc/calls/unveil_test.c index b252fd8ce..6681eec8d 100644 --- a/test/libc/calls/unveil_test.c +++ b/test/libc/calls/unveil_test.c @@ -94,7 +94,8 @@ TEST(unveil, api_differences) { } TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) { - if (IsOpenbsd()) return; // TOOD(jart): why pledge violation? + if (IsOpenbsd()) + return; // TOOD(jart): why pledge violation? SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); testlib_extract("/zip/life.elf", "folder/life.elf", 0755); @@ -151,7 +152,8 @@ TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) { } TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) { - if (IsOpenbsd()) return; // TOOD(jart): why pledge violation? + if (IsOpenbsd()) + return; // TOOD(jart): why pledge violation? SPAWN(fork); ASSERT_SYS(0, 0, mkdir("folder", 0755)); ASSERT_SYS(0, 0, unveil("folder", "rwcx")); @@ -179,7 +181,8 @@ TEST(unveil, dirfdHacking_doesntWork) { } TEST(unveil, mostRestrictivePolicy) { - if (IsOpenbsd()) return; // openbsd behaves oddly; see docs + if (IsOpenbsd()) + return; // openbsd behaves oddly; see docs SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, mkdir("garden", 0755)); @@ -221,7 +224,8 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) { } TEST(unveil, usedTwice_allowedOnLinux) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, xbarf("jail/ok.txt", "hello", 5)); @@ -259,7 +263,8 @@ TEST(unveil, truncate_isForbiddenBySeccomp) { } TEST(unveil, ftruncate_isForbidden) { - if (IsOpenbsd()) return; // b/c O_PATH is a Linux thing + if (IsOpenbsd()) + return; // b/c O_PATH is a Linux thing SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, mkdir("garden", 0755)); @@ -275,7 +280,8 @@ TEST(unveil, ftruncate_isForbidden) { } TEST(unveil, procfs_isForbiddenByDefault) { - if (IsOpenbsd()) return; + if (IsOpenbsd()) + return; SPAWN(fork); ASSERT_SYS(0, 0, mkdir("jail", 0755)); ASSERT_SYS(0, 0, unveil("jail", "rw")); diff --git a/test/libc/calls/utimensat_test.c b/test/libc/calls/utimensat_test.c index 8595700f7..583f2e67f 100644 --- a/test/libc/calls/utimensat_test.c +++ b/test/libc/calls/utimensat_test.c @@ -58,7 +58,8 @@ TEST(utimes, test) { } TEST(futimes, test) { - if (IsLinux() && !__is_linux_2_6_23()) return; + if (IsLinux() && !__is_linux_2_6_23()) + return; struct stat st; struct timeval tv[2] = {{1655455857, 1}, {827727928, 2}}; EXPECT_SYS(0, 3, creat("boop", 0644)); @@ -123,7 +124,8 @@ TEST(utimensat, testOmit) { TEST(futimens, test2) { struct timespec ts[2]; int fd = creat("foo", 0600); - if (fd < 0) exit(1); + if (fd < 0) + exit(1); struct stat st; int64_t birth; ASSERT_SYS(0, 0, fstat(fd, &st)); diff --git a/test/libc/calls/write_test.c b/test/libc/calls/write_test.c index df8567f98..77ddfd9a1 100644 --- a/test/libc/calls/write_test.c +++ b/test/libc/calls/write_test.c @@ -66,7 +66,8 @@ TEST(write, readOnlyFd_ebadf) { TEST(write, badMemory_efault) { ASSERT_SYS(EFAULT, -1, write(1, 0, 1)); - if (!IsAsan()) return; + if (!IsAsan()) + return; ASSERT_SYS(EFAULT, -1, write(1, (void *)1, 1)); } @@ -109,7 +110,8 @@ TEST(write, brokenPipe_sigpipeBlocked_returnsEpipe) { } TEST(write, rlimitFsizeExceeded_raisesEfbig) { - if (IsWindows()) return; // not supported + if (IsWindows()) + return; // not supported struct rlimit rl = {1, 10}; SPAWN(fork); signal(SIGXFSZ, SIG_IGN); diff --git a/test/libc/calls/writev_test.c b/test/libc/calls/writev_test.c index c045cd7ec..796d9ff59 100644 --- a/test/libc/calls/writev_test.c +++ b/test/libc/calls/writev_test.c @@ -52,7 +52,8 @@ TEST(writev, negative_einvalOrEfault) { } TEST(writev, exceedsIovMax_einval) { - if (IsWindows()) return; // it's complicated + if (IsWindows()) + return; // it's complicated int i, n = IOV_MAX + 1; struct iovec *v = gc(malloc(sizeof(struct iovec) * n)); for (i = 0; i < n; ++i) { @@ -96,7 +97,8 @@ TEST(writev, big_fullCompletion) { } TEST(writev, asanError_efaults) { - if (!IsAsan()) return; + if (!IsAsan()) + return; void *malloc_(size_t) asm("malloc"); void free_(void *) asm("free"); void *p; diff --git a/test/libc/intrin/kprintf_test.c b/test/libc/intrin/kprintf_test.c index f091d48b0..97e5ebdda 100644 --- a/test/libc/intrin/kprintf_test.c +++ b/test/libc/intrin/kprintf_test.c @@ -43,7 +43,8 @@ */ static uint64_t Rando(void) { uint64_t x; - do x = lemur64(); + do + x = lemur64(); while (((x ^ READ64LE("!!!!!!!!")) - 0x0101010101010101) & ~(x ^ READ64LE("!!!!!!!!")) & 0x8080808080808080); return x; @@ -247,11 +248,15 @@ TEST(kprintf, testFailure_wontClobberErrnoAndBypassesSystemCallSupport) { ASSERT_EQ(0, errno); EXPECT_SYS(0, 3, dup(2)); // - if (close(2)) _Exit(200); + if (close(2)) + _Exit(200); n = __syscount; - if (__syscount != n) _Exit(201); - if (errno != 0) _Exit(202); - if (dup2(3, 2) != 2) _Exit(203); + if (__syscount != n) + _Exit(201); + if (errno != 0) + _Exit(202); + if (dup2(3, 2) != 2) + _Exit(203); // EXPECT_SYS(0, 0, close(3)); } diff --git a/test/libc/intrin/lock_test.c b/test/libc/intrin/lock_test.c index e58a6aba6..491700d38 100644 --- a/test/libc/intrin/lock_test.c +++ b/test/libc/intrin/lock_test.c @@ -132,7 +132,8 @@ void TestContendedLock(const char *name, int kind) { kprintf("clone failed: %s\n", strerror(rc)); _Exit(1); } - while (!atomic_load(&ready)) donothing; + while (!atomic_load(&ready)) + donothing; t1 = timespec_real(); for (i = 0; i < n; ++i) { ASSERT_EQ(0, pthread_mutex_lock(&mu)); @@ -142,7 +143,8 @@ void TestContendedLock(const char *name, int kind) { ASSERT_EQ(0, pthread_mutex_unlock(&mu)); } t2 = timespec_real(); - while (tib.tib_tid) donothing; + while (tib.tib_tid) + donothing; ASSERT_EQ(1, atomic_load(&success)); ASSERT_EQ(0, atomic_load(&counter)); FreeCosmoStack(stk); @@ -178,7 +180,8 @@ int main(int argc, char *argv[]) { #ifdef __aarch64__ // our usage of raw clone() is probably broken in aarch64 // we should just get rid of clone() - if (1) return 0; + if (1) + return 0; #endif if (_weaken(nsync_mu_lock)) { diff --git a/test/libc/intrin/memcmp_test.c b/test/libc/intrin/memcmp_test.c index 1fed4eb29..10a9d7891 100644 --- a/test/libc/intrin/memcmp_test.c +++ b/test/libc/intrin/memcmp_test.c @@ -68,8 +68,10 @@ TEST(memcmp, hug) { static int coerce(int result) { #ifdef __aarch64__ // arm's strcmp assembly is nuts and unpredictable, but it's legal - if (result < 0) return -1; - if (result > 0) return +1; + if (result < 0) + return -1; + if (result > 0) + return +1; return 0; #else return result; diff --git a/test/libc/intrin/memset_test.c b/test/libc/intrin/memset_test.c index 5a2f5194d..056e05b34 100644 --- a/test/libc/intrin/memset_test.c +++ b/test/libc/intrin/memset_test.c @@ -27,8 +27,10 @@ static dontasan void *golden(void *p, int c, size_t n) { size_t i; - if (IsAsan()) __asan_verify(p, n); - for (i = 0; i < n; ++i) ((char *)p)[i] = c; + if (IsAsan()) + __asan_verify(p, n); + for (i = 0; i < n; ++i) + ((char *)p)[i] = c; return p; } diff --git a/test/libc/intrin/pthread_mutex_lock2_test.c b/test/libc/intrin/pthread_mutex_lock2_test.c index 1b0a3279a..93224da84 100644 --- a/test/libc/intrin/pthread_mutex_lock2_test.c +++ b/test/libc/intrin/pthread_mutex_lock2_test.c @@ -175,9 +175,11 @@ struct MutexContentionArgs { void *MutexContentionWorker(void *arg) { struct MutexContentionArgs *a = arg; while (!atomic_load_explicit(&a->done, memory_order_relaxed)) { - if (pthread_mutex_lock(a->mutex)) notpossible; + if (pthread_mutex_lock(a->mutex)) + notpossible; atomic_store_explicit(&a->ready, 1, memory_order_relaxed); - if (pthread_mutex_unlock(a->mutex)) notpossible; + if (pthread_mutex_unlock(a->mutex)) + notpossible; } return 0; } @@ -204,7 +206,8 @@ BENCH(pthread_mutex_lock, bench_contended) { pthread_spinlock_t s = {0}; struct SpinContentionArgs a = {&s}; pthread_create(&t, 0, SpinContentionWorker, &a); - while (!a.ready) sched_yield(); + while (!a.ready) + sched_yield(); EZBENCH2("spin 2x", donothing, BenchSpinUnspin(&s)); a.done = true; pthread_join(t, 0); @@ -213,7 +216,8 @@ BENCH(pthread_mutex_lock, bench_contended) { nsync_mu m = {0}; struct NsyncContentionArgs a = {&m}; pthread_create(&t, 0, NsyncContentionWorker, &a); - while (!a.ready) sched_yield(); + while (!a.ready) + sched_yield(); EZBENCH2("nsync 2x", donothing, BenchLockUnlockNsync(&m)); a.done = true; pthread_join(t, 0); @@ -226,7 +230,8 @@ BENCH(pthread_mutex_lock, bench_contended) { pthread_mutex_init(&m, &attr); struct MutexContentionArgs a = {&m}; pthread_create(&t, 0, MutexContentionWorker, &a); - while (!a.ready) sched_yield(); + while (!a.ready) + sched_yield(); EZBENCH2("normal 2x", donothing, BenchLockUnlock(&m)); a.done = true; pthread_join(t, 0); @@ -239,7 +244,8 @@ BENCH(pthread_mutex_lock, bench_contended) { pthread_mutex_init(&m, &attr); struct MutexContentionArgs a = {&m}; pthread_create(&t, 0, MutexContentionWorker, &a); - while (!a.ready) sched_yield(); + while (!a.ready) + sched_yield(); EZBENCH2("recursive 2x", donothing, BenchLockUnlock(&m)); a.done = true; pthread_join(t, 0); @@ -252,7 +258,8 @@ BENCH(pthread_mutex_lock, bench_contended) { pthread_mutex_init(&m, &attr); struct MutexContentionArgs a = {&m}; pthread_create(&t, 0, MutexContentionWorker, &a); - while (!a.ready) sched_yield(); + while (!a.ready) + sched_yield(); EZBENCH2("errorcheck 2x", donothing, BenchLockUnlock(&m)); a.done = true; pthread_join(t, 0); diff --git a/test/libc/intrin/rand64_test.c b/test/libc/intrin/rand64_test.c index ac763e895..dc0c19a4b 100644 --- a/test/libc/intrin/rand64_test.c +++ b/test/libc/intrin/rand64_test.c @@ -64,7 +64,8 @@ TEST(_rand64, testLcg_doesntProduceIdenticalValues) { for (i = 0; i < ARRAYLEN(A); ++i) { EXPECT_NE(0, A[i], "i=%d", i); for (j = 0; j < ARRAYLEN(A); ++j) { - if (i == j) continue; + if (i == j) + continue; EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j); } } @@ -93,7 +94,8 @@ TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) { for (i = 0; i < ARRAYLEN(A); ++i) { EXPECT_NE(0, A[i], "i=%d", i); for (j = 0; j < ARRAYLEN(A); ++j) { - if (i == j) continue; + if (i == j) + continue; EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j); } } diff --git a/test/libc/intrin/strchr_test.c b/test/libc/intrin/strchr_test.c index fbb4afaad..0943a83cf 100644 --- a/test/libc/intrin/strchr_test.c +++ b/test/libc/intrin/strchr_test.c @@ -72,8 +72,10 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) { char *strchr_pure(const char *s, int c) { for (c &= 0xff;; ++s) { - if ((*s & 0xff) == c) return (char *)s; - if (!*s) return NULL; + if ((*s & 0xff) == c) + return (char *)s; + if (!*s) + return NULL; } } @@ -106,7 +108,8 @@ BENCH(strchr, bench) { char *memchr_pure(const char *m, int c, size_t n) { const unsigned char *p, *pe; for (c &= 0xff, p = (const unsigned char *)m, pe = p + n; p < pe; ++p) { - if (*p == c) return (void *)p; + if (*p == c) + return (void *)p; } return NULL; } @@ -126,8 +129,10 @@ TEST(memchr, fuzz) { char *strchrnul_pure(const char *s, int c) { for (c &= 0xff;; ++s) { - if ((*s & 0xff) == c) return (char *)s; - if (!*s) return (void *)s; + if ((*s & 0xff) == c) + return (char *)s; + if (!*s) + return (void *)s; } } @@ -147,7 +152,8 @@ TEST(strchrnul, fuzz) { void *rawmemchr_pure(const void *m, int c) { const unsigned char *s; for (c &= 255, s = m;; ++s) { - if (*s == c) return (void *)s; + if (*s == c) + return (void *)s; } } diff --git a/test/libc/intrin/strcmp_test.c b/test/libc/intrin/strcmp_test.c index fe7a4efac..a17153f58 100644 --- a/test/libc/intrin/strcmp_test.c +++ b/test/libc/intrin/strcmp_test.c @@ -491,7 +491,8 @@ TEST(wcsncmp, testTwosComplementBane) { dontinline int strcmp_pure(const char *a, const char *b) { for (; *a == *b; a++, b++) { - if (!*a) break; + if (!*a) + break; } return (*a & 0xff) - (*b & 0xff); } diff --git a/test/libc/intrin/strlen_test.c b/test/libc/intrin/strlen_test.c index 6ef0b70b1..87c316fa0 100644 --- a/test/libc/intrin/strlen_test.c +++ b/test/libc/intrin/strlen_test.c @@ -30,7 +30,8 @@ wchar_t u32[] = L"utf32 ☻"; size_t strlen_pure(const char *s) { size_t n = 0; - while (*s++) ++n; + while (*s++) + ++n; return n; } @@ -64,7 +65,8 @@ TEST(strlen, test_const) { TEST(strlen, test_nonconst) { char buf[256]; unsigned i; - for (i = 0; i < 255; ++i) buf[i] = i + 1; + for (i = 0; i < 255; ++i) + buf[i] = i + 1; buf[i] = '\0'; ASSERT_EQ(255, strlen(buf)); } @@ -85,7 +87,8 @@ TEST(strlen, testnonconst) { "m"(*StR) */ char buf[256]; unsigned i; - for (i = 0; i < 250; ++i) buf[i] = i + 1; + for (i = 0; i < 250; ++i) + buf[i] = i + 1; buf[i] = '\0'; ASSERT_EQ(250, strlen(buf)); } diff --git a/test/libc/intrin/strsignal_r_test.c b/test/libc/intrin/strsignal_r_test.c index c0cddbf16..e89b6603c 100644 --- a/test/libc/intrin/strsignal_r_test.c +++ b/test/libc/intrin/strsignal_r_test.c @@ -31,7 +31,8 @@ TEST(strsignal, test) { } TEST(strsignal, realtime) { - if (!SIGRTMIN) return; + if (!SIGRTMIN) + return; EXPECT_STREQ("SIGTHR", strsignal(SIGTHR)); ASSERT_STREQ("SIGRTMIN+1", strsignal(SIGRTMIN + 1)); } diff --git a/test/libc/mem/critbit0_test.c b/test/libc/mem/critbit0_test.c index 3e48b54c0..0fa7a206b 100644 --- a/test/libc/mem/critbit0_test.c +++ b/test/libc/mem/critbit0_test.c @@ -61,7 +61,8 @@ TEST(critbit0, testContains) { struct critbit0 tree[1]; MakeTree(tree); for (unsigned i = 0; elems[i]; ++i) { - if (!critbit0_contains(tree, elems[i])) abort(); + if (!critbit0_contains(tree, elems[i])) + abort(); } critbit0_clear(tree); } @@ -73,15 +74,19 @@ TEST(critbit0, testDelete) { struct critbit0 tree = {0}; for (unsigned i = 1; elems2[i]; ++i) { critbit0_clear(&tree); - for (unsigned j = 0; j < i; ++j) critbit0_insert(&tree, elems2[j]); + for (unsigned j = 0; j < i; ++j) + critbit0_insert(&tree, elems2[j]); for (unsigned j = 0; j < i; ++j) { - if (!critbit0_contains(&tree, elems2[j])) abort(); + if (!critbit0_contains(&tree, elems2[j])) + abort(); } for (unsigned j = 0; j < i; ++j) { - if (1 != critbit0_delete(&tree, elems2[j])) abort(); + if (1 != critbit0_delete(&tree, elems2[j])) + abort(); } for (unsigned j = 0; j < i; ++j) { - if (critbit0_contains(&tree, elems2[j])) abort(); + if (critbit0_contains(&tree, elems2[j])) + abort(); } } critbit0_clear(&tree); diff --git a/test/libc/mem/djbsort_test.c b/test/libc/mem/djbsort_test.c index e56195642..3f1f9db9b 100644 --- a/test/libc/mem/djbsort_test.c +++ b/test/libc/mem/djbsort_test.c @@ -97,8 +97,10 @@ TEST(djbsort, test64) { } static int CompareInt(const void *a, const void *b) { - if (*(const int *)a < *(const int *)b) return -1; - if (*(const int *)a > *(const int *)b) return +1; + if (*(const int *)a < *(const int *)b) + return -1; + if (*(const int *)a > *(const int *)b) + return +1; return 0; } diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index 327975b69..f27e1e3c3 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -50,36 +50,46 @@ TEST(malloc, zero) { char *p; ASSERT_NE(NULL, (p = malloc(0))); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p, 1)); free(p); } TEST(realloc, bothAreZero_createsMinimalAllocation) { char *p; ASSERT_NE(NULL, (p = realloc(0, 0))); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p, 1)); free(p); } TEST(realloc, ptrIsZero_createsAllocation) { char *p; ASSERT_NE(NULL, (p = realloc(0, 1))); - if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1)); + if (IsAsan()) + ASSERT_TRUE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p + 1, 1)); ASSERT_EQ(p, realloc(p, 0)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p + 1, 1)); free(p); } TEST(realloc, sizeIsZero_shrinksAllocation) { char *p; ASSERT_NE(NULL, (p = malloc(1))); - if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1)); + if (IsAsan()) + ASSERT_TRUE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p + 1, 1)); ASSERT_EQ(p, realloc(p, 0)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1)); - if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p, 1)); + if (IsAsan()) + ASSERT_FALSE(__asan_is_valid(p + 1, 1)); free(p); } @@ -154,9 +164,12 @@ TEST(malloc, test) { } } free(big); - for (i = 0; i < ARRAYLEN(A); ++i) free(A[i]); - for (i = 0; i < ARRAYLEN(maps); ++i) munmap(maps[i], mapsizes[i]); - for (i = 0; i < ARRAYLEN(fds); ++i) close(fds[i]); + for (i = 0; i < ARRAYLEN(A); ++i) + free(A[i]); + for (i = 0; i < ARRAYLEN(maps); ++i) + munmap(maps[i], mapsizes[i]); + for (i = 0; i < ARRAYLEN(fds); ++i) + close(fds[i]); } TEST(memalign, roundsUpAlignmentToTwoPower) { @@ -211,7 +224,8 @@ void *Worker(void *arg) { BENCH(malloc, torture) { int i, n = __get_cpu_count() * 2; pthread_t *t = gc(malloc(sizeof(pthread_t) * n)); - if (!n) return; + if (!n) + return; printf("\nmalloc torture test w/ %d threads and %d iterations\n", n, ITERATIONS); SPAWN(fork); diff --git a/test/libc/mem/qsort_test.c b/test/libc/mem/qsort_test.c index 197653bdd..a30e3e32a 100644 --- a/test/libc/mem/qsort_test.c +++ b/test/libc/mem/qsort_test.c @@ -31,8 +31,10 @@ int CompareLow(const void *a, const void *b) { const int *x = a; const int *y = b; - if ((char)*x < (char)*y) return -1; - if ((char)*x > (char)*y) return +1; + if ((char)*x < (char)*y) + return -1; + if ((char)*x > (char)*y) + return +1; return 0; } @@ -72,16 +74,20 @@ TEST(sort, stability) { int CompareInt(const void *a, const void *b) { const int *x = a; const int *y = b; - if (*x < *y) return -1; - if (*x > *y) return +1; + if (*x < *y) + return -1; + if (*x > *y) + return +1; return 0; } int CompareLong(const void *a, const void *b) { const long *x = a; const long *y = b; - if (*x < *y) return -1; - if (*x > *y) return +1; + if (*x < *y) + return -1; + if (*x > *y) + return +1; return 0; } @@ -110,8 +116,10 @@ struct Record { int CompareRecord(const void *a, const void *b) { const struct Record *x = a; const struct Record *y = b; - if (x->z > y->z) return -1; - if (x->z < y->z) return +1; + if (x->z > y->z) + return -1; + if (x->z < y->z) + return +1; return 0; } @@ -119,7 +127,8 @@ TEST(qsort, records) { int i, n = 256; struct Record *A = gc(calloc(n, sizeof(struct Record))); struct Record *B = gc(calloc(n, sizeof(struct Record))); - for (i = 0; i < n; ++i) A[i].z = B[i].z = lemur64(); + for (i = 0; i < n; ++i) + A[i].z = B[i].z = lemur64(); qsort(A, n, sizeof(struct Record), CompareRecord); mergesort(B, n, sizeof(struct Record), CompareRecord); ASSERT_EQ(0, memcmp(A, B, n * sizeof(struct Record))); @@ -131,7 +140,8 @@ TEST(qsort, equivalence_random) { long *a = gc(malloc(n * sizeof(long))); long *b = gc(malloc(n * sizeof(long))); long *c = gc(malloc(n * sizeof(long))); - for (i = 0; i < n; ++i) a[i] = lemur64(); + for (i = 0; i < n; ++i) + a[i] = lemur64(); memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); qsort(b, n, sizeof(long), CompareLong); @@ -154,7 +164,8 @@ TEST(qsort, equivalence_reverse) { long *a = gc(malloc(n * sizeof(long))); long *b = gc(malloc(n * sizeof(long))); long *c = gc(malloc(n * sizeof(long))); - for (i = 0; i < n; ++i) a[n - i - 1] = i; + for (i = 0; i < n; ++i) + a[n - i - 1] = i; memcpy(b, a, n * sizeof(long)); memcpy(c, a, n * sizeof(long)); qsort(b, n, sizeof(long), CompareLong); @@ -178,7 +189,8 @@ BENCH(qsort, bench) { long *p2 = gc(malloc(n * sizeof(long))); printf("\n"); - for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1); + for (i = 0; i < n; ++i) + p1[i] = i + ((lemur64() % 3) - 1); EZBENCH2("qsort nearly", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("qsort_r nearly", memcpy(p2, p1, n * sizeof(long)), @@ -193,7 +205,8 @@ BENCH(qsort, bench) { _longsort(p2, n)); printf("\n"); - for (i = 0; i < n; ++i) p1[i] = n - i; + for (i = 0; i < n; ++i) + p1[i] = n - i; EZBENCH2("qsort reverse", memcpy(p2, p1, n * sizeof(long)), qsort(p2, n, sizeof(long), CompareLong)); EZBENCH2("qsort_r reverse", memcpy(p2, p1, n * sizeof(long)), diff --git a/test/libc/nexgen32e/gclongjmp_test.c b/test/libc/nexgen32e/gclongjmp_test.c index c567dda51..a033e5186 100644 --- a/test/libc/nexgen32e/gclongjmp_test.c +++ b/test/libc/nexgen32e/gclongjmp_test.c @@ -43,7 +43,8 @@ void Free(char *p) { void C(void) { x = GC(strdup("abcd")); - if (0) PrintGarbage(); + if (0) + PrintGarbage(); gclongjmp(jb, 1); abort(); } @@ -65,12 +66,14 @@ void (*Bp)(void(void)) = B; void (*Cp)(void) = C; TEST(gclongjmp, test) { - if (0) PrintGarbage(); + if (0) + PrintGarbage(); if (!setjmp(jb)) { Ap(Cp, Bp); abort(); } - if (0) PrintGarbage(); + if (0) + PrintGarbage(); EXPECT_STREQ("FREE", x); EXPECT_STREQ("FREE", y); EXPECT_STREQ("FREE", z); @@ -80,7 +83,8 @@ TEST(gclongjmp, test) { } void crawl(const char *path) { - if (!strcmp(path, "/") || !strcmp(path, ".")) return; + if (!strcmp(path, "/") || !strcmp(path, ".")) + return; crawl(gc(xdirname(path))); } @@ -92,8 +96,10 @@ void *Worker(void *arg) { TEST(gc, torture) { int i, n = 32; pthread_t *t = gc(malloc(sizeof(pthread_t) * n)); - for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, pthread_create(t + i, 0, Worker, 0)); - for (i = 0; i < n; ++i) EXPECT_SYS(0, 0, pthread_join(t[i], 0)); + for (i = 0; i < n; ++i) + ASSERT_SYS(0, 0, pthread_create(t + i, 0, Worker, 0)); + for (i = 0; i < n; ++i) + EXPECT_SYS(0, 0, pthread_join(t[i], 0)); } #if defined(__GNUC__) && __GNUC__ >= 12 @@ -101,7 +107,8 @@ TEST(gc, torture) { #endif void crawl2(jmp_buf jb, const char *path) { - if (!strcmp(path, "/") || !strcmp(path, ".")) gclongjmp(jb, 1); + if (!strcmp(path, "/") || !strcmp(path, ".")) + gclongjmp(jb, 1); crawl2(jb, gc(xdirname(path))); } diff --git a/test/libc/nexgen32e/lz4decode_test.c b/test/libc/nexgen32e/lz4decode_test.c index c652ad0e2..bb679a334 100644 --- a/test/libc/nexgen32e/lz4decode_test.c +++ b/test/libc/nexgen32e/lz4decode_test.c @@ -72,7 +72,8 @@ TEST(lz4, decompress_runLengthDecode) { } TEST(lz4, zoneFileGmt) { - if (!fileexists("usr/share/zoneinfo.dict.lz4")) return; + if (!fileexists("usr/share/zoneinfo.dict.lz4")) + return; char *dict = gc(xslurp("usr/share/zoneinfo.dict.lz4", 0)); char *gmt = gc(xslurp("usr/share/zoneinfo/GMT.lz4", 0)); size_t mapsize, gmtsize; diff --git a/test/libc/proc/execve_test.c b/test/libc/proc/execve_test.c index bd323958d..01573483e 100644 --- a/test/libc/proc/execve_test.c +++ b/test/libc/proc/execve_test.c @@ -65,9 +65,12 @@ TEST(execve, testArgPassing) { } TEST(execve, ziposELF) { - if (1) return; // TODO: rewrite - if (IsFreebsd()) return; // TODO: fixme on freebsd - if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux + if (1) + return; // TODO: rewrite + if (IsFreebsd()) + return; // TODO: fixme on freebsd + if (IsLinux() && !__is_linux_2_6_23()) + return; // TODO: fixme on old linux if (!IsLinux() && !IsFreebsd()) { EXPECT_SYS(ENOSYS, -1, execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0})); @@ -80,9 +83,12 @@ TEST(execve, ziposELF) { } TEST(execve, ziposAPE) { - if (1) return; // TODO: rewrite - if (IsFreebsd()) return; // TODO: fixme on freebsd - if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux + if (1) + return; // TODO: rewrite + if (IsFreebsd()) + return; // TODO: fixme on freebsd + if (IsLinux() && !__is_linux_2_6_23()) + return; // TODO: fixme on old linux if (!IsLinux() && !IsFreebsd()) { EXPECT_EQ( -1, execve("/zip/life-nomod", (char *const[]){0}, (char *const[]){0})); @@ -137,7 +143,8 @@ void ExecveTinyElf(const char *path) { } BENCH(execve, bench) { - if (!IsLinux()) return; + if (!IsLinux()) + return; char path[128] = "/tmp/tinyelf.XXXXXX"; int fd = mkstemp(path); fchmod(fd, 0700); diff --git a/test/libc/proc/fork_test.c b/test/libc/proc/fork_test.c index dd7283ea4..8fb801ae6 100644 --- a/test/libc/proc/fork_test.c +++ b/test/libc/proc/fork_test.c @@ -103,7 +103,8 @@ static void OnSigusr2(int sig) { } TEST(fork, childToChild) { - if (IsWindows()) return; // :'( + if (IsWindows()) + return; // :'( sigset_t mask, oldmask; int ws, parent, child1, child2; gotsigusr1 = false; @@ -144,7 +145,8 @@ TEST(fork, preservesTlsMemory) { void ForkInSerial(void) { int pid, ws; ASSERT_NE(-1, (pid = fork())); - if (!pid) _Exit(0); + if (!pid) + _Exit(0); ASSERT_NE(-1, waitpid(pid, &ws, 0)); ASSERT_TRUE(WIFEXITED(ws)); ASSERT_EQ(0, WEXITSTATUS(ws)); diff --git a/test/libc/proc/getpriority_test.c b/test/libc/proc/getpriority_test.c index 024dcfd9f..274d52464 100644 --- a/test/libc/proc/getpriority_test.c +++ b/test/libc/proc/getpriority_test.c @@ -60,7 +60,8 @@ TEST(getpriority, higherPriorityOfSelf) { } TEST(getpriority, lowerAndRaiseItAgain_notAllowed) { - if (1) return; // this behavior seems limited to modern linux + if (1) + return; // this behavior seems limited to modern linux SPAWN(fork); ASSERT_SYS(0, 0, setpriority(PRIO_PROCESS, 0, 5)); ASSERT_SYS(EACCES, -1, setpriority(PRIO_PROCESS, 0, 4)); diff --git a/test/libc/proc/handkill_test.c b/test/libc/proc/handkill_test.c index 4d2872fcf..7e03f7a38 100644 --- a/test/libc/proc/handkill_test.c +++ b/test/libc/proc/handkill_test.c @@ -69,7 +69,8 @@ void *Killer(void *arg) { void *Killed(void *arg) { shm->ready = true; - while (!shm->got_signal) donothing; + while (!shm->got_signal) + donothing; shm->handler_returned = true; return 0; } @@ -88,7 +89,8 @@ TEST(handkill, main2thread_async) { pthread_t th; shm->target = pthread_self(); pthread_create(&th, 0, Killed, 0); - while (!shm->ready) donothing; + while (!shm->ready) + donothing; ASSERT_EQ(0, pthread_kill(th, SIGUSR1)); ASSERT_EQ(0, pthread_join(th, 0)); TERMS(SIGUSR1); @@ -101,7 +103,8 @@ TEST(handkill, thread2main_async) { pthread_t th; shm->target = pthread_self(); pthread_create(&th, 0, Killer, 0); - while (!shm->got_signal) donothing; + while (!shm->got_signal) + donothing; shm->handler_returned = true; pthread_join(th, 0); TERMS(SIGUSR1); @@ -122,13 +125,16 @@ TEST(handkill, thread2thread_async) { } TEST(handkill, process_async) { - if (IsWindows()) return; + if (IsWindows()) + return; SPAWN(fork); shm->ready = true; - while (!shm->got_signal) donothing; + while (!shm->got_signal) + donothing; shm->handler_returned = true; PARENT(); - while (!shm->ready) donothing; + while (!shm->ready) + donothing; ASSERT_SYS(0, 0, kill(child, SIGUSR1)); WAIT(term, SIGUSR1); EXPECT_TRUE(shm->got_signal); @@ -136,13 +142,15 @@ TEST(handkill, process_async) { } TEST(handkill, process_pause) { - if (IsWindows()) return; + if (IsWindows()) + return; SPAWN(fork); shm->ready = true; pause(); shm->handler_returned = true; PARENT(); - while (!shm->ready) donothing; + while (!shm->ready) + donothing; usleep(1e6 / CLK_TCK * 2); ASSERT_SYS(0, 0, kill(child, SIGUSR1)); WAIT(term, SIGUSR1); diff --git a/test/libc/proc/posix_spawn_test.c b/test/libc/proc/posix_spawn_test.c index 16294928e..e83abb2a8 100644 --- a/test/libc/proc/posix_spawn_test.c +++ b/test/libc/proc/posix_spawn_test.c @@ -129,8 +129,10 @@ TEST(posix_spawn, ape) { } TEST(posix_spawn, elf) { - if (IsOpenbsd()) return; // mimmutable() ugh - if (IsXnu() || IsWindows() || IsMetal()) return; + if (IsOpenbsd()) + return; // mimmutable() ugh + if (IsXnu() || IsWindows() || IsMetal()) + return; int ws, pid; char *prog = "./life.elf"; // assimilate -bcef char *args[] = {prog, 0}; @@ -193,7 +195,8 @@ void OhMyGoth(int sig) { // time for a vfork() clone() signal bloodbath TEST(posix_spawn, torture) { - if (1) return; + if (1) + return; int n = 10; int ws, pid; sigset_t allsig; @@ -259,10 +262,14 @@ void EmptySigHandler(int sig) { } TEST(posix_spawn, etxtbsy) { - if (IsWindows()) return; // can't deliver signals between processes - if (IsXnu()) return; // they don't appear impacted by this race condition - if (IsNetbsd()) return; // they don't appear impacted by this race condition - if (IsOpenbsd()) return; // they don't appear impacted by this race condition + if (IsWindows()) + return; // can't deliver signals between processes + if (IsXnu()) + return; // they don't appear impacted by this race condition + if (IsNetbsd()) + return; // they don't appear impacted by this race condition + if (IsOpenbsd()) + return; // they don't appear impacted by this race condition int ws, me, pid, thief; char *prog = "./life"; char *args[] = {prog, 0}; @@ -398,12 +405,14 @@ BENCH(posix_spawn, bench) { EZBENCH2("vfork life-pe", donothing, VforkExecveWait("./life-pe")); EZBENCH2("fork life-pe", donothing, ForkExecveWait("./life-pe")); } - if (IsXnu() || IsWindows() || IsMetal()) return; + if (IsXnu() || IsWindows() || IsMetal()) + return; EZBENCH2("posix_spawn life.elf", donothing, PosixSpawnWait("./life.elf")); EZBENCH2("vfork life.elf", donothing, VforkExecveWait("./life.elf")); EZBENCH2("fork life.elf", donothing, ForkExecveWait("./life.elf")); #ifdef __x86_64__ - if (!IsLinux()) return; + if (!IsLinux()) + return; EZBENCH2("posix_spawn tiny64", donothing, PosixSpawnWait("tiny64")); EZBENCH2("vfork tiny64", donothing, VforkExecveWait("tiny64")); EZBENCH2("fork tiny64", donothing, ForkExecveWait("tiny64")); diff --git a/test/libc/proc/sched_getaffinity_test.c b/test/libc/proc/sched_getaffinity_test.c index 23abc1fe9..d75680f95 100644 --- a/test/libc/proc/sched_getaffinity_test.c +++ b/test/libc/proc/sched_getaffinity_test.c @@ -51,7 +51,8 @@ TEST(sched_getaffinity, firstOnly) { } TEST(sched_getaffinity, secondOnly) { - if (__get_cpu_count() < 2) return; + if (__get_cpu_count() < 2) + return; cpu_set_t x, y; CPU_ZERO(&x); CPU_SET(1, &x); @@ -122,7 +123,8 @@ TEST(pthread_getaffinity, getpid) { CPU_ZERO(&x); CPU_SET(0, &x); ASSERT_SYS(0, 0, pthread_setaffinity_np(pthread_self(), sizeof(x), &x)); - if (IsWindows()) return; // win32 doesn't define GetThreadAffinityMask ;_; + if (IsWindows()) + return; // win32 doesn't define GetThreadAffinityMask ;_; ASSERT_SYS(0, 0, pthread_getaffinity_np(pthread_self(), sizeof(y), &y)); EXPECT_EQ(1, CPU_COUNT(&y)); EXPECT_TRUE(CPU_ISSET(0, &y)); diff --git a/test/libc/proc/system_test.c b/test/libc/proc/system_test.c index 9d719e6bb..b80873320 100644 --- a/test/libc/proc/system_test.c +++ b/test/libc/proc/system_test.c @@ -171,7 +171,8 @@ TEST(system, usleep) { TEST(system, kill) { int ws = system("kill -TERM $$; usleep"); - if (!IsWindows()) ASSERT_EQ(SIGTERM, WTERMSIG(ws)); + if (!IsWindows()) + ASSERT_EQ(SIGTERM, WTERMSIG(ws)); } TEST(system, exitStatusPreservedAfterSemiColon) { diff --git a/test/libc/runtime/exit_test.c b/test/libc/runtime/exit_test.c index cbdc1459a..3522f8de1 100644 --- a/test/libc/runtime/exit_test.c +++ b/test/libc/runtime/exit_test.c @@ -73,7 +73,8 @@ TEST(exit, narrowing) { } TEST(exit, exitCode259_wontCauseParentProcessToHangForever) { - if (!IsWindows()) return; + if (!IsWindows()) + return; SPAWN(vfork); _Exit(259); EXITS(259); @@ -88,7 +89,8 @@ TEST(exit, sigkill) { pause(); } } - while (!*ready) donothing; + while (!*ready) + donothing; ASSERT_EQ(0, kill(pid, SIGKILL)); ASSERT_SYS(0, pid, wait(&ws)); ASSERT_EQ(SIGKILL, ws); @@ -107,7 +109,8 @@ TEST(exit, sigalrm) { pause(); } } - while (!*ready) donothing; + while (!*ready) + donothing; ASSERT_EQ(0, kill(pid, SIGALRM)); ASSERT_SYS(0, pid, wait(&ws)); ASSERT_EQ(SIGALRM, ws); diff --git a/test/libc/runtime/grow_test.c b/test/libc/runtime/grow_test.c index 63be403af..071fa2f89 100644 --- a/test/libc/runtime/grow_test.c +++ b/test/libc/runtime/grow_test.c @@ -70,8 +70,10 @@ TEST(grow, testGrowth_clearsNewMemory) { memset(p, 'a', capacity); EXPECT_TRUE(__grow(&p, &capacity, 1, 0)); EXPECT_GT(capacity, 123); - for (i = 0; i < 123; ++i) ASSERT_EQ('a', p[i]); - for (i = 123; i < capacity; ++i) ASSERT_EQ(0, p[i]); + for (i = 0; i < 123; ++i) + ASSERT_EQ('a', p[i]); + for (i = 123; i < capacity; ++i) + ASSERT_EQ(0, p[i]); free(p); } diff --git a/test/libc/runtime/memtrack_test.c b/test/libc/runtime/memtrack_test.c index 41c19e2a2..0ccdeeb31 100644 --- a/test/libc/runtime/memtrack_test.c +++ b/test/libc/runtime/memtrack_test.c @@ -72,15 +72,18 @@ bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) { static bool AreMemoryIntervalsEqual(const struct MemoryIntervals *mm1, const struct MemoryIntervals *mm2) { - if (mm1->i != mm2->i) return false; - if (memcmp(mm1->p, mm2->p, mm1->i * sizeof(*mm2->p)) != 0) return false; + if (mm1->i != mm2->i) + return false; + if (memcmp(mm1->p, mm2->p, mm1->i * sizeof(*mm2->p)) != 0) + return false; return true; } static void PrintMemoryInterval(const struct MemoryIntervals *mm) { int i; for (i = 0; i < mm->i; ++i) { - if (i) fprintf(stderr, ","); + if (i) + fprintf(stderr, ","); fprintf(stderr, "{%d,%d}", mm->p[i].x, mm->p[i].y); } fprintf(stderr, "\n"); @@ -294,7 +297,8 @@ TEST(__untrack_memory, TestPunchHole) { } TEST(__untrack_memory, TestShortenLeft) { - if (IsWindows()) return; + if (IsWindows()) + return; static struct MemoryIntervals mm[2] = { {1, OPEN_MAX, 0, {I(0, 9)}}, {1, OPEN_MAX, 0, {I(0, 7)}}, @@ -305,7 +309,8 @@ TEST(__untrack_memory, TestShortenLeft) { } TEST(__untrack_memory, TestShortenRight) { - if (IsWindows()) return; + if (IsWindows()) + return; static struct MemoryIntervals mm[2] = { {1, OPEN_MAX, 0, {I(0, 9)}}, {1, OPEN_MAX, 0, {I(3, 9)}}, @@ -316,7 +321,8 @@ TEST(__untrack_memory, TestShortenRight) { } TEST(__untrack_memory, TestShortenLeft2) { - if (IsWindows()) return; + if (IsWindows()) + return; static struct MemoryIntervals mm[2] = { {1, OPEN_MAX, 0, {I(0, 9)}}, {1, OPEN_MAX, 0, {I(0, 7)}}, @@ -327,7 +333,8 @@ TEST(__untrack_memory, TestShortenLeft2) { } TEST(__untrack_memory, TestShortenRight2) { - if (IsWindows()) return; + if (IsWindows()) + return; static struct MemoryIntervals mm[2] = { {1, OPEN_MAX, 0, {I(0, 9)}}, {1, OPEN_MAX, 0, {I(3, 9)}}, diff --git a/test/libc/runtime/mmap_test.c b/test/libc/runtime/mmap_test.c index 1136a91c1..bf05855dd 100644 --- a/test/libc/runtime/mmap_test.c +++ b/test/libc/runtime/mmap_test.c @@ -104,7 +104,8 @@ TEST(mmap, smallerThanPage_mapsRemainder) { } TEST(mmap, smallerThanPage_remainderIsPoisoned) { - if (!IsAsan()) return; + if (!IsAsan()) + return; char *map; ASSERT_NE(MAP_FAILED, (map = mmap(0, 1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0))); @@ -474,7 +475,8 @@ void BenchMmapPrivate(void) { void *p; p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (p == MAP_FAILED) abort(); + if (p == MAP_FAILED) + abort(); ptrs[count++] = p; } diff --git a/test/libc/runtime/mprotect_test.c b/test/libc/runtime/mprotect_test.c index b4c8a82cc..c06eeb005 100644 --- a/test/libc/runtime/mprotect_test.c +++ b/test/libc/runtime/mprotect_test.c @@ -183,8 +183,10 @@ TEST(mprotect, testExecJit_actuallyWorks) { } TEST(mprotect, testRwxMap_vonNeumannRules) { - if (IsOpenbsd()) return; // boo - if (IsXnuSilicon()) return; // boo + if (IsOpenbsd()) + return; // boo + if (IsXnuSilicon()) + return; // boo int (*p)(void) = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ))); memcpy(p, kRet31337, sizeof(kRet31337)); EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), @@ -196,7 +198,8 @@ TEST(mprotect, testRwxMap_vonNeumannRules) { } TEST(mprotect, testExecuteFlatFileMapOpenedAsReadonly) { - if (IsXnuSilicon()) return; // TODO(jart): Use APE Loader SIP workaround? + if (IsXnuSilicon()) + return; // TODO(jart): Use APE Loader SIP workaround? int (*p)(void); size_t n = sizeof(kRet31337); ASSERT_SYS(0, 3, creat("return31337", 0755)); diff --git a/test/libc/runtime/msync_test.c b/test/libc/runtime/msync_test.c index 0d374ecec..3fa7a1dbe 100644 --- a/test/libc/runtime/msync_test.c +++ b/test/libc/runtime/msync_test.c @@ -62,7 +62,8 @@ TEST(msync, changeFileMappingAndWakeSpinLockWaiter) { (map = mmap(0, 1, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0))); if (!fork()) { // wait for other process to enter spin sem - while (*sem == 0) donothing; + while (*sem == 0) + donothing; // change the file mapping map[0] = 1; // openbsd fails with this line commented out @@ -72,7 +73,8 @@ TEST(msync, changeFileMappingAndWakeSpinLockWaiter) { _Exit(123); } *sem = 1; - while (*sem == 1) donothing; + while (*sem == 1) + donothing; ASSERT_EQ(1, map[0]); ASSERT_SYS(0, 1, pread(3, &byte, 1, 0)); ASSERT_EQ(1, byte); diff --git a/test/libc/runtime/munmap_test.c b/test/libc/runtime/munmap_test.c index ea0ef0078..9483485cb 100644 --- a/test/libc/runtime/munmap_test.c +++ b/test/libc/runtime/munmap_test.c @@ -140,7 +140,8 @@ TEST(munmap, memoryGone) { } TEST(munmap, testTooSmallToUnmapAsan) { - if (!IsAsan()) return; + if (!IsAsan()) + return; char *p; ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0))); @@ -150,7 +151,8 @@ TEST(munmap, testTooSmallToUnmapAsan) { } TEST(munmap, testLargeEnoughToUnmapAsan) { - if (!IsAsan()) return; + if (!IsAsan()) + return; if (IsWindows()) { // we're unfortunately never able to unmap asan pages on windows // because the memtrack array items always have to be 64kb so we diff --git a/test/libc/sock/connect_test.c b/test/libc/sock/connect_test.c index 5192cbd87..806961eb0 100644 --- a/test/libc/sock/connect_test.c +++ b/test/libc/sock/connect_test.c @@ -35,8 +35,10 @@ #include "libc/thread/thread.h" TEST(connect, nonblocking) { - if (IsFreebsd()) return; // TODO(jart): why did this start flaking? - if (IsOpenbsd()) return; // TODO(jart): why did this start freezing? + if (IsFreebsd()) + return; // TODO(jart): why did this start flaking? + if (IsOpenbsd()) + return; // TODO(jart): why did this start freezing? char buf[16] = {0}; atomic_uint *sem = _mapshared(sizeof(unsigned)); uint32_t addrsize = sizeof(struct sockaddr_in); @@ -49,7 +51,8 @@ TEST(connect, nonblocking) { ASSERT_SYS(0, 0, getsockname(3, (struct sockaddr *)&addr, &addrsize)); ASSERT_SYS(0, 0, listen(3, SOMAXCONN)); SPAWN(fork); - while (!*sem) pthread_yield(); + while (!*sem) + pthread_yield(); ASSERT_SYS(0, 4, accept(3, (struct sockaddr *)&addr, &addrsize)); ASSERT_SYS(0, 2, read(4, buf, 16)); // hi ASSERT_SYS(0, 5, write(4, "hello", 5)); diff --git a/test/libc/sock/nonblock_test.c b/test/libc/sock/nonblock_test.c index 8e639e624..baf7aa92e 100644 --- a/test/libc/sock/nonblock_test.c +++ b/test/libc/sock/nonblock_test.c @@ -37,7 +37,8 @@ TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) { // TODO(jart): this doesn't make any sense on windows - if (IsWindows()) return; + if (IsWindows()) + return; char buf[16] = {0}; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { diff --git a/test/libc/sock/recvfrom_test.c b/test/libc/sock/recvfrom_test.c index acb2cf9e1..8126a8f4e 100644 --- a/test/libc/sock/recvfrom_test.c +++ b/test/libc/sock/recvfrom_test.c @@ -33,7 +33,8 @@ // two clients send a udp packet containing their local address // server verifies content of packet matches the peer's address TEST(recvfrom, test) { - if (!IsWindows()) return; + if (!IsWindows()) + return; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in server = { .sin_family = AF_INET, diff --git a/test/libc/sock/sendfile_test.c b/test/libc/sock/sendfile_test.c index 95d65b1aa..c63e2cb1c 100644 --- a/test/libc/sock/sendfile_test.c +++ b/test/libc/sock/sendfile_test.c @@ -40,8 +40,10 @@ #include "libc/x/x.h" void SetUpOnce(void) { - if (IsNetbsd()) exit(0); - if (IsOpenbsd()) exit(0); + if (IsNetbsd()) + exit(0); + if (IsOpenbsd()) + exit(0); testlib_enable_tmp_setup_teardown(); ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath proc inet", 0)); } @@ -101,7 +103,8 @@ TEST(sendfile, testSeeking) { TEST(sendfile, testPositioning) { // TODO(jart): fix test regression on windows - if (IsWindows()) return; + if (IsWindows()) + return; char buf[1024]; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { diff --git a/test/libc/sock/socket_test.c b/test/libc/sock/socket_test.c index 0a529f2be..74983072d 100644 --- a/test/libc/sock/socket_test.c +++ b/test/libc/sock/socket_test.c @@ -152,7 +152,8 @@ __attribute__((__constructor__)) static void StdioPro(int argc, char *argv[]) { } TEST(socket, canBeUsedAsExecutedStdio) { - if (IsWindows()) return; // TODO(jart): What broke this? + if (IsWindows()) + return; // TODO(jart): What broke this? char buf[16] = {0}; const char *prog; uint32_t addrsize = sizeof(struct sockaddr_in); diff --git a/test/libc/sock/unix_test.c b/test/libc/sock/unix_test.c index 3c3c0821f..c1691234b 100644 --- a/test/libc/sock/unix_test.c +++ b/test/libc/sock/unix_test.c @@ -43,7 +43,8 @@ void SetUpOnce(void) { } TEST(unix, datagram) { - if (IsWindows()) return; // no unix datagram on windows :'( + if (IsWindows()) + return; // no unix datagram on windows :'( atomic_bool *ready = _mapshared(1); SPAWN(fork); char buf[256] = {0}; @@ -60,7 +61,8 @@ TEST(unix, datagram) { EXPECT_STREQ("hello", buf); ASSERT_SYS(0, 0, close(3)); PARENT(); - while (!*ready) sched_yield(); + while (!*ready) + sched_yield(); ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_DGRAM, 0)); uint32_t len = sizeof(struct sockaddr_un); struct sockaddr_un addr = {AF_UNIX, "foo.sock"}; @@ -95,7 +97,8 @@ void StreamServer(atomic_bool *ready) { TEST(unix, stream) { int ws; - if (IsWindows() && !IsAtLeastWindows10()) return; + if (IsWindows() && !IsAtLeastWindows10()) + return; atomic_bool *ready = _mapshared(1); // TODO(jart): move this line down when kFdProcess is gone ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_STREAM, 0)); @@ -104,7 +107,8 @@ TEST(unix, stream) { StreamServer(ready); _Exit(0); } - while (!*ready) sched_yield(); + while (!*ready) + sched_yield(); uint32_t len = sizeof(struct sockaddr_un); struct sockaddr_un addr = {AF_UNIX, "foo.sock"}; ASSERT_SYS(0, 0, connect(3, (void *)&addr, len)); @@ -117,8 +121,10 @@ TEST(unix, stream) { } TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine - if (IsWindows()) return; - if (IsCygwin()) return; + if (IsWindows()) + return; + if (IsCygwin()) + return; char buf[8] = {0}; uint32_t len = sizeof(struct sockaddr_un); struct sockaddr_un addr = {AF_UNIX, "foo.sock"}; @@ -152,8 +158,10 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine } TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier - if (IsWindows()) return; - if (IsCygwin()) return; + if (IsWindows()) + return; + if (IsCygwin()) + return; char buf[8] = {0}; uint32_t len = sizeof(struct sockaddr_un); struct sockaddr_un addr = {AF_UNIX, "foo.sock"}; diff --git a/test/libc/stdio/dirstream_test.c b/test/libc/stdio/dirstream_test.c index 392497840..447f0f433 100644 --- a/test/libc/stdio/dirstream_test.c +++ b/test/libc/stdio/dirstream_test.c @@ -61,7 +61,8 @@ void SetUp(void) { TEST(opendir, efault) { ASSERT_SYS(EFAULT, NULL, opendir(0)); - if (!IsAsan()) return; // not possible + if (!IsAsan()) + return; // not possible ASSERT_SYS(EFAULT, NULL, opendir((void *)77)); } @@ -180,8 +181,10 @@ TEST(rewinddir, test) { readdir(dir); rewinddir(dir); while ((ent = readdir(dir))) { - if (strcmp(ent->d_name, "foo")) hasfoo = true; - if (strcmp(ent->d_name, "bar")) hasbar = true; + if (strcmp(ent->d_name, "foo")) + hasfoo = true; + if (strcmp(ent->d_name, "bar")) + hasbar = true; } EXPECT_TRUE(hasfoo); EXPECT_TRUE(hasbar); diff --git a/test/libc/stdio/fds_torture_test.c b/test/libc/stdio/fds_torture_test.c index c43ad2e1e..18f446663 100644 --- a/test/libc/stdio/fds_torture_test.c +++ b/test/libc/stdio/fds_torture_test.c @@ -35,7 +35,8 @@ void *Torturer(void *arg) { } for (i = 0; i < FDS; ++i) { ASSERT_EQ(2, write(fd[i], "hi", 2)); - if (!vfork()) _Exit(0); + if (!vfork()) + _Exit(0); wait(0); } for (i = 0; i < FDS; ++i) { diff --git a/test/libc/stdio/fgets_test.c b/test/libc/stdio/fgets_test.c index ee248ee09..405df39f8 100644 --- a/test/libc/stdio/fgets_test.c +++ b/test/libc/stdio/fgets_test.c @@ -53,7 +53,8 @@ void Benchmark(void) { f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+"); for (;;) { line = fgets(buf, sizeof(buf), f); - if (!line) break; + if (!line) + break; } fclose(f); } diff --git a/test/libc/stdio/fprintf_test.c b/test/libc/stdio/fprintf_test.c index 55011e438..9fd12402f 100644 --- a/test/libc/stdio/fprintf_test.c +++ b/test/libc/stdio/fprintf_test.c @@ -24,7 +24,8 @@ TEST(fprintf, testWriteError) { // Only Linux, NetBSD and FreeBSD are known to have /dev/full - if (!IsLinux() && !IsNetbsd() && !IsFreebsd()) return; + if (!IsLinux() && !IsNetbsd() && !IsFreebsd()) + return; FILE *fp = fopen("/dev/full", "w"); ASSERT_NE(fp, NULL); diff --git a/test/libc/stdio/fwrite_test.c b/test/libc/stdio/fwrite_test.c index e06d10dca..270fb1411 100644 --- a/test/libc/stdio/fwrite_test.c +++ b/test/libc/stdio/fwrite_test.c @@ -162,7 +162,8 @@ void OnSigInt(int sig) { } TEST(fwrite, signalStorm) { - if (IsWindows()) return; + if (IsWindows()) + return; int pid; struct sigaction oldchld, oldint; struct sigaction sachld = {.sa_handler = SIG_IGN}; @@ -180,7 +181,8 @@ TEST(fwrite, signalStorm) { pause(); MeatyReadWriteTest(); EXPECT_NE(-1, kill(pid, SIGINT)); - while (wait(0) == -1 && errno == EINTR) donothing; + while (wait(0) == -1 && errno == EINTR) + donothing; EXPECT_NE(-1, sigaction(SIGCHLD, &oldchld, NULL)); EXPECT_NE(-1, sigaction(SIGINT, &oldint, NULL)); } diff --git a/test/libc/stdio/getdelim_test.c b/test/libc/stdio/getdelim_test.c index 2fb02ff1f..37f88bd18 100644 --- a/test/libc/stdio/getdelim_test.c +++ b/test/libc/stdio/getdelim_test.c @@ -99,7 +99,8 @@ void ReadHyperionLines(void) { ASSERT_NE(NULL, (f = fopen("hyperion.txt", "r"))); for (;;) { rc = getline(&line, &linesize, f); - if (rc == -1) break; + if (rc == -1) + break; data = xrealloc(data, size + rc); memcpy(data + size, line, rc); size += rc; diff --git a/test/libc/stdio/getentropy_test.c b/test/libc/stdio/getentropy_test.c index 73b860e39..532e6b098 100644 --- a/test/libc/stdio/getentropy_test.c +++ b/test/libc/stdio/getentropy_test.c @@ -51,9 +51,11 @@ void *TortureWorker(void *arg) { ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &ss, 0)); ready = true; while (!done) { - if (!IsWindows()) pthread_kill(parent, SIGUSR1); + if (!IsWindows()) + pthread_kill(parent, SIGUSR1); usleep(1); - if (!IsWindows()) pthread_kill(parent, SIGUSR2); + if (!IsWindows()) + pthread_kill(parent, SIGUSR2); usleep(1); } return 0; @@ -72,7 +74,8 @@ TEST(getentropy, test) { ASSERT_SYS(0, 0, sigaction(SIGUSR2, &sa, 0)); parent = pthread_self(); ASSERT_EQ(0, pthread_create(&child, 0, TortureWorker, 0)); - while (!ready) pthread_yield(); + while (!ready) + pthread_yield(); for (k = 0; k < 10; ++k) { ASSERT_SYS(0, 0, getentropy(0, 0)); for (i = 0; i < n; i += m) { @@ -83,9 +86,11 @@ TEST(getentropy, test) { if ((e = MeasureEntropy(buf, n)) < w) { fprintf(stderr, "error: entropy suspect! got %g but want >=%g\n", e, w); for (i = 0; i < n;) { - if (!(i % 16)) fprintf(stderr, "%6x ", i); + if (!(i % 16)) + fprintf(stderr, "%6x ", i); fprintf(stderr, "%lc", kCp437[buf[i] & 255]); - if (!(++i % 16)) fprintf(stderr, "\n"); + if (!(++i % 16)) + fprintf(stderr, "\n"); } fprintf(stderr, "\n"); done = true; @@ -95,7 +100,8 @@ TEST(getentropy, test) { } done = true; ASSERT_EQ(0, pthread_join(child, 0)); - if (!IsWindows()) ASSERT_GT(gotsome, 0); + if (!IsWindows()) + ASSERT_GT(gotsome, 0); } #endif /* __aarch64__ */ diff --git a/test/libc/stdio/mt19937_test.c b/test/libc/stdio/mt19937_test.c index 696685a74..1da2588a9 100644 --- a/test/libc/stdio/mt19937_test.c +++ b/test/libc/stdio/mt19937_test.c @@ -35,8 +35,10 @@ void GetRandom(void *p, size_t n) { for (i = 0; i < n; i += rc) { m = MIN(n - i, 256); rc = getrandom((char *)p + i, m, 0); - if (rc == -1 && errno == EINTR) continue; - if (rc <= 0) abort(); + if (rc == -1 && errno == EINTR) + continue; + if (rc <= 0) + abort(); } } diff --git a/test/libc/stdio/popen_test.c b/test/libc/stdio/popen_test.c index b60e7c085..ef4a2b973 100644 --- a/test/libc/stdio/popen_test.c +++ b/test/libc/stdio/popen_test.c @@ -120,7 +120,8 @@ void OnSig(int sig) { } TEST(popen, complicated) { - if (IsWindows()) return; // windows treats sigusr1 as terminate + if (IsWindows()) + return; // windows treats sigusr1 as terminate char cmd[64]; signal(SIGUSR1, OnSig); sprintf(cmd, "read a ; test \"x$a\" = xhello && kill -USR1 %d", getpid()); @@ -164,8 +165,10 @@ TEST(popen, torture) { int i, n = 4; pthread_t *t = gc(malloc(sizeof(pthread_t) * n)); testlib_extract("/zip/echo", "echo", 0755); - for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0)); - for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_join(t[i], 0)); + for (i = 0; i < n; ++i) + ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0)); + for (i = 0; i < n; ++i) + ASSERT_EQ(0, pthread_join(t[i], 0)); CheckForFdLeaks(); } diff --git a/test/libc/stdio/tmpfile_test.c b/test/libc/stdio/tmpfile_test.c index 7b976ccc7..0e8079f46 100644 --- a/test/libc/stdio/tmpfile_test.c +++ b/test/libc/stdio/tmpfile_test.c @@ -39,8 +39,10 @@ bool IsDirectoryEmpty(const char *path) { struct dirent *e; ASSERT_NE(NULL, (d = opendir(path))); while ((e = readdir(d))) { - if (!strcmp(e->d_name, ".")) continue; - if (!strcmp(e->d_name, "..")) continue; + if (!strcmp(e->d_name, ".")) + continue; + if (!strcmp(e->d_name, "..")) + continue; res = false; } closedir(d); @@ -83,7 +85,8 @@ TEST(tmpfile, test) { #ifndef __aarch64__ // TODO(jart): Why does this apply to pi and qemu-aarch64? TEST(tmpfile, renameToRealFile) { - if (!(IsLinux() && __is_linux_2_6_23())) return; // need non-ancient linux + if (!(IsLinux() && __is_linux_2_6_23())) + return; // need non-ancient linux FILE *f; f = tmpfile(); ASSERT_EQ(2, fputs("hi", f)); diff --git a/test/libc/str/highwayhash64_test.c b/test/libc/str/highwayhash64_test.c index f73171630..6ba2f443a 100644 --- a/test/libc/str/highwayhash64_test.c +++ b/test/libc/str/highwayhash64_test.c @@ -68,7 +68,8 @@ uint32_t KnuthMultiplicativeHash32(const void *buf, size_t size) { uint32_t h; const uint32_t kPhiPrime = 0x9e3779b1; const unsigned char *p = (const unsigned char *)buf; - for (h = i = 0; i < size; i++) h = (p[i] + h) * kPhiPrime; + for (h = i = 0; i < size; i++) + h = (p[i] + h) * kPhiPrime; return h; } diff --git a/test/libc/str/longsort_test.c b/test/libc/str/longsort_test.c index bacb49301..3a92b0586 100644 --- a/test/libc/str/longsort_test.c +++ b/test/libc/str/longsort_test.c @@ -42,8 +42,10 @@ void InsertionSort(int *A, int n) { int CompareLong(const void *a, const void *b) { const long *x = a; const long *y = b; - if (*x < *y) return -1; - if (*x > *y) return +1; + if (*x < *y) + return -1; + if (*x > *y) + return +1; return 0; } @@ -61,7 +63,8 @@ TEST(_longsort, test) { #ifdef __x86_64__ TEST(vqsort_int64_avx2, test) { - if (!X86_HAVE(AVX2)) return; + if (!X86_HAVE(AVX2)) + return; size_t n = 5000; long *a = gc(calloc(n, sizeof(long))); long *b = gc(calloc(n, sizeof(long))); @@ -73,7 +76,8 @@ TEST(vqsort_int64_avx2, test) { } TEST(vqsort_int64_sse4, test) { - if (!X86_HAVE(SSE4_2)) return; + if (!X86_HAVE(SSE4_2)) + return; size_t n = 5000; long *a = gc(calloc(n, sizeof(long))); long *b = gc(calloc(n, sizeof(long))); @@ -85,7 +89,8 @@ TEST(vqsort_int64_sse4, test) { } TEST(vqsort_int64_ssse3, test) { - if (!X86_HAVE(SSSE3)) return; + if (!X86_HAVE(SSSE3)) + return; size_t n = 5000; long *a = gc(calloc(n, sizeof(long))); long *b = gc(calloc(n, sizeof(long))); @@ -152,8 +157,10 @@ BENCH(_longsort, bench) { int CompareInt(const void *a, const void *b) { const int *x = a; const int *y = b; - if (*x < *y) return -1; - if (*x > *y) return +1; + if (*x < *y) + return -1; + if (*x > *y) + return +1; return 0; } @@ -171,7 +178,8 @@ TEST(InsertionSort, test) { #ifdef __x86_64__ TEST(vqsort_int32_avx2, test) { - if (!X86_HAVE(AVX2)) return; + if (!X86_HAVE(AVX2)) + return; size_t n = 5000; int *a = gc(calloc(n, sizeof(int))); int *b = gc(calloc(n, sizeof(int))); @@ -183,7 +191,8 @@ TEST(vqsort_int32_avx2, test) { } TEST(vqsort_int32_sse4, test) { - if (!X86_HAVE(SSE4_2)) return; + if (!X86_HAVE(SSE4_2)) + return; size_t n = 5000; int *a = gc(calloc(n, sizeof(int))); int *b = gc(calloc(n, sizeof(int))); @@ -195,7 +204,8 @@ TEST(vqsort_int32_sse4, test) { } TEST(vqsort_int32_ssse3, test) { - if (!X86_HAVE(SSSE3)) return; + if (!X86_HAVE(SSSE3)) + return; size_t n = 5000; int *a = gc(calloc(n, sizeof(int))); int *b = gc(calloc(n, sizeof(int))); diff --git a/test/libc/str/memccpy_test.c b/test/libc/str/memccpy_test.c index 4b6267310..5b54c189f 100644 --- a/test/libc/str/memccpy_test.c +++ b/test/libc/str/memccpy_test.c @@ -28,7 +28,8 @@ void *memccpy_pure(void *d, const void *s, int c, size_t n) { unsigned char *x; const unsigned char *y; for (c &= 0xff, x = d, y = s, i = 0; i < n; ++i) { - if ((x[i] = y[i]) == c) return x + i + 1; + if ((x[i] = y[i]) == c) + return x + i + 1; } return NULL; } diff --git a/test/libc/str/memmem_test.c b/test/libc/str/memmem_test.c index 145282a7d..413397be8 100644 --- a/test/libc/str/memmem_test.c +++ b/test/libc/str/memmem_test.c @@ -30,13 +30,18 @@ void *memmem_naive(const void *haystk, size_t haystklen, // const void *needle, size_t needlelen) { size_t i, j; - if (!needlelen) return (void *)haystk; - if (needlelen > haystklen) return 0; + if (!needlelen) + return (void *)haystk; + if (needlelen > haystklen) + return 0; for (i = 0; i < haystklen; ++i) { for (j = 0;; ++j) { - if (j == needlelen) return (/*unconst*/ char *)haystk + i; - if (i + j == haystklen) break; - if (((char *)haystk)[i + j] != ((char *)needle)[j]) break; + if (j == needlelen) + return (/*unconst*/ char *)haystk + i; + if (i + j == haystklen) + break; + if (((char *)haystk)[i + j] != ((char *)needle)[j]) + break; } } return 0; diff --git a/test/libc/str/strcasestr_test.c b/test/libc/str/strcasestr_test.c index 32f9ae339..a4b29daff 100644 --- a/test/libc/str/strcasestr_test.c +++ b/test/libc/str/strcasestr_test.c @@ -32,14 +32,19 @@ char *strcasestr_naive(const char *haystack, const char *needle) { size_t i; - if (haystack == needle || !*needle) return (void *)haystack; + if (haystack == needle || !*needle) + return (void *)haystack; for (;;) { for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; } diff --git a/test/libc/str/strstr_test.c b/test/libc/str/strstr_test.c index 0d40cae36..929185e6f 100644 --- a/test/libc/str/strstr_test.c +++ b/test/libc/str/strstr_test.c @@ -31,14 +31,19 @@ char *strstr_naive(const char *haystack, const char *needle) { size_t i; - if (haystack == needle || !*needle) return (void *)haystack; + if (haystack == needle || !*needle) + return (void *)haystack; for (;;) { for (i = 0;; ++i) { - if (!needle[i]) return (/*unconst*/ char *)haystack; - if (!haystack[i]) break; - if (needle[i] != haystack[i]) break; + if (!needle[i]) + return (/*unconst*/ char *)haystack; + if (!haystack[i]) + break; + if (needle[i] != haystack[i]) + break; } - if (!*haystack++) break; + if (!*haystack++) + break; } return 0; } diff --git a/test/libc/thread/makecontext_test.c b/test/libc/thread/makecontext_test.c index 93bdee907..3f53241d6 100644 --- a/test/libc/thread/makecontext_test.c +++ b/test/libc/thread/makecontext_test.c @@ -92,7 +92,8 @@ TEST(makecontext, crash) { } TEST(makecontext, backtrace) { - if (IsTiny()) return; // doesn't print full crash report + if (IsTiny()) + return; // doesn't print full crash report SPAWN(fork); if (IsWindows()) { __klog_handle = @@ -109,7 +110,8 @@ TEST(makecontext, backtrace) { makecontext(&uc, itsatrap, 2, 123, 456); setcontext(&uc); TERMS(SIGSEGV); - if (!GetSymbolTable()) return; + if (!GetSymbolTable()) + return; char *log = gc(xslurp("log", 0)); EXPECT_NE(0, strstr(log, "itsatrap")); EXPECT_NE(0, strstr(log, "runcontext")); diff --git a/test/libc/thread/nsync_test.c b/test/libc/thread/nsync_test.c index 11c0e2c46..d781c5243 100644 --- a/test/libc/thread/nsync_test.c +++ b/test/libc/thread/nsync_test.c @@ -41,14 +41,17 @@ int Put(long v, nsync_time abs_deadline) { } if (count != limit) { int i = pos + count; - if (limit <= i) i -= limit; + if (limit <= i) + i -= limit; data[i] = v; - if (count == 0) wake = 1; + if (count == 0) + wake = 1; count++; added = 1; } nsync_mu_unlock(&mu); - if (wake) nsync_cv_broadcast(&non_empty); + if (wake) + nsync_cv_broadcast(&non_empty); return added; } diff --git a/test/libc/thread/pthread_cancel_test.c b/test/libc/thread/pthread_cancel_test.c index 62604d327..c43aacc04 100644 --- a/test/libc/thread/pthread_cancel_test.c +++ b/test/libc/thread/pthread_cancel_test.c @@ -97,10 +97,12 @@ TEST(pthread_cancel, synchronous) { TEST(pthread_cancel, synchronous_deferred) { void *rc; pthread_t th; - if (!IsWindows()) return; + if (!IsWindows()) + return; ASSERT_SYS(0, 0, pipe(pfds)); ASSERT_EQ(0, pthread_create(&th, 0, Worker, 0)); - while (!ready) pthread_yield(); + while (!ready) + pthread_yield(); ASSERT_SYS(0, 0, usleep(10)); EXPECT_EQ(0, pthread_cancel(th)); EXPECT_EQ(0, pthread_join(th, &rc)); @@ -257,7 +259,8 @@ TEST(pthread_cancel, async) { is_in_infinite_loop = false; key_destructor_was_run = false; ASSERT_EQ(0, pthread_create(&th, 0, CpuBoundWorker, 0)); - while (!is_in_infinite_loop) pthread_yield(); + while (!is_in_infinite_loop) + pthread_yield(); ASSERT_EQ(0, pthread_cancel(th)); ASSERT_EQ(0, pthread_join(th, &rc)); ASSERT_EQ(PTHREAD_CANCELED, rc); @@ -289,7 +292,8 @@ TEST(pthread_cancel, self_asynchronous_takesImmediateEffect) { atomic_bool was_completed; void WaitUntilReady(void) { - while (!ready) pthread_yield(); + while (!ready) + pthread_yield(); ASSERT_EQ(0, errno); ASSERT_SYS(0, 0, usleep(1000)); } diff --git a/test/libc/thread/pthread_cond_signal_test.c b/test/libc/thread/pthread_cond_signal_test.c index 8389ddd53..107562814 100644 --- a/test/libc/thread/pthread_cond_signal_test.c +++ b/test/libc/thread/pthread_cond_signal_test.c @@ -41,14 +41,17 @@ int Put(long v, struct timespec *abs_deadline) { } if (count != limit) { int i = pos + count; - if (limit <= i) i -= limit; + if (limit <= i) + i -= limit; data[i] = v; - if (count == 0) wake = 1; + if (count == 0) + wake = 1; count++; added = 1; } pthread_mutex_unlock(&mu); - if (wake) pthread_cond_broadcast(&non_empty); + if (wake) + pthread_cond_broadcast(&non_empty); return added; } diff --git a/test/libc/thread/pthread_kill_test.c b/test/libc/thread/pthread_kill_test.c index e4eaae1ac..25a8f0b3c 100644 --- a/test/libc/thread/pthread_kill_test.c +++ b/test/libc/thread/pthread_kill_test.c @@ -61,7 +61,8 @@ void OnSig(int sig) { } void WaitUntilReady(void) { - while (!ready) pthread_yield(); + while (!ready) + pthread_yield(); ASSERT_EQ(0, errno); ASSERT_SYS(0, 0, usleep(100000)); } @@ -192,7 +193,8 @@ void *SocketAcceptWorker(void *arg) { } TEST(pthread_kill, canInterruptSocketAcceptOperation) { - if (IsWindows()) return; // TODO(jart): BAH + if (IsWindows()) + return; // TODO(jart): BAH pthread_t t; struct sigaction oldsa; struct sigaction sa = {.sa_handler = OnSig}; @@ -265,7 +267,8 @@ TEST(pthread_kill, canAsynchronouslyRunHandlerInsideTargetThread) { struct sigaction sa = {.sa_handler = OnSigAsync}; ASSERT_SYS(0, 0, sigaction(SIGUSR1, &sa, &oldsa)); ASSERT_EQ(0, pthread_create(&t, 0, CpuWorker, 0)); - while (!is_wasting_cpu) donothing; + while (!is_wasting_cpu) + donothing; EXPECT_EQ(0, pthread_kill(t, SIGUSR1)); ASSERT_EQ(0, pthread_join(t, 0)); ASSERT_TRUE(got_sig_async); @@ -290,9 +293,11 @@ TEST(pthread_kill, defaultThreadSignalHandlerWillKillWholeProcess) { SPAWN(fork); pthread_t t; ASSERT_EQ(0, pthread_create(&t, 0, FunWorker, 0)); - while (!is_having_fun) sched_yield(); + while (!is_having_fun) + sched_yield(); ASSERT_SYS(0, 0, pthread_kill(t, SIGKILL)); - for (;;) sched_yield(); + for (;;) + sched_yield(); TERMS(SIGKILL); ASSERT_NE(0, __get_tls()->tib_tid); } diff --git a/test/libc/thread/pthread_setname_np_test.c b/test/libc/thread/pthread_setname_np_test.c index 0adb7681e..d7e9a4bb9 100644 --- a/test/libc/thread/pthread_setname_np_test.c +++ b/test/libc/thread/pthread_setname_np_test.c @@ -85,7 +85,8 @@ atomic_char sync1, sync2; static void *GetNameOfOtherThreadWorker(void *arg) { pthread_setname_np(pthread_self(), "justine"); atomic_store(&sync1, 1); - while (!atomic_load(&sync2)) pthread_yield(); + while (!atomic_load(&sync2)) + pthread_yield(); return 0; } @@ -97,10 +98,13 @@ TEST(pthread_setname_np, GetNameOfOtherThread) { return; } ASSERT_EQ(0, pthread_create(&id, 0, GetNameOfOtherThreadWorker, 0)); - while (!atomic_load(&sync1)) pthread_yield(); + while (!atomic_load(&sync1)) + pthread_yield(); errno_t e = pthread_getname_np(id, me, sizeof(me)); - if (IsLinux() && e == ENOENT) goto GiveUp; // bah old kernel - if (IsLinux() && e == EACCES) goto GiveUp; // meh landlock + if (IsLinux() && e == ENOENT) + goto GiveUp; // bah old kernel + if (IsLinux() && e == EACCES) + goto GiveUp; // meh landlock ASSERT_EQ(0, e); EXPECT_STREQ("justine", me); ASSERT_EQ(0, pthread_setname_np(id, "tunney")); diff --git a/test/libc/thread/sem_timedwait_test.c b/test/libc/thread/sem_timedwait_test.c index c8a5ef101..aac8514d7 100644 --- a/test/libc/thread/sem_timedwait_test.c +++ b/test/libc/thread/sem_timedwait_test.c @@ -44,7 +44,8 @@ TEST(sem_init, einval) { } TEST(sem_post, afterDestroyed_isUndefinedBehavior) { - if (!IsModeDbg()) return; + if (!IsModeDbg()) + return; sem_t sem; SPAWN(fork); signal(SIGILL, SIG_DFL); @@ -56,7 +57,8 @@ TEST(sem_post, afterDestroyed_isUndefinedBehavior) { } TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) { - if (!IsModeDbg()) return; + if (!IsModeDbg()) + return; sem_t sem; SPAWN(fork); signal(SIGILL, SIG_DFL); @@ -68,7 +70,8 @@ TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) { } TEST(sem_wait, afterDestroyed_isUndefinedBehavior) { - if (!IsModeDbg()) return; + if (!IsModeDbg()) + return; sem_t sem; SPAWN(fork); signal(SIGILL, SIG_DFL); @@ -80,7 +83,8 @@ TEST(sem_wait, afterDestroyed_isUndefinedBehavior) { } TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) { - if (!IsModeDbg()) return; + if (!IsModeDbg()) + return; sem_t sem; SPAWN(fork); signal(SIGILL, SIG_DFL); @@ -107,12 +111,16 @@ TEST(sem_timedwait, threads) { pthread_t *t = gc(malloc(sizeof(pthread_t) * n)); ASSERT_SYS(0, 0, sem_init(s[0], 0, 0)); ASSERT_SYS(0, 0, sem_init(s[1], 0, 0)); - for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, s)); - for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_wait(s[0])); + for (i = 0; i < n; ++i) + ASSERT_EQ(0, pthread_create(t + i, 0, Worker, s)); + for (i = 0; i < n; ++i) + ASSERT_SYS(0, 0, sem_wait(s[0])); ASSERT_SYS(0, 0, sem_getvalue(s[0], &r)); ASSERT_EQ(0, r); - for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_post(s[1])); - for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_join(t[i], 0)); + for (i = 0; i < n; ++i) + ASSERT_SYS(0, 0, sem_post(s[1])); + for (i = 0; i < n; ++i) + ASSERT_EQ(0, pthread_join(t[i], 0)); ASSERT_SYS(0, 0, sem_getvalue(s[1], &r)); ASSERT_EQ(0, r); ASSERT_SYS(0, 0, sem_destroy(s[1])); @@ -126,12 +134,15 @@ TEST(sem_timedwait, processes) { ASSERT_SYS(0, 0, sem_init(s[1], pshared, 0)); for (i = 0; i < n; ++i) { ASSERT_NE(-1, (rc = fork())); - if (!rc) Worker(s), _Exit(0); + if (!rc) + Worker(s), _Exit(0); } - for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_wait(s[0])); + for (i = 0; i < n; ++i) + ASSERT_SYS(0, 0, sem_wait(s[0])); ASSERT_SYS(0, 0, sem_getvalue(s[0], &r)); ASSERT_EQ(0, r); - for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, sem_post(s[1])); + for (i = 0; i < n; ++i) + ASSERT_SYS(0, 0, sem_post(s[1])); for (;;) { int ws, pid, e = errno; if ((pid = waitpid(0, &ws, 0)) != -1) { diff --git a/test/libc/tinymath/magicu_test.c b/test/libc/tinymath/magicu_test.c index 55ad461bd..cb3da8d6a 100644 --- a/test/libc/tinymath/magicu_test.c +++ b/test/libc/tinymath/magicu_test.c @@ -38,7 +38,8 @@ T V[] = {5, 4, 77, 4, 7, 0, TEST(magicu, test) { int i, j; for (i = 0; i < ARRAYLEN(V); ++i) { - if (!V[i]) continue; + if (!V[i]) + continue; struct magicu d = __magicu_get(V[i]); for (j = 0; j < ARRAYLEN(V); ++j) { EXPECT_EQ(V[j] / V[i], __magicu_div(V[j], d)); diff --git a/test/libc/x/utf8to32_test.c b/test/libc/x/utf8to32_test.c index 9cdfa2647..0935f7485 100644 --- a/test/libc/x/utf8to32_test.c +++ b/test/libc/x/utf8to32_test.c @@ -88,7 +88,8 @@ char *GenerateBranchyUtf8Text(size_t *out_n) { wchar_t *q = gc(utf8to32(kViewables, kViewablesSize, &n)); shuffle(lemur64, q, n); p = utf32to8(q, n, &n); - if (out_n) *out_n = n; + if (out_n) + *out_n = n; return p; } diff --git a/test/libcxx/openmp_test.cc b/test/libcxx/openmp_test.cc index 160b63629..927d0f854 100644 --- a/test/libcxx/openmp_test.cc +++ b/test/libcxx/openmp_test.cc @@ -99,12 +99,14 @@ struct Gemmlin { } void gemm(long m, long n, long k) { - if (!m || !n) return; + if (!m || !n) + return; for (long i = 0; i < m; ++i) for (long j = 0; j < n; ++j) { C[ldc * i + j] *= β; } - if (!k) return; + if (!k) + return; cub = sqrt(LV1DCACHE) / sqrt(sizeof(T) * 3); mnpack(0, m, 0, n, 0, k); } @@ -120,9 +122,12 @@ struct Gemmlin { long kc = rounddown(std::min(k - k0, cub), 4); long kp = k0 + (k - k0) / kc * kc; kpack(m0, mc, mp, n0, nc, np, k0, kc, k, kp); - if (m - mp) mnpack(mp, m, n0, np, k0, k); - if (n - np) mnpack(m0, mp, np, n, k0, k); - if (m - mp && n - np) mnpack(mp, m, np, n, k0, k); + if (m - mp) + mnpack(mp, m, n0, np, k0, k); + if (n - np) + mnpack(m0, mp, np, n, k0, k); + if (m - mp && n - np) + mnpack(mp, m, np, n, k0, k); } void kpack(long m0, long mc, long m, // @@ -130,7 +135,8 @@ struct Gemmlin { long k0, long kc, long k, // long kp) { rpack(m0, mc, m, n0, nc, n, k0, kc, kp); - if (k - kp) rpack(m0, mc, m, n0, nc, n, kp, k - kp, k); + if (k - kp) + rpack(m0, mc, m, n0, nc, n, kp, k - kp, k); } void rpack(long m0, long mc, long m, // @@ -267,9 +273,11 @@ void show(FILE *f, long max, long m, long n, const TA *A, long lda, const TB *B, sprintf(ba, "%13.7f", static_cast(A[lda * i + j])); sprintf(bb, "%13.7f", static_cast(B[ldb * i + j])); for (long k = 0; ba[k] && bb[k]; ++k) { - if (ba[k] != bb[k]) fputs_unlocked("\33[31m", f); + if (ba[k] != bb[k]) + fputs_unlocked("\33[31m", f); fputc_unlocked(ba[k], f); - if (ba[k] != bb[k]) fputs_unlocked("\33[0m", f); + if (ba[k] != bb[k]) + fputs_unlocked("\33[0m", f); } } fprintf(f, "\n"); @@ -303,8 +311,10 @@ double diff(long m, long n, const TA *Want, long lda, const TB *Got, long ldb) { ++got_nans; else s += std::fabs(Want[lda * i + j] - Got[ldb * i + j]); - if (got_nans) printf("WARNING: got %d NaNs!\n", got_nans); - if (want_nans) printf("WARNING: want array has %d NaNs!\n", want_nans); + if (got_nans) + printf("WARNING: got %d NaNs!\n", got_nans); + if (want_nans) + printf("WARNING: want array has %d NaNs!\n", want_nans); return s / (m * n); } diff --git a/test/math/float16_test.c b/test/math/float16_test.c index f550b1c27..174fe7753 100644 --- a/test/math/float16_test.c +++ b/test/math/float16_test.c @@ -19,16 +19,19 @@ #include "libc/math.h" #define CHECK(x) \ - if (!(x)) return __LINE__ -#define FALSE(x) \ - { \ - volatile bool x_ = x; \ - if (x_) return __LINE__; \ + if (!(x)) \ + return __LINE__ +#define FALSE(x) \ + { \ + volatile bool x_ = x; \ + if (x_) \ + return __LINE__; \ } -#define TRUE(x) \ - { \ - volatile bool x_ = x; \ - if (!x_) return __LINE__; \ +#define TRUE(x) \ + { \ + volatile bool x_ = x; \ + if (!x_) \ + return __LINE__; \ } _Float16 identity(_Float16 x) { diff --git a/test/math/hypot_test.c b/test/math/hypot_test.c index dbe345edc..6cdb62f69 100644 --- a/test/math/hypot_test.c +++ b/test/math/hypot_test.c @@ -25,7 +25,8 @@ #define MAX_ERROR_ULP 1 #define CHECK(x) \ - if (!(x)) return __LINE__ + if (!(x)) \ + return __LINE__ #define TEST(e, x) \ errno = 0; \ @@ -85,7 +86,8 @@ int main() { continue; } long e = b.i - a.i; - if (e < 0) e = -e; + if (e < 0) + e = -e; CHECK(e <= MAX_ERROR_ULP); } } diff --git a/test/math/hypotf_test.c b/test/math/hypotf_test.c index 961f3c6d6..0fcc53f5b 100644 --- a/test/math/hypotf_test.c +++ b/test/math/hypotf_test.c @@ -25,7 +25,8 @@ #define MAX_ERROR_ULP 1 #define CHECK(x) \ - if (!(x)) return __LINE__ + if (!(x)) \ + return __LINE__ #define TEST(e, x) \ errno = 0; \ @@ -87,7 +88,8 @@ int main() { continue; } long e = b.i - a.i; - if (e < 0) e = -e; + if (e < 0) + e = -e; CHECK(e <= MAX_ERROR_ULP); } } diff --git a/test/math/powf_test.c b/test/math/powf_test.c index 357299826..dfcde8dd7 100644 --- a/test/math/powf_test.c +++ b/test/math/powf_test.c @@ -25,7 +25,8 @@ #define MAX_ERROR_ULP 1 #define CHECK(x) \ - if (!(x)) return __LINE__ + if (!(x)) \ + return __LINE__ #define TEST(e, x) \ errno = 0; \ @@ -97,7 +98,8 @@ int main() { continue; } int e = b.i - a.i; - if (e < 0) e = -e; + if (e < 0) + e = -e; CHECK(e <= MAX_ERROR_ULP); } } diff --git a/test/net/http/decodelatin1_test.c b/test/net/http/decodelatin1_test.c index e2a40c909..be3d87503 100644 --- a/test/net/http/decodelatin1_test.c +++ b/test/net/http/decodelatin1_test.c @@ -49,7 +49,8 @@ TEST(DecodeLatin1, testAbleToImposeCharacterRestrictions) { TEST(EncodeLatin1, roundTrip) { int i; char b[256]; - for (i = 0; i < 256; ++i) b[i] = i; + for (i = 0; i < 256; ++i) + b[i] = i; char *utf8 = gc(DecodeLatin1(b, 256, &n)); EXPECT_EQ(384, n); char *lat1 = gc(EncodeLatin1(utf8, n, &n, 0)); diff --git a/test/net/http/tokenbucket_test.c b/test/net/http/tokenbucket_test.c index 749ccd5b9..94bd3ff43 100644 --- a/test/net/http/tokenbucket_test.c +++ b/test/net/http/tokenbucket_test.c @@ -63,14 +63,16 @@ TEST(tokenbucket, test) { ASSERT_EQ(1, AcquireToken(tok.b, 0x7f000001, TB_CIDR)); ASSERT_EQ(0, AcquireToken(tok.b, 0x7f000002, TB_CIDR)); ASSERT_EQ(3, AcquireToken(tok.b, 0x08080808, TB_CIDR)); - for (int i = 0; i < 130; ++i) ReplenishTokens(tok.w, TB_WORDS); + for (int i = 0; i < 130; ++i) + ReplenishTokens(tok.w, TB_WORDS); ASSERT_EQ(127, AcquireToken(tok.b, 0x08080808, TB_CIDR)); } void NaiveReplenishTokens(atomic_schar *b, size_t n) { for (size_t i = 0; i < n; ++i) { int x = atomic_load_explicit(b + i, memory_order_relaxed); - if (x == 127) continue; + if (x == 127) + continue; atomic_fetch_add_explicit(b + i, 1, memory_order_acq_rel); } } diff --git a/test/net/https/mbedtls_test.c b/test/net/https/mbedtls_test.c index 821e83eb4..34eea7401 100644 --- a/test/net/https/mbedtls_test.c +++ b/test/net/https/mbedtls_test.c @@ -702,7 +702,8 @@ BENCH(inv_mod, bench3) { } TEST(ShiftRightAvx, test1) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[1] = {_rand64()}; @@ -717,7 +718,8 @@ TEST(ShiftRightAvx, test1) { } TEST(ShiftRightAvx, test2) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[2] = {_rand64(), _rand64()}; @@ -733,7 +735,8 @@ TEST(ShiftRightAvx, test2) { } TEST(ShiftRightAvx, test3) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[3] = {_rand64(), _rand64(), _rand64()}; @@ -750,7 +753,8 @@ TEST(ShiftRightAvx, test3) { } TEST(ShiftRightAvx, test4) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[4] = {_rand64(), _rand64(), _rand64(), _rand64()}; @@ -768,7 +772,8 @@ TEST(ShiftRightAvx, test4) { } TEST(ShiftRightAvx, test8) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[8] = {_rand64(), _rand64(), _rand64(), _rand64(), @@ -791,7 +796,8 @@ TEST(ShiftRightAvx, test8) { } TEST(ShiftRightAvx, test9) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; int i; for (i = 0; i < 10; ++i) { uint64_t mem[9] = {_rand64(), _rand64(), _rand64(), _rand64(), _rand64(), @@ -810,7 +816,8 @@ TEST(ShiftRightAvx, test9) { } BENCH(ShiftRight, bench) { - if (!X86_HAVE(AVX)) return; + if (!X86_HAVE(AVX)) + return; uint64_t x[64]; rngset(x, sizeof(x), _rand64, -1); EZBENCH2("ShiftRight", donothing, ShiftRight(x, 64, 1)); @@ -895,7 +902,8 @@ TEST(endian, big4) { TEST(Mul4x4, test) { int N, M; mbedtls_mpi A, B, C, D; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 4; M = 4; mbedtls_mpi_init(&A); @@ -918,7 +926,8 @@ TEST(Mul4x4, test) { BENCH(Mul4x4, bench) { int i, N, M; mbedtls_mpi A, B, C, D, E; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 4; M = 4; mbedtls_mpi_init(&A); @@ -973,7 +982,8 @@ BENCH(Mul4x4, bench) { BENCH(Mul6x6, bench) { int i, N, M; mbedtls_mpi A, B, C, D; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 6; M = 6; mbedtls_mpi_init(&A); @@ -1010,7 +1020,8 @@ BENCH(Mul6x6, bench) { BENCH(Mul10x10, bench) { int N, M; mbedtls_mpi A, B, C; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 10; M = 10; mbedtls_mpi_init(&A); @@ -1029,7 +1040,8 @@ BENCH(Mul10x10, bench) { BENCH(Mul16x16, bench) { int N, M; mbedtls_mpi A, B, C; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 16; M = 16; mbedtls_mpi_init(&A); @@ -1048,7 +1060,8 @@ BENCH(Mul16x16, bench) { BENCH(Mul32x32, bench) { int i, N, M; mbedtls_mpi A, B, C, D, K; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 32; M = 32; mbedtls_mpi_init(&A); @@ -1089,7 +1102,8 @@ BENCH(Mul32x32, bench) { BENCH(Mul16x1, bench) { int N, M; mbedtls_mpi A, B, C; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 16; M = 1; mbedtls_mpi_init(&A); @@ -1108,7 +1122,8 @@ BENCH(Mul16x1, bench) { BENCH(Mul32x1, bench) { int N, M; mbedtls_mpi A, B, C; - if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; + if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) + return; N = 32; M = 1; mbedtls_mpi_init(&A); diff --git a/test/posix/atoi_test.c b/test/posix/atoi_test.c index afef98200..f6b1ebbda 100644 --- a/test/posix/atoi_test.c +++ b/test/posix/atoi_test.c @@ -21,7 +21,8 @@ #include #define TEST(x) \ - if (!(x)) return __LINE__ + if (!(x)) \ + return __LINE__ int main() { TEST(atoi("") == 0); diff --git a/test/posix/reentrant_signal_test.c b/test/posix/reentrant_signal_test.c index e8271df56..90e4befac 100644 --- a/test/posix/reentrant_signal_test.c +++ b/test/posix/reentrant_signal_test.c @@ -31,7 +31,8 @@ void reentrant_signal_handler(int signum) { burn_stack[0] = 3; // Increment the count to indicate the signal was handled - if (++signal_handled_count == 10000) return; + if (++signal_handled_count == 10000) + return; // Re-raise the signal to test reentrancy raise(signum | burn_stack[3000]); diff --git a/test/posix/sa_resethand_test.c b/test/posix/sa_resethand_test.c index 1db070d02..c582d90fe 100644 --- a/test/posix/sa_resethand_test.c +++ b/test/posix/sa_resethand_test.c @@ -29,11 +29,18 @@ int main() { sa.sa_handler = OnSig; sa.sa_flags = SA_RESETHAND; sigemptyset(&sa.sa_mask); - if (sigaction(SIGUSR1, &sa, 0)) return 1; - if (sigaction(SIGUSR1, 0, &sa)) return 2; - if (sa.sa_handler != OnSig) return 3; - if (raise(SIGUSR1)) return 4; - if (gotsig != SIGUSR1) return 5; - if (sigaction(SIGUSR1, 0, &sa)) return 6; - if (sa.sa_handler != SIG_DFL) return 7; + if (sigaction(SIGUSR1, &sa, 0)) + return 1; + if (sigaction(SIGUSR1, 0, &sa)) + return 2; + if (sa.sa_handler != OnSig) + return 3; + if (raise(SIGUSR1)) + return 4; + if (gotsig != SIGUSR1) + return 5; + if (sigaction(SIGUSR1, 0, &sa)) + return 6; + if (sa.sa_handler != SIG_DFL) + return 7; } diff --git a/test/posix/sigchld_test.c b/test/posix/sigchld_test.c index 2b9de5860..36cf1f032 100644 --- a/test/posix/sigchld_test.c +++ b/test/posix/sigchld_test.c @@ -83,7 +83,8 @@ void OnSigchld(int sig, siginfo_t *si, void *arg) { int main(int argc, char *argv[]) { const char *startup = getenv("EXITCODE"); - if (startup) exit(atoi(startup)); + if (startup) + exit(atoi(startup)); struct sigaction newsa, oldsa; sigset_t oldmask, blocksigchld, unblockall; char *prog = argv[0]; diff --git a/test/posix/strtol_test.c b/test/posix/strtol_test.c index 4a6da98be..7df3733d3 100644 --- a/test/posix/strtol_test.c +++ b/test/posix/strtol_test.c @@ -21,7 +21,8 @@ #include #define TEST(x) \ - if (!(x)) return __LINE__ + if (!(x)) \ + return __LINE__ int main() { char *end; diff --git a/test/tool/build/lib/getargs_test.c b/test/tool/build/lib/getargs_test.c index 464bbc7c2..b26146833 100644 --- a/test/tool/build/lib/getargs_test.c +++ b/test/tool/build/lib/getargs_test.c @@ -55,7 +55,8 @@ void GetAllArgs(char **args) { size_t i = 0; struct GetArgs ga; getargs_init(&ga, args); - while (getargs_next(&ga)) ++i; + while (getargs_next(&ga)) + ++i; getargs_destroy(&ga); ASSERT_EQ(2 + 13790, i); } diff --git a/test/tool/net/redbean_test.c b/test/tool/net/redbean_test.c index 39fcbb4e1..685db685f 100644 --- a/test/tool/net/redbean_test.c +++ b/test/tool/net/redbean_test.c @@ -50,7 +50,8 @@ void SetUpOnce(void) { ssize_t n; char buf[1024]; int fdin, fdout; - if (IsWindows()) return; + if (IsWindows()) + return; testlib_enable_tmp_setup_teardown_once(); ASSERT_NE(-1, mkdir("bin", 0755)); ASSERT_NE(-1, (fdin = open("/zip/o/" MODE "/test/tool/net/redbean-tester", @@ -58,7 +59,8 @@ void SetUpOnce(void) { ASSERT_NE(-1, (fdout = creat("bin/redbean-tester", 0755))); for (;;) { ASSERT_NE(-1, (n = read(fdin, buf, sizeof(buf)))); - if (!n) break; + if (!n) + break; ASSERT_EQ(n, write(fdout, buf, n)); } close(fdout); @@ -83,7 +85,8 @@ char *SendHttpRequest(const char *s) { for (p = 0, n = 0;; n += rc) { p = xrealloc(p, n + 512); EXPECT_NE(-1, (rc = read(fd, p + n, 512))); - if (rc <= 0) break; + if (rc <= 0) + break; } p = xrealloc(p, n + 1); p[n] = 0; @@ -102,7 +105,8 @@ bool Matches(const char *regex, const char *str) { } TEST(redbean, testOptions) { - if (IsWindows()) return; + if (IsWindows()) + return; char portbuf[16]; int pid, pipefds[2]; sigset_t chldmask, savemask; @@ -142,7 +146,8 @@ TEST(redbean, testOptions) { } TEST(redbean, testPipeline) { - if (IsWindows()) return; + if (IsWindows()) + return; char portbuf[16]; int pid, pipefds[2]; sigset_t chldmask, savemask; @@ -190,7 +195,8 @@ TEST(redbean, testPipeline) { } TEST(redbean, testContentRange) { - if (IsWindows()) return; + if (IsWindows()) + return; char portbuf[16]; int pid, pipefds[2]; sigset_t chldmask, savemask; diff --git a/test/tool/net/sqlite_test.c b/test/tool/net/sqlite_test.c index 803806b9d..96c5bacc3 100644 --- a/test/tool/net/sqlite_test.c +++ b/test/tool/net/sqlite_test.c @@ -39,11 +39,14 @@ void SetUpOnce(void) { int DbOpen(const char *path, sqlite3 **db) { int i, rc; rc = sqlite3_open(path, db); - if (rc != SQLITE_OK) return rc; + if (rc != SQLITE_OK) + return rc; for (i = 0; i < 16; ++i) { rc = sqlite3_exec(*db, "PRAGMA journal_mode=WAL", 0, 0, 0); - if (rc == SQLITE_OK) break; - if (rc != SQLITE_BUSY) return rc; + if (rc == SQLITE_OK) + break; + if (rc != SQLITE_BUSY) + return rc; usleep(1000L << i); } return sqlite3_exec(*db, "PRAGMA synchronous=NORMAL", 0, 0, 0); @@ -53,9 +56,12 @@ int DbStep(sqlite3_stmt *stmt) { int i, rc; for (i = 0; i < 16; ++i) { rc = sqlite3_step(stmt); - if (rc == SQLITE_ROW) break; - if (rc == SQLITE_DONE) break; - if (rc != SQLITE_BUSY) return rc; + if (rc == SQLITE_ROW) + break; + if (rc == SQLITE_DONE) + break; + if (rc != SQLITE_BUSY) + return rc; usleep(1000L << i); } return rc; @@ -65,8 +71,10 @@ int DbExec(sqlite3 *db, const char *sql) { int i, rc; for (i = 0; i < 16; ++i) { rc = sqlite3_exec(db, sql, 0, 0, 0); - if (rc == SQLITE_OK) break; - if (rc != SQLITE_BUSY) return rc; + if (rc == SQLITE_OK) + break; + if (rc != SQLITE_BUSY) + return rc; usleep(1000L << i); } return rc; @@ -100,7 +108,8 @@ void *Worker(void *arg) { ASSERT_EQ(SQLITE_OK, DbExec(db, "BEGIN TRANSACTION")); for (;;) { rc = DbStep(stmt[1]); - if (rc == SQLITE_DONE) break; + if (rc == SQLITE_DONE) + break; ASSERT_EQ(SQLITE_ROW, rc); } ASSERT_EQ(SQLITE_OK, sqlite3_reset(stmt[1])); diff --git a/test/tool/plinko/plinko_test.c b/test/tool/plinko/plinko_test.c index cefc2f192..087663223 100644 --- a/test/tool/plinko/plinko_test.c +++ b/test/tool/plinko/plinko_test.c @@ -97,14 +97,16 @@ TEST(plinko, worksOrPrintsNiceError) { for (i = 0; i < ARRAYLEN(kSauces); ++i) { EXPECT_NE(-1, (fdin = open(kSauces[i], O_RDONLY))); rc = copyfd(fdin, pfds[0][1], -1); - if (rc == -1) EXPECT_EQ(EPIPE, errno); + if (rc == -1) + EXPECT_EQ(EPIPE, errno); EXPECT_NE(-1, close(fdin)); } EXPECT_NE(-1, close(pfds[0][1])); bzero(buf, sizeof(buf)); ASSERT_NE(-1, (got = read(pfds[1][0], buf, sizeof(buf) - 1))); EXPECT_NE(0, got); - while (read(pfds[1][0], drain, sizeof(drain)) > 0) donothing; + while (read(pfds[1][0], drain, sizeof(drain)) > 0) + donothing; EXPECT_NE(-1, close(pfds[1][0])); EXPECT_NE(-1, waitpid(pid, &wstatus, 0)); EXPECT_TRUE(WIFEXITED(wstatus)); diff --git a/test/tool/viz/lib/fun_test.c b/test/tool/viz/lib/fun_test.c index 64fbcffb2..5cb0ac213 100644 --- a/test/tool/viz/lib/fun_test.c +++ b/test/tool/viz/lib/fun_test.c @@ -195,12 +195,18 @@ void ExpandLuminosityRange(unsigned n, unsigned char *Y) { CHECK_ALIGNED(16, Y); for (i = 0; i < n; i += 16) { memcpy(b, Y + i, 16); - for (j = 0; j < 16; ++j) b[j] = MAX(0, b[j] - 16); - for (j = 0; j < 16; ++j) s[j] = b[j]; - for (j = 0; j < 16; ++j) s[j] *= 150; - for (j = 0; j < 16; ++j) s[j] /= 128; - for (j = 0; j < 16; ++j) s[j] = MIN(255, s[j]); - for (j = 0; j < 16; ++j) b[j] = s[j]; + for (j = 0; j < 16; ++j) + b[j] = MAX(0, b[j] - 16); + for (j = 0; j < 16; ++j) + s[j] = b[j]; + for (j = 0; j < 16; ++j) + s[j] *= 150; + for (j = 0; j < 16; ++j) + s[j] /= 128; + for (j = 0; j < 16; ++j) + s[j] = MIN(255, s[j]); + for (j = 0; j < 16; ++j) + b[j] = s[j]; memcpy(Y + i, b, 16); } } diff --git a/tool/build/apelink.c b/tool/build/apelink.c index 7e5ae9aa5..25bbbd365 100644 --- a/tool/build/apelink.c +++ b/tool/build/apelink.c @@ -280,12 +280,14 @@ static wontreturn void DieOom(void) { static void *Malloc(size_t n) { void *p; - if (!(p = malloc(n))) DieOom(); + if (!(p = malloc(n))) + DieOom(); return p; } static void *Realloc(void *p, size_t n) { - if (!(p = realloc(p, n))) DieOom(); + if (!(p = realloc(p, n))) + DieOom(); return p; } @@ -369,8 +371,10 @@ static char *LoadSourceCode(const char *path) { size_t i; char *text; ssize_t rc, size; - if ((fd = open(path, O_RDONLY)) == -1) DieSys(path); - if ((size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path); + if ((fd = open(path, O_RDONLY)) == -1) + DieSys(path); + if ((size = lseek(fd, 0, SEEK_END)) == -1) + DieSys(path); text = Malloc(size + 1); text[size] = 0; for (i = 0; i < size; i += rc) { @@ -381,7 +385,8 @@ static char *LoadSourceCode(const char *path) { Die(path, "source code contains binary data"); } } - if (close(fd)) DieSys(path); + if (close(fd)) + DieSys(path); HashInput(text, size); return text; } @@ -488,7 +493,8 @@ static void ValidateElfImage(Elf64_Ehdr *e, Elf64_Off esize, // int found_load = 0; Elf64_Addr last_vaddr = 0; for (i = 0; i < e->e_phnum; ++i) { - if (p[i].p_type != PT_LOAD) continue; + if (p[i].p_type != PT_LOAD) + continue; if (found_load && p[i].p_vaddr <= last_vaddr) { Die(epath, "ELF PT_LOAD segments must be ordered by p_vaddr"); } @@ -566,7 +572,8 @@ static void ValidateElfImage(Elf64_Ehdr *e, Elf64_Off esize, // Elf64_Off a = p[i].p_vaddr & -pagesz; Elf64_Off b = (p[i].p_vaddr + p[i].p_memsz + (pagesz - 1)) & -pagesz; for (j = i + 1; j < e->e_phnum; ++j) { - if (p[j].p_type != PT_LOAD) continue; + if (p[j].p_type != PT_LOAD) + continue; Elf64_Off c = p[j].p_vaddr & -pagesz; Elf64_Off d = (p[j].p_vaddr + p[j].p_memsz + (pagesz - 1)) & -pagesz; if (MAX(a, c) < MIN(b, d)) { @@ -627,7 +634,8 @@ static bool IsSymbolWorthyOfSymtab(Elf64_Sym *sym) { } static void AppendZipAsset(unsigned char *lfile, unsigned char *cfile) { - if (assets.n == 65534) Die(outpath, "fat binary has >65534 zip assets"); + if (assets.n == 65534) + Die(outpath, "fat binary has >65534 zip assets"); assets.p = Realloc(assets.p, (assets.n + 1) * sizeof(*assets.p)); assets.p[assets.n].cfile = cfile; assets.p[assets.n].lfile = lfile; @@ -666,7 +674,8 @@ static void LoadSymbols(Elf64_Ehdr *e, Elf64_Off size, const char *path) { const char *name = ConvertElfMachineToSymtabName(e); size_t name_size = strlen(name); struct SymbolTable *st = OpenSymbolTable(path); - if (!st) Die(path, "could not load elf symbol table"); + if (!st) + Die(path, "could not load elf symbol table"); size_t data_size; void *data = Deflate(st, st->size, &data_size); uint32_t crc = crc32_z(0, st, st->size); @@ -1086,9 +1095,12 @@ static void OpenLoader(struct Loader *ldr) { static int PhdrFlagsToProt(Elf64_Word flags) { int prot = PROT_NONE; - if (flags & PF_R) prot |= PROT_READ; - if (flags & PF_W) prot |= PROT_WRITE; - if (flags & PF_X) prot |= PROT_EXEC; + if (flags & PF_R) + prot |= PROT_READ; + if (flags & PF_W) + prot |= PROT_WRITE; + if (flags & PF_X) + prot |= PROT_EXEC; return prot; } @@ -1101,8 +1113,10 @@ static char *EncodeWordAsPrintf(char *p, uint64_t w, int bytes) { *p++ = c; } else { *p++ = '\\'; - if ((c & 0700)) *p++ = '0' + ((c & 0700) >> 6); - if ((c & 0770)) *p++ = '0' + ((c & 070) >> 3); + if ((c & 0700)) + *p++ = '0' + ((c & 0700) >> 6); + if ((c & 0770)) + *p++ = '0' + ((c & 070) >> 3); *p++ = '0' + (c & 7); } } @@ -1203,7 +1217,8 @@ static char *GenerateElf(char *p, struct Input *in) { static bool IsPhdrAllocated(struct Input *in, Elf64_Phdr *phdr) { int i; Elf64_Shdr *shdr; - if (1) return true; + if (1) + return true; for (i = 0; i < in->elf->e_shnum; ++i) { if (!(shdr = GetElfSectionHeaderAddress(in->elf, in->size, i))) { Die(in->path, "elf section header overflow"); @@ -1226,7 +1241,8 @@ static struct Elf64_Sym *GetElfSymbol(struct Input *in, const char *name) { ss = GetElfStringTable(in->elf, in->size, ".strtab"); sh = GetElfSymbolTable(in->elf, in->size, SHT_SYMTAB, &n); st = GetElfSectionAddress(in->elf, in->size, sh); - if (!st || !ss) Die(in->path, "missing elf symbol table"); + if (!st || !ss) + Die(in->path, "missing elf symbol table"); for (i = sh->sh_info; i < n; ++i) { if (st[i].st_name && !strcmp(ss + st[i].st_name, name)) { return st + i; @@ -1252,7 +1268,8 @@ static char *DefineMachoUuid(char *p) { ++macholoadcount; load->command = MAC_LC_UUID; load->size = sizeof(*load); - if (!hashes) Die(outpath, "won't generate macho uuid"); + if (!hashes) + Die(outpath, "won't generate macho uuid"); memcpy(load->uuid, hashpool, sizeof(load->uuid)); return p + sizeof(*load); } @@ -1411,7 +1428,8 @@ static char *SecondPass(char *p, struct Input *in) { FixupPrintf(in->printf_phoff, p - prologue); for (i = 0; i < in->elf->e_phnum; ++i) { phdr = GetElfProgramHeaderAddress(in->elf, in->size, i); - if (phdr->p_type == PT_LOAD && !IsPhdrAllocated(in, phdr)) continue; + if (phdr->p_type == PT_LOAD && !IsPhdrAllocated(in, phdr)) + continue; *(phdr2 = (Elf64_Phdr *)p) = *phdr; p += sizeof(Elf64_Phdr); if (phdr->p_filesz) { @@ -1580,14 +1598,19 @@ static Elf64_Off ThirdPass(Elf64_Off offset, struct Input *in) { static void OpenInput(const char *path) { int fd; struct Input *in; - if (inputs.n == ARRAYLEN(inputs.p)) Die(prog, "too many input files"); + if (inputs.n == ARRAYLEN(inputs.p)) + Die(prog, "too many input files"); in = inputs.p + inputs.n++; in->path = path; - if ((fd = open(path, O_RDONLY)) == -1) DieSys(path); - if ((in->size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path); + if ((fd = open(path, O_RDONLY)) == -1) + DieSys(path); + if ((in->size = lseek(fd, 0, SEEK_END)) == -1) + DieSys(path); in->map = mmap(0, in->size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (in->map == MAP_FAILED) DieSys(path); - if (!IsElf64Binary(in->elf, in->size)) Die(path, "not an elf64 binary"); + if (in->map == MAP_FAILED) + DieSys(path); + if (!IsElf64Binary(in->elf, in->size)) + Die(path, "not an elf64 binary"); HashInput(in->map, in->size); close(fd); } @@ -1820,7 +1843,8 @@ int main(int argc, char *argv[]) { #endif prog = argv[0]; - if (!prog) prog = "apelink"; + if (!prog) + prog = "apelink"; // process flags GetOpts(argc, argv); @@ -2042,7 +2066,8 @@ int main(int argc, char *argv[]) { // output native mach-o morph for (i = 0; i < inputs.n; ++i) { struct Input *in = inputs.p + i; - if (in->elf->e_machine != EM_NEXGEN32E) continue; + if (in->elf->e_machine != EM_NEXGEN32E) + continue; if (GetLoader(in->elf->e_machine, _HOSTXNU)) { p = stpcpy(p, "if [ x\"$1\" = x--assimilate ]; then\n"); } @@ -2197,7 +2222,8 @@ int main(int argc, char *argv[]) { size_t compressed_size; struct Loader *loader; loader = loaders.p + i; - if (!loader->used) continue; + if (!loader->used) + continue; compressed_data = Gzip(loader->map, loader->size, &compressed_size); if (loader->ddarg_skip1) { FixupWordAsDecimal(loader->ddarg_skip1, offset); diff --git a/tool/build/ar.c b/tool/build/ar.c index e89109b01..469d76582 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -102,7 +102,8 @@ static wontreturn void Die(const char *path, const char *reason) { static wontreturn void SysDie(const char *path, const char *func) { const char *errstr; - if (!(errstr = _strerdoc(errno))) errstr = "Unknown error"; + if (!(errstr = _strerdoc(errno))) + errstr = "Unknown error"; tinyprint(2, path, ": ", func, ": ", errstr, "\n", NULL); exit(1); } @@ -180,11 +181,14 @@ static void *reballoc(void *p, size_t n, size_t z) { size_t c; assert(n >= 0); assert(z >= 1 && !(z & (z - 1))); - if (ckd_mul(&n, n, z)) n = HEAP_SIZE; - if (!p) return balloc(~n, z); + if (ckd_mul(&n, n, z)) + n = HEAP_SIZE; + if (!p) + return balloc(~n, z); memcpy(&c, (char *)p - sizeof(c), sizeof(c)); assert(c >= z && c < HEAP_SIZE && !(c & (c - 1))); - if (n <= c) return p; + if (n <= c) + return p; return memcpy(balloc(~n, z), p, c); } @@ -264,7 +268,8 @@ static int64_t CopyFileOrDie(const char *inpath, int infd, // for (mode = CFR, toto = 0;; toto += exchanged) { if (mode == CFR) { got = copy_file_range(infd, 0, outfd, 0, 4194304, 0); - if (!got) break; + if (!got) + break; if (got != -1) { exchanged = got; } else if (errno == EXDEV || // different partitions @@ -278,11 +283,15 @@ static int64_t CopyFileOrDie(const char *inpath, int infd, // } } else { got = read(infd, buf, sizeof(buf)); - if (!got) break; - if (got == -1) SysDie(inpath, "read"); + if (!got) + break; + if (got == -1) + SysDie(inpath, "read"); wrote = write(outfd, buf, got); - if (wrote == -1) SysDie(outpath, "write"); - if (wrote != got) Die(outpath, "posix violated"); + if (wrote == -1) + SysDie(outpath, "write"); + if (wrote != got) + Die(outpath, "posix violated"); exchanged = wrote; } } @@ -326,7 +335,8 @@ int main(int argc, char *argv[]) { // on modern systems that it isn't worth supporting the byzantine // standard posix ar flags intended to improve cassette tape perf SortChars(flags, strlen(flags)); - if (*flags == 'D') ++flags; + if (*flags == 'D') + ++flags; if (!IsEqual(flags, "cr") && // !IsEqual(flags, "cru") && // !IsEqual(flags, "crsu") && // @@ -349,14 +359,22 @@ int main(int argc, char *argv[]) { for (objectid = 0;;) { struct stat st; const char *arg; - if (!(arg = getargs_next(&ga))) break; - if (endswith(arg, "/")) continue; - if (endswith(arg, ".pkg")) continue; - if (stat(arg, &st)) SysDie(arg, "stat"); - if (S_ISDIR(st.st_mode)) continue; - if (!st.st_size) Die(arg, "file is empty"); - if (st.st_size > 0x7ffff000) Die(arg, "file too large"); - if ((fd = open(arg, O_RDONLY)) == -1) SysDie(arg, "open"); + if (!(arg = getargs_next(&ga))) + break; + if (endswith(arg, "/")) + continue; + if (endswith(arg, ".pkg")) + continue; + if (stat(arg, &st)) + SysDie(arg, "stat"); + if (S_ISDIR(st.st_mode)) + continue; + if (!st.st_size) + Die(arg, "file is empty"); + if (st.st_size > 0x7ffff000) + Die(arg, "file too large"); + if ((fd = open(arg, O_RDONLY)) == -1) + SysDie(arg, "open"); AppendArg(&args, StrDup(arg)); AppendInt(&sizes, st.st_size); AppendInt(&modes, st.st_mode); @@ -374,25 +392,35 @@ int main(int argc, char *argv[]) { } size_t mapsize = st.st_size; void *elf = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, fd, 0); - if (elf == MAP_FAILED) SysDie(arg, "mmap"); - if (!IsElf64Binary(elf, mapsize)) Die(arg, "not an elf64 binary"); + if (elf == MAP_FAILED) + SysDie(arg, "mmap"); + if (!IsElf64Binary(elf, mapsize)) + Die(arg, "not an elf64 binary"); char *strs = GetElfStringTable(elf, mapsize, ".strtab"); - if (!strs) Die(arg, "elf .strtab not found"); + if (!strs) + Die(arg, "elf .strtab not found"); Elf64_Xword symcount; Elf64_Shdr *symsec = GetElfSymbolTable(elf, mapsize, SHT_SYMTAB, &symcount); Elf64_Sym *syms = GetElfSectionAddress(elf, mapsize, symsec); - if (!syms) Die(arg, "elf symbol table not found"); + if (!syms) + Die(arg, "elf symbol table not found"); for (Elf64_Xword j = symsec->sh_info; j < symcount; ++j) { - if (!syms[j].st_name) continue; - if (syms[j].st_shndx == SHN_UNDEF) continue; - if (syms[j].st_shndx == SHN_COMMON) continue; + if (!syms[j].st_name) + continue; + if (syms[j].st_shndx == SHN_UNDEF) + continue; + if (syms[j].st_shndx == SHN_COMMON) + continue; const char *symname = GetElfString(elf, mapsize, strs, syms[j].st_name); - if (!symname) Die(arg, "elf symbol name corrupted"); + if (!symname) + Die(arg, "elf symbol name corrupted"); AppendBytes(&symbols, symname, strlen(symname) + 1); AppendInt(&symnames, objectid); } - if (munmap(elf, mapsize)) SysDie(arg, "munmap"); - if (close(fd)) SysDie(arg, "close"); + if (munmap(elf, mapsize)) + SysDie(arg, "munmap"); + if (close(fd)) + SysDie(arg, "close"); ++objectid; } getargs_destroy(&ga); diff --git a/tool/build/assimilate.c b/tool/build/assimilate.c index 3a4a63169..d294b8ec2 100644 --- a/tool/build/assimilate.c +++ b/tool/build/assimilate.c @@ -197,7 +197,8 @@ static void GetElfHeader(Elf64_Ehdr *ehdr, const char *image, size_t n) { const char *p, *e; for (p = image, e = p + MIN(n, 8192); p < e; ++p) { TryAgain: - if (READ64LE(p) != READ64LE("printf '")) continue; + if (READ64LE(p) != READ64LE("printf '")) + continue; for (i = 0, p += 8; p + 3 < e && (c = *p++) != '\'';) { if (c == '\\') { if ('0' <= *p && *p <= '7') { @@ -378,18 +379,24 @@ static ssize_t Pwrite(int fd, const void *data, size_t size, uint64_t offset) { static int GetMode(int fd) { struct stat st; - if (fstat(fd, &st)) DieSys(path); + if (fstat(fd, &st)) + DieSys(path); return st.st_mode & 0777; } static void CopyFile(int infd, const char *map, size_t size, // const void *hdr, size_t hdrsize) { int outfd; - if (!outpath) return; - if ((outfd = creat(outpath, GetMode(infd))) == -1) DieSys(outpath); - if (hdrsize && Write(outfd, hdr, hdrsize) == -1) DieSys(outpath); - if (Write(outfd, map + hdrsize, size - hdrsize) == -1) DieSys(outpath); - if (close(outfd)) DieSys(outpath); + if (!outpath) + return; + if ((outfd = creat(outpath, GetMode(infd))) == -1) + DieSys(outpath); + if (hdrsize && Write(outfd, hdr, hdrsize) == -1) + DieSys(outpath); + if (Write(outfd, map + hdrsize, size - hdrsize) == -1) + DieSys(outpath); + if (close(outfd)) + DieSys(outpath); } static void WriteOutput(int infd, const char *map, size_t size, // @@ -398,7 +405,8 @@ static void WriteOutput(int infd, const char *map, size_t size, // if (outpath) { CopyFile(infd, map, size, hdr, hdrsize); } else if (g_clobber) { - if (Pwrite(infd, hdr, hdrsize, 0) == -1) DieSys(path); + if (Pwrite(infd, hdr, hdrsize, 0) == -1) + DieSys(path); } else { omode = GetMode(infd); oflags = O_WRONLY | O_CREAT | (g_force ? O_TRUNC : O_EXCL); @@ -406,10 +414,14 @@ static void WriteOutput(int infd, const char *map, size_t size, // if (strlcat(bakpath, ".bak", sizeof(bakpath)) >= sizeof(bakpath)) { Die(path, "filename too long"); } - if ((outfd = open(bakpath, oflags, omode)) == -1) DieSys(bakpath); - if (Write(outfd, map, size) == -1) DieSys(bakpath); - if (close(outfd)) DieSys(bakpath); - if (Pwrite(infd, hdr, hdrsize, 0) == -1) DieSys(path); + if ((outfd = open(bakpath, oflags, omode)) == -1) + DieSys(bakpath); + if (Write(outfd, map, size) == -1) + DieSys(bakpath); + if (close(outfd)) + DieSys(bakpath); + if (Pwrite(infd, hdr, hdrsize, 0) == -1) + DieSys(path); } } @@ -438,11 +450,15 @@ static void Assimilate(void) { int oflags; ssize_t size; oflags = outpath ? O_RDONLY : O_RDWR; - if ((fd = open(path, oflags)) == -1) DieSys(path); - if ((size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path); - if (size < 64) Die(path, "ape executables must be at least 64 bytes"); + if ((fd = open(path, oflags)) == -1) + DieSys(path); + if ((size = lseek(fd, 0, SEEK_END)) == -1) + DieSys(path); + if (size < 64) + Die(path, "ape executables must be at least 64 bytes"); p = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); - if (p == MAP_FAILED) DieSys(path); + if (p == MAP_FAILED) + DieSys(path); if (READ32LE(p) == READ32LE("\177ELF")) { Elf64_Ehdr *ehdr; @@ -604,8 +620,10 @@ static void Assimilate(void) { AssimilateMacho(fd, p, size); } - if (munmap(p, size)) DieSys(path); - if (close(fd)) DieSys(path); + if (munmap(p, size)) + DieSys(path); + if (close(fd)) + DieSys(path); } int main(int argc, char *argv[]) { diff --git a/tool/build/bigmul.c b/tool/build/bigmul.c index 36dd0a817..b731d9fc7 100644 --- a/tool/build/bigmul.c +++ b/tool/build/bigmul.c @@ -51,13 +51,15 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) { Rs = gc(calloc(sizeof(*Rs), n + m + 1)); Ra = gc(calloc(sizeof(*Ra), n + m + 1)); for (j = 0; j < n; ++j) { - if (j) printf(", "); + if (j) + printf(", "); printf("H%d", j); } printf(";\n"); printf(" uint64_t "); for (j = 0; j < n + m; ++j) { - if (j) printf(", "); + if (j) + printf(", "); printf("R%d", j); } printf(";\n"); diff --git a/tool/build/chmod.c b/tool/build/chmod.c index 3786478a9..9014ee674 100644 --- a/tool/build/chmod.c +++ b/tool/build/chmod.c @@ -60,7 +60,8 @@ int main(int argc, char *argv[]) { int i, mode; char *endptr; prog = argv[0]; - if (!prog) prog = "chmod"; + if (!prog) + prog = "chmod"; GetOpts(argc, argv); if (argc - optind < 2) { tinyprint(2, prog, ": missing operand\n", NULL); diff --git a/tool/build/compile.c b/tool/build/compile.c index 6beb51581..6707351d3 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -364,8 +364,10 @@ char *Slurp(const char *path) { bool HasFlag(const char *flags, const char *s) { char buf[256]; size_t n = strlen(s); - if (!flags) return false; - if (n + 2 > sizeof(buf)) return false; + if (!flags) + return false; + if (n + 2 > sizeof(buf)) + return false; memcpy(buf, s, n); buf[n] = '\n'; buf[n + 1] = 0; @@ -375,18 +377,29 @@ bool HasFlag(const char *flags, const char *s) { bool IsGccOnlyFlag(const char *s) { if (s[0] == '-') { if (s[1] == 'f') { - if (startswith(s, "-ffixed-")) return true; - if (startswith(s, "-fcall-saved")) return true; - if (startswith(s, "-fcall-used")) return true; - if (startswith(s, "-fgcse-")) return true; - if (startswith(s, "-fvect-cost-model=")) return true; - if (startswith(s, "-fsimd-cost-model=")) return true; - if (startswith(s, "-fopt-info")) return true; + if (startswith(s, "-ffixed-")) + return true; + if (startswith(s, "-fcall-saved")) + return true; + if (startswith(s, "-fcall-used")) + return true; + if (startswith(s, "-fgcse-")) + return true; + if (startswith(s, "-fvect-cost-model=")) + return true; + if (startswith(s, "-fsimd-cost-model=")) + return true; + if (startswith(s, "-fopt-info")) + return true; } - if (startswith(s, "-mstringop-strategy=")) return true; - if (startswith(s, "-mpreferred-stack-boundary=")) return true; - if (startswith(s, "-Wframe-larger-than=")) return true; - if (startswith(s, "-Walloca-larger-than=")) return true; + if (startswith(s, "-mstringop-strategy=")) + return true; + if (startswith(s, "-mpreferred-stack-boundary=")) + return true; + if (startswith(s, "-Wframe-larger-than=")) + return true; + if (startswith(s, "-Walloca-larger-than=")) + return true; } static bool once; static char *gcc_only_flags; @@ -409,10 +422,14 @@ bool IsClangOnlyFlag(const char *s) { bool FileExistsAndIsNewerThan(const char *filepath, const char *thanpath) { struct stat st1, st2; - if (stat(filepath, &st1) == -1) return false; - if (stat(thanpath, &st2) == -1) return false; - if (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) return false; - if (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) return true; + if (stat(filepath, &st1) == -1) + return false; + if (stat(thanpath, &st2) == -1) + return false; + if (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) + return false; + if (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) + return true; return st1.st_mtim.tv_nsec >= st2.st_mtim.tv_nsec; } @@ -499,44 +516,55 @@ static int GetBaseCpuFreqMhz(void) { void PlanResource(int resource, struct rlimit rlim) { struct rlimit prior; - if (getrlimit(resource, &prior)) return; + if (getrlimit(resource, &prior)) + return; rlim.rlim_cur = MIN(rlim.rlim_cur, prior.rlim_max); rlim.rlim_max = MIN(rlim.rlim_max, prior.rlim_max); posix_spawnattr_setrlimit(&spawnattr, resource, &rlim); } void SetCpuLimit(int secs) { - if (secs <= 0) return; - if (IsWindows()) return; + if (secs <= 0) + return; + if (IsWindows()) + return; #ifdef __x86_64__ int mhz, lim; - if (!(mhz = GetBaseCpuFreqMhz())) return; + if (!(mhz = GetBaseCpuFreqMhz())) + return; lim = ceil(3100. / mhz * secs); PlanResource(RLIMIT_CPU, (struct rlimit){lim, lim + 1}); #endif } void SetFszLimit(long n) { - if (n <= 0) return; - if (IsWindows()) return; + if (n <= 0) + return; + if (IsWindows()) + return; PlanResource(RLIMIT_FSIZE, (struct rlimit){n, n + (n >> 1)}); } void SetMemLimit(long n) { - if (n <= 0) return; - if (IsWindows() || IsXnu()) return; + if (n <= 0) + return; + if (IsWindows() || IsXnu()) + return; PlanResource(RLIMIT_AS, (struct rlimit){n, n}); } void SetStkLimit(long n) { - if (IsWindows()) return; - if (n <= 0) return; + if (IsWindows()) + return; + if (n <= 0) + return; n = MAX(n, PTHREAD_STACK_MIN * 2); PlanResource(RLIMIT_STACK, (struct rlimit){n, n}); } void SetProLimit(long n) { - if (n <= 0) return; + if (n <= 0) + return; PlanResource(RLIMIT_NPROC, (struct rlimit){n, n}); } @@ -586,7 +614,8 @@ char *AddShellQuotes(const char *s) { } p[j++] = '\''; p[j] = 0; - if ((q = realloc(p, j + 1))) p = q; + if ((q = realloc(p, j + 1))) + p = q; return p; } @@ -659,7 +688,8 @@ int Launch(void) { break; } if ((rc = read(pipefds[0], buf, sizeof(buf))) != -1) { - if (!(got = rc)) break; + if (!(got = rc)) + break; appendd(&output, buf, got); if (outquota > 0 && appendz(output).i > outquota) { kill(pid, SIGXFSZ); @@ -789,7 +819,8 @@ char *MakeTmpOut(const char *path) { g_tmpout_original = path; p = stpcpy(p, __get_tmpdir()); while ((c = *path++)) { - if (c == '/') c = '_'; + if (c == '/') + c = '_'; if (p == e) { tinyprint(2, program_invocation_short_name, ": fatal error: MakeTmpOut() generated temporary filename " @@ -826,7 +857,8 @@ int main(int argc, char *argv[]) { stkquota = 8 * 1024 * 1024; // bytes fszquota = 256 * 1000 * 1000; // bytes memquota = 2048L * 1024 * 1024; // bytes - if ((s = getenv("V"))) verbose = atoi(s); + if ((s = getenv("V"))) + verbose = atoi(s); while ((opt = getopt(argc, argv, "hnstvwA:C:F:L:M:O:P:T:V:S:")) != -1) { switch (opt) { case 'n': @@ -897,7 +929,8 @@ int main(int argc, char *argv[]) { cmd = argv[optind]; if (!strchr(cmd, '/')) { - if (!(cmd = commandv(cmd, ccpath, sizeof(ccpath)))) exit(127); + if (!(cmd = commandv(cmd, ccpath, sizeof(ccpath)))) + exit(127); } s = basename(strdup(cmd)); @@ -1020,13 +1053,20 @@ int main(int argc, char *argv[]) { #ifdef __x86_64__ } else if (!strcmp(argv[i], "-march=native")) { const struct X86ProcessorModel *model; - if (X86_HAVE(XOP)) AddArg("-mxop"); - if (X86_HAVE(SSE4A)) AddArg("-msse4a"); - if (X86_HAVE(SSE3)) AddArg("-msse3"); - if (X86_HAVE(SSSE3)) AddArg("-mssse3"); - if (X86_HAVE(SSE4_1)) AddArg("-msse4.1"); - if (X86_HAVE(SSE4_2)) AddArg("-msse4.2"); - if (X86_HAVE(AVX)) AddArg("-mavx"); + if (X86_HAVE(XOP)) + AddArg("-mxop"); + if (X86_HAVE(SSE4A)) + AddArg("-msse4a"); + if (X86_HAVE(SSE3)) + AddArg("-msse3"); + if (X86_HAVE(SSSE3)) + AddArg("-mssse3"); + if (X86_HAVE(SSE4_1)) + AddArg("-msse4.1"); + if (X86_HAVE(SSE4_2)) + AddArg("-msse4.2"); + if (X86_HAVE(AVX)) + AddArg("-mavx"); if (X86_HAVE(AVX2)) { AddArg("-mavx2"); if (isgcc) { @@ -1034,27 +1074,48 @@ int main(int argc, char *argv[]) { AddArg("-Wa,-msse2avx"); } } - if (X86_HAVE(AVX512F)) AddArg("-mavx512f"); - if (X86_HAVE(AVX512PF)) AddArg("-mavx512pf"); - if (X86_HAVE(AVX512ER)) AddArg("-mavx512er"); - if (X86_HAVE(AVX512CD)) AddArg("-mavx512cd"); - if (X86_HAVE(AVX512VL)) AddArg("-mavx512vl"); - if (X86_HAVE(AVX512BW)) AddArg("-mavx512bw"); - if (X86_HAVE(AVX512DQ)) AddArg("-mavx512dq"); - if (X86_HAVE(AVX512IFMA)) AddArg("-mavx512ifma"); - if (X86_HAVE(AVX512VBMI)) AddArg("-mavx512vbmi"); - if (X86_HAVE(SHA)) AddArg("-msha"); - if (X86_HAVE(AES)) AddArg("-maes"); - if (X86_HAVE(VAES)) AddArg("-mvaes"); - if (X86_HAVE(PCLMUL)) AddArg("-mpclmul"); - if (X86_HAVE(FSGSBASE)) AddArg("-mfsgsbase"); - if (X86_HAVE(F16C)) AddArg("-mf16c"); - if (X86_HAVE(FMA)) AddArg("-mfma"); - if (X86_HAVE(POPCNT)) AddArg("-mpopcnt"); - if (X86_HAVE(BMI)) AddArg("-mbmi"); - if (X86_HAVE(BMI2)) AddArg("-mbmi2"); - if (X86_HAVE(ADX)) AddArg("-madx"); - if (X86_HAVE(FXSR)) AddArg("-mfxsr"); + if (X86_HAVE(AVX512F)) + AddArg("-mavx512f"); + if (X86_HAVE(AVX512PF)) + AddArg("-mavx512pf"); + if (X86_HAVE(AVX512ER)) + AddArg("-mavx512er"); + if (X86_HAVE(AVX512CD)) + AddArg("-mavx512cd"); + if (X86_HAVE(AVX512VL)) + AddArg("-mavx512vl"); + if (X86_HAVE(AVX512BW)) + AddArg("-mavx512bw"); + if (X86_HAVE(AVX512DQ)) + AddArg("-mavx512dq"); + if (X86_HAVE(AVX512IFMA)) + AddArg("-mavx512ifma"); + if (X86_HAVE(AVX512VBMI)) + AddArg("-mavx512vbmi"); + if (X86_HAVE(SHA)) + AddArg("-msha"); + if (X86_HAVE(AES)) + AddArg("-maes"); + if (X86_HAVE(VAES)) + AddArg("-mvaes"); + if (X86_HAVE(PCLMUL)) + AddArg("-mpclmul"); + if (X86_HAVE(FSGSBASE)) + AddArg("-mfsgsbase"); + if (X86_HAVE(F16C)) + AddArg("-mf16c"); + if (X86_HAVE(FMA)) + AddArg("-mfma"); + if (X86_HAVE(POPCNT)) + AddArg("-mpopcnt"); + if (X86_HAVE(BMI)) + AddArg("-mbmi"); + if (X86_HAVE(BMI2)) + AddArg("-mbmi2"); + if (X86_HAVE(ADX)) + AddArg("-madx"); + if (X86_HAVE(FXSR)) + AddArg("-mfxsr"); if ((model = getx86processormodel(kX86ProcessorModelKey))) { switch (model->march) { case X86_MARCH_CORE2: @@ -1123,9 +1184,11 @@ int main(int argc, char *argv[]) { #endif /* __x86_64__ */ } else if (!strcmp(argv[i], "-fsanitize=address")) { - if (isgcc && ccversion >= 6) wantasan = true; + if (isgcc && ccversion >= 6) + wantasan = true; } else if (!strcmp(argv[i], "-fsanitize=undefined")) { - if (isgcc && ccversion >= 6) wantubsan = true; + if (isgcc && ccversion >= 6) + wantubsan = true; } else if (!strcmp(argv[i], "-fno-sanitize=address")) { wantasan = false; } else if (!strcmp(argv[i], "-fno-sanitize=undefined")) { @@ -1134,14 +1197,18 @@ int main(int argc, char *argv[]) { wantasan = false; wantubsan = false; } else if (!strcmp(argv[i], "-fno-sanitize=null")) { - if (isgcc && ccversion >= 6) no_sanitize_null = true; + if (isgcc && ccversion >= 6) + no_sanitize_null = true; } else if (!strcmp(argv[i], "-fno-sanitize=alignment")) { - if (isgcc && ccversion >= 6) no_sanitize_alignment = true; + if (isgcc && ccversion >= 6) + no_sanitize_alignment = true; } else if (!strcmp(argv[i], "-fno-sanitize=pointer-overflow")) { - if (isgcc && ccversion >= 6) no_sanitize_pointer_overflow = true; + if (isgcc && ccversion >= 6) + no_sanitize_pointer_overflow = true; } else if (startswith(argv[i], "-fsanitize=implicit") && strstr(argv[i], "integer")) { - if (isgcc) AddArg(argv[i]); + if (isgcc) + AddArg(argv[i]); } else if (strstr(argv[i], "stack-protector")) { if (isclang || (isgcc && ccversion >= 6)) { AddArg(argv[i]); @@ -1158,7 +1225,8 @@ int main(int argc, char *argv[]) { colorflag = argv[i]; } else if (startswith(argv[i], "-R") || !strcmp(argv[i], "-fsave-optimization-record")) { - if (isclang) AddArg(argv[i]); + if (isclang) + AddArg(argv[i]); } else if (isclang && startswith(argv[i], "--debug-prefix-map")) { /* llvm doesn't provide a gas interface so simulate w/ clang */ AddArg(xstrcat("-f", argv[i] + 2)); @@ -1381,11 +1449,14 @@ int main(int argc, char *argv[]) { if (verbose < 1) { /* make silent mode, i.e. `V=0 make o//target` */ appendr(&command, 0); - if (!action) action = "BUILD"; - if (!outpath) outpath = shortened; + if (!action) + action = "BUILD"; + if (!outpath) + outpath = shortened; n = strlen(action); appends(&command, action); - do appendw(&command, ' '), ++n; + do + appendw(&command, ' '), ++n; while (n < 15); appends(&command, outpath); n += strlen(outpath); @@ -1395,7 +1466,8 @@ int main(int argc, char *argv[]) { appendw(&output, READ32LE("...")); } else { if (n < m && (__nocolor || !ischardev(2))) { - while (n < m) appendw(&command, ' '), ++n; + while (n < m) + appendw(&command, ' '), ++n; } appendd(&output, command, n); } @@ -1411,7 +1483,8 @@ int main(int argc, char *argv[]) { j += (j - 1) / 3; j += 1 + 3; j += 1 + 3; - while (i < j) appendw(&output, ' '), ++i; + while (i < j) + appendw(&output, ' '), ++i; if (us > timeout * 1000000ull / 2) { if (us > timeout * 1000000ull) { PrintRed(); @@ -1436,7 +1509,8 @@ int main(int argc, char *argv[]) { j += (j - 1) / 3; j += 1 + 3; j += 1 + 3; - while (i < j) appendw(&output, ' '), ++i; + while (i < j) + appendw(&output, ' '), ++i; if ((isproblematic = us > cpuquota * 1000000ull / 2)) { if (us > cpuquota * 1000000ull - (cpuquota * 1000000ull) / 5) { PrintRed(); @@ -1455,7 +1529,8 @@ int main(int argc, char *argv[]) { i = FormatUint64Thousands(buf, usage.ru_maxrss) - buf; j = ceil(log10(memquota / 1024)); j += (j - 1) / 3; - while (i < j) appendw(&output, ' '), ++i; + while (i < j) + appendw(&output, ' '), ++i; if ((isproblematic = usage.ru_maxrss * 1024 > memquota / 2)) { if (usage.ru_maxrss * 1024 > memquota - memquota / 5) { PrintRed(); @@ -1473,7 +1548,8 @@ int main(int argc, char *argv[]) { if (fszquota > 0) { us = usage.ru_inblock + usage.ru_oublock; i = FormatUint64Thousands(buf, us) - buf; - while (i < 7) appendw(&output, ' '), ++i; + while (i < 7) + appendw(&output, ' '), ++i; appends(&output, buf); appendw(&output, READ32LE("iop ")); n += i + 4; @@ -1516,7 +1592,8 @@ int main(int argc, char *argv[]) { if (errno == EINTR) { s = "notice: compile output truncated\n"; } else { - if (!exitcode) exitcode = 55; + if (!exitcode) + exitcode = 55; s = "error: compile failed to write result\n"; } write(2, s, strlen(s)); diff --git a/tool/build/cp.c b/tool/build/cp.c index 8915b8ee7..5aed44442 100644 --- a/tool/build/cp.c +++ b/tool/build/cp.c @@ -182,8 +182,10 @@ bool MovePreservingDestinationInode(const char *from, const char *to) { void Cp(char *src, char *dst) { ssize_t rc; const char *s; - if (strlen(src) + 1 > PATH_MAX) _Exit(2); - if (strlen(dst) + 1 > PATH_MAX) _Exit(2); + if (strlen(src) + 1 > PATH_MAX) + _Exit(2); + if (strlen(dst) + 1 > PATH_MAX) + _Exit(2); basename(src); basename(dst); if (IsDirectory(src)) { @@ -243,7 +245,8 @@ int main(int argc, char *argv[]) { int i; prog = argv[0]; - if (!prog) prog = "cp"; + if (!prog) + prog = "cp"; GetOpts(argc, argv); diff --git a/tool/build/dd.c b/tool/build/dd.c index 571680f86..77c7d6e26 100644 --- a/tool/build/dd.c +++ b/tool/build/dd.c @@ -48,7 +48,8 @@ int main(int argc, char *argv[]) { const char *oufile = "/dev/stdout"; prog = argv[0]; - if (!prog) prog = "dd"; + if (!prog) + prog = "dd"; for (i = 1; i < argc; ++i) { @@ -65,14 +66,16 @@ int main(int argc, char *argv[]) { argv[i][2] == '=') { infile = argv[i] + 3 + (argv[i][3] == '"'); p = strchr(infile, '"'); - if (p) *p = 0; + if (p) + *p = 0; } else if (argv[i][0] == 'o' && // argv[i][1] == 'f' && // argv[i][2] == '=') { oufile = argv[i] + 3 + (argv[i][3] == '"'); p = strchr(infile, '"'); - if (p) *p = 0; + if (p) + *p = 0; } else if (argv[i][0] == 's' && // argv[i][1] == 'k' && // diff --git a/tool/build/echo.c b/tool/build/echo.c index 7d652893d..d3adc0ee1 100644 --- a/tool/build/echo.c +++ b/tool/build/echo.c @@ -36,7 +36,8 @@ int main(int argc, char *argv[]) { } for (j = 0; i + j < argc; ++j) { - if (j) fputc(' ', stream); + if (j) + fputc(' ', stream); fputs(argv[i + j], stream); } if (wantnewline) { diff --git a/tool/build/elf2pe.c b/tool/build/elf2pe.c index 6e65bda36..bebbde1d1 100644 --- a/tool/build/elf2pe.c +++ b/tool/build/elf2pe.c @@ -179,12 +179,14 @@ static wontreturn void DieOom(void) { static void *Calloc(size_t n) { void *p; - if (!(p = calloc(1, n))) DieOom(); + if (!(p = calloc(1, n))) + DieOom(); return p; } static void *Realloc(void *p, size_t n) { - if (!(p = realloc(p, n))) DieOom(); + if (!(p = realloc(p, n))) + DieOom(); return p; } @@ -629,10 +631,12 @@ static bool ParseDllImportSymbol(const char *symbol_name, size_t n; char *dll_name; const char *dolla; - if (!startswith(symbol_name, "dll$")) return false; + if (!startswith(symbol_name, "dll$")) + return false; symbol_name += 4; dolla = strchr(symbol_name, '$'); - if (!dolla) return false; + if (!dolla) + return false; n = dolla - symbol_name; dll_name = memcpy(Calloc(n + 1), symbol_name, n); *out_dll_name = dll_name; @@ -682,19 +686,26 @@ static struct Elf *OpenElf(const char *path) { struct Elf *elf; elf = Calloc(sizeof(*elf)); elf->path = path; - if ((fd = open(path, O_RDONLY)) == -1) DieSys(path); - if ((elf->size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path); + if ((fd = open(path, O_RDONLY)) == -1) + DieSys(path); + if ((elf->size = lseek(fd, 0, SEEK_END)) == -1) + DieSys(path); elf->map = mmap(0, elf->size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (elf->map == MAP_FAILED) DieSys(path); - if (!IsElf64Binary(elf->ehdr, elf->size)) Die(path, "not an elf64 binary"); + if (elf->map == MAP_FAILED) + DieSys(path); + if (!IsElf64Binary(elf->ehdr, elf->size)) + Die(path, "not an elf64 binary"); elf->symhdr = GetElfSymbolTable(elf->ehdr, elf->size, SHT_SYMTAB, &elf->symcount); elf->symtab = GetElfSectionAddress(elf->ehdr, elf->size, elf->symhdr); - if (!elf->symtab) Die(path, "elf doesn't have symbol table"); + if (!elf->symtab) + Die(path, "elf doesn't have symbol table"); elf->strtab = GetElfStringTable(elf->ehdr, elf->size, ".strtab"); - if (!elf->strtab) Die(path, "elf doesn't have string table"); + if (!elf->strtab) + Die(path, "elf doesn't have string table"); elf->secstrs = GetElfSectionNameStringTable(elf->ehdr, elf->size); - if (!elf->strtab) Die(path, "elf doesn't have section string table"); + if (!elf->strtab) + Die(path, "elf doesn't have section string table"); LoadDllImports(elf); LoadSectionsIntoSegments(elf); close(fd); @@ -810,14 +821,18 @@ static struct ImagePointer GeneratePe(struct Elf *elf, char *fp, int64_t vp) { // embed the ms-dos stub and/or bios bootloader if (stubpath) { int fd = open(stubpath, O_RDONLY); - if (fd == -1) DieSys(stubpath); + if (fd == -1) + DieSys(stubpath); for (;;) { ssize_t got = read(fd, fp, 512); - if (got == -1) DieSys(stubpath); - if (!got) break; + if (got == -1) + DieSys(stubpath); + if (!got) + break; fp += got; } - if (close(fd)) DieSys(stubpath); + if (close(fd)) + DieSys(stubpath); } // output portable executable magic @@ -1083,15 +1098,18 @@ int main(int argc, char *argv[]) { #endif // get program name prog = argv[0]; - if (!prog) prog = "elf2pe"; + if (!prog) + prog = "elf2pe"; // process flags GetOpts(argc, argv); // translate executable struct Elf *elf = OpenElf(argv[optind]); char *buf = memalign(MAX_ALIGN, 134217728); struct ImagePointer ip = GeneratePe(elf, buf, 0x00400000); - if (creat(outpath, 0755) == -1) DieSys(elf->path); + if (creat(outpath, 0755) == -1) + DieSys(elf->path); Pwrite(3, buf, ip.fp - buf, 0); - if (close(3)) DieSys(elf->path); + if (close(3)) + DieSys(elf->path); // PrintElf(elf); } diff --git a/tool/build/fastdiff.c b/tool/build/fastdiff.c index 787fcd844..1cbea5757 100644 --- a/tool/build/fastdiff.c +++ b/tool/build/fastdiff.c @@ -53,8 +53,10 @@ int main(int argc, char *argv[]) { if (!l1 && !l2) { exit(0); } - if (l1) chomp(l1); - if (l2) chomp(l2); + if (l1) + chomp(l1); + if (l2) + chomp(l2); if (!l1 || !l2) { printf("> %s\n", l1 ? l1 : "EOF"); printf("< %s\n", l2 ? l2 : "EOF"); diff --git a/tool/build/fixupobj.c b/tool/build/fixupobj.c index fbe9fbc95..807ec0133 100644 --- a/tool/build/fixupobj.c +++ b/tool/build/fixupobj.c @@ -78,18 +78,21 @@ static wontreturn void DieOom(void) { static void *Malloc(size_t n) { void *p; - if (!(p = malloc(n))) DieOom(); + if (!(p = malloc(n))) + DieOom(); return p; } static void *Realloc(void *p, size_t n) { - if (!(p = realloc(p, n))) DieOom(); + if (!(p = realloc(p, n))) + DieOom(); return p; } static wontreturn void SysExit(const char *func) { const char *errstr; - if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN"; + if (!(errstr = _strerdoc(errno))) + errstr = "EUNKNOWN"; tinyprint(2, epath, ": ", func, " failed with ", errstr, "\n", NULL); exit(1); } @@ -201,11 +204,15 @@ static const unsigned char kNops[10][10] = { static unsigned char *CoalesceNops(unsigned char *p, const unsigned char *e) { long n; for (; p + 1 < e; p += n) { - if (p[0] != 0x90) break; - if (p[1] != 0x90) break; + if (p[0] != 0x90) + break; + if (p[1] != 0x90) + break; for (n = 2; p + n < e; ++n) { - if (p[n] != 0x90) break; - if (n == ARRAYLEN(kNops) - 1) break; + if (p[n] != 0x90) + break; + if (n == ARRAYLEN(kNops) - 1) + break; } memcpy(p, kNops[n], n); } @@ -218,16 +225,23 @@ static void CheckPrivilegedCrossReferences(void) { const Elf64_Shdr *shdr; const Elf64_Rela *rela, *erela; shdr = FindElfSectionByName(elf, esize, secstrs, ".rela.privileged"); - if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr))) return; + if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr))) + return; erela = rela + shdr->sh_size / sizeof(*rela); for (; rela < erela; ++rela) { - if (!ELF64_R_TYPE(rela->r_info)) continue; - if (!(x = ELF64_R_SYM(rela->r_info))) continue; - if (x >= symcount) continue; - if (syms[x].st_shndx == SHN_ABS) continue; - if (!syms[x].st_shndx) continue; + if (!ELF64_R_TYPE(rela->r_info)) + continue; + if (!(x = ELF64_R_SYM(rela->r_info))) + continue; + if (x >= symcount) + continue; + if (syms[x].st_shndx == SHN_ABS) + continue; + if (!syms[x].st_shndx) + continue; if ((shdr = GetElfSectionHeaderAddress(elf, esize, syms[x].st_shndx))) { - if (~shdr->sh_flags & SHF_EXECINSTR) continue; // data reference + if (~shdr->sh_flags & SHF_EXECINSTR) + continue; // data reference if ((secname = GetElfString(elf, esize, secstrs, shdr->sh_name)) && strcmp(".privileged", secname)) { tinyprint(2, epath, @@ -334,12 +348,15 @@ static void OptimizePatchableFunctionEntries(void) { Elf64_Addr sym_rva; if (elf->e_machine == EM_NEXGEN32E) { for (i = 0; i < symcount; ++i) { - if (!syms[i].st_size) continue; - if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) continue; + if (!syms[i].st_size) + continue; + if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) + continue; if (!(shdr = GetElfSectionHeaderAddress(elf, esize, syms[i].st_shndx))) { Die("elf header overflow #3"); } - if (shdr->sh_type != SHT_PROGBITS) continue; + if (shdr->sh_type != SHT_PROGBITS) + continue; if (!(p = GetElfSectionAddress(elf, esize, shdr))) { Die("elf section overflow"); } @@ -371,7 +388,8 @@ static void RelinkZipFiles(void) { // scan backwards for zip eocd todo record // that was created by libc/nexgen32e/zip.S for (;;) { - if (eocd < stop) return; + if (eocd < stop) + return; if (READ32LE(eocd) == kZipCdirHdrMagicTodo && // ZIP_CDIR_SIZE(eocd) && // !ZIP_CDIR_OFFSET(eocd) && // @@ -446,13 +464,17 @@ static void GenerateIfuncInit(void) { static char code[16384]; static Elf64_Rela relas[1024]; Elf64_Shdr *symtab_shdr = GetElfSymbolTable(elf, esize, SHT_SYMTAB, 0); - if (!symtab_shdr) Die("symbol table section header not found"); + if (!symtab_shdr) + Die("symbol table section header not found"); Elf64_Word symtab_shdr_index = ((char *)symtab_shdr - ((char *)elf + elf->e_shoff)) / elf->e_shentsize; for (Elf64_Xword i = 0; i < symcount; ++i) { - if (syms[i].st_shndx == SHN_UNDEF) continue; - if (syms[i].st_shndx >= SHN_LORESERVE) continue; - if (ELF64_ST_TYPE(syms[i].st_info) != STT_GNU_IFUNC) continue; + if (syms[i].st_shndx == SHN_UNDEF) + continue; + if (syms[i].st_shndx >= SHN_LORESERVE) + continue; + if (ELF64_ST_TYPE(syms[i].st_info) != STT_GNU_IFUNC) + continue; if (!(name = GetElfString(elf, esize, symstrs, syms[i].st_name))) Die("could not get symbol name of ifunc"); static char resolver_name[65536]; @@ -463,11 +485,16 @@ static void GenerateIfuncInit(void) { Elf64_Xword function_sym_index = i; Elf64_Xword resolver_sym_index = -1; for (Elf64_Xword i = 0; i < symcount; ++i) { - if (syms[i].st_shndx == SHN_UNDEF) continue; - if (syms[i].st_shndx >= SHN_LORESERVE) continue; - if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) continue; - if (!(s = GetElfString(elf, esize, symstrs, syms[i].st_name))) continue; - if (strcmp(s, resolver_name)) continue; + if (syms[i].st_shndx == SHN_UNDEF) + continue; + if (syms[i].st_shndx >= SHN_LORESERVE) + continue; + if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) + continue; + if (!(s = GetElfString(elf, esize, symstrs, syms[i].st_name))) + continue; + if (strcmp(s, resolver_name)) + continue; resolver_sym_index = i; break; } @@ -521,15 +548,18 @@ static void GenerateIfuncInit(void) { 0x5e, // pop %rsi 0x5f, // pop %rdi }; - if (code_i + sizeof(chunk3) > sizeof(code)) Die("too many ifuncs"); + if (code_i + sizeof(chunk3) > sizeof(code)) + Die("too many ifuncs"); memcpy(code + code_i, chunk3, sizeof(chunk3)); code_i += sizeof(chunk3); } - if (!code_i) return; + if (!code_i) + return; // prepare to mutate elf // remap file so it has more space - if (elf->e_shnum + 2 > 65535) Die("too many sections"); + if (elf->e_shnum + 2 > 65535) + Die("too many sections"); size_t reserve_size = esize + 32 * 1024 * 1024; elf = Realloc(elf, reserve_size); diff --git a/tool/build/gzip.c b/tool/build/gzip.c index 2bc83e18b..9ebbfa5c1 100644 --- a/tool/build/gzip.c +++ b/tool/build/gzip.c @@ -157,15 +157,19 @@ void Compress(const char *inpath) { p = openflags; *p++ = opt_append ? 'a' : 'w'; *p++ = 'b'; - if (opt_exclusive) *p++ = 'x'; - if (opt_level) *p++ = opt_level; - if (opt_strategy) *p++ = opt_strategy; + if (opt_exclusive) + *p++ = 'x'; + if (opt_level) + *p++ = opt_level; + if (opt_strategy) + *p++ = opt_strategy; *p = 0; if (opt_usestdout) { outpath = "/dev/stdout"; output = gzdopen(1, openflags); } else { - if (strlen(inpath) + 3 + 1 > PATH_MAX) _Exit(2); + if (strlen(inpath) + 3 + 1 > PATH_MAX) + _Exit(2); stpcpy(stpcpy(pathbuf, inpath), ".gz"); outpath = pathbuf; output = gzopen(outpath, openflags); @@ -237,7 +241,8 @@ void Decompress(const char *inpath) { outpath = "/dev/stdout"; } else if (endswith(inpath, ".gz")) { n = strlen(inpath); - if (n - 3 + 1 > PATH_MAX) _Exit(2); + if (n - 3 + 1 > PATH_MAX) + _Exit(2); memcpy(pathbuf, inpath, n - 3); pathbuf[n - 3] = 0; outpath = pathbuf; @@ -291,7 +296,8 @@ void Decompress(const char *inpath) { int main(int argc, char *argv[]) { int i; prog = argv[0]; - if (!prog) prog = "gzip"; + if (!prog) + prog = "gzip"; GetOpts(argc, argv); if (opt_decompress) { if (optind == argc) { diff --git a/tool/build/killall.c b/tool/build/killall.c index fc954121a..5d347c825 100644 --- a/tool/build/killall.c +++ b/tool/build/killall.c @@ -69,7 +69,8 @@ static wontreturn void OutOfMemory(void) { static void *Calloc(size_t n, size_t z) { void *p; - if (!(p = calloc(n, z))) OutOfMemory(); + if (!(p = calloc(n, z))) + OutOfMemory(); return p; } @@ -186,7 +187,8 @@ int main(int argc, char *argv[]) { int64_t hProcess; char16_t name[PATH_MAX]; for (subcount = i = 0; i < n; i++) { - if (!pids[i]) continue; + if (!pids[i]) + continue; if ((hProcess = MyOpenProcess(pids[i]))) { if (GetProcessName(hProcess, name)) { ConvertStringToLowercase16(name); diff --git a/tool/build/lib/asmdown.c b/tool/build/lib/asmdown.c index a97b0b5a8..17aee2445 100644 --- a/tool/build/lib/asmdown.c +++ b/tool/build/lib/asmdown.c @@ -33,9 +33,11 @@ static bool IsSymbolChar2(char c) { } static bool IsSymbolString(const char *s) { - if (!IsSymbolChar1(*s++)) return false; + if (!IsSymbolChar1(*s++)) + return false; while (*s) { - if (!IsSymbolChar2(*s++)) return false; + if (!IsSymbolChar2(*s++)) + return false; } return true; } diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 60c4b030e..037047f66 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -32,7 +32,8 @@ void AppendData(struct Buffer *b, const char *data, size_t len) { unsigned n; if (b->i + len + 1 > b->n) { n = MAX(b->i + len + 1, MAX(16, b->n + (b->n >> 1))); - if (!(p = realloc(b->p, n))) return; + if (!(p = realloc(b->p, n))) + return; b->p = p; b->n = n; } diff --git a/tool/build/lib/demangle.c b/tool/build/lib/demangle.c index f06410a6a..a2d11cd14 100644 --- a/tool/build/lib/demangle.c +++ b/tool/build/lib/demangle.c @@ -65,17 +65,21 @@ char *CopySymbol(char *p, size_t pn, const char *s, size_t sn) { assert(pn >= 1 + 3 + 1 + 1); iscomplicated = memchr(s, ' ', sn) || memchr(s, '(', sn); extra = 1; - if (iscomplicated) extra += 2; + if (iscomplicated) + extra += 2; if (sn + extra > pn) { sn = pn - extra - 3; showdots = true; } else { showdots = false; } - if (iscomplicated) *p++ = '"'; + if (iscomplicated) + *p++ = '"'; p = mempcpy(p, s, sn); - if (showdots) p = stpcpy(p, "..."); - if (iscomplicated) *p++ = '"'; + if (showdots) + p = stpcpy(p, "..."); + if (iscomplicated) + *p++ = '"'; *p = '\0'; return p; } @@ -85,8 +89,10 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) { size_t got; struct iovec iov[2]; static char buf[4096]; - if (!g_cxxfilt.pid) SpawnCxxFilt(); - if (g_cxxfilt.pid == -1) return NULL; + if (!g_cxxfilt.pid) + SpawnCxxFilt(); + if (g_cxxfilt.pid == -1) + return NULL; buf[0] = '\n'; iov[0].iov_base = (void *)s; iov[0].iov_len = sn; @@ -96,7 +102,8 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) { if ((rc = read(g_cxxfilt.reader, buf, sizeof(buf))) != -1) { got = rc; if (got >= 2 && buf[got - 1] == '\n') { - if (buf[got - 2] == '\r') --got; + if (buf[got - 2] == '\r') + --got; --got; return CopySymbol(p, pn, buf, got); } @@ -117,7 +124,8 @@ char *Demangle(char *p, const char *symbol, size_t n) { size_t sn; sn = strlen(symbol); if (startswith(symbol, "_Z")) { - if ((r = DemangleCxxFilt(p, n, symbol, sn))) return r; + if ((r = DemangleCxxFilt(p, n, symbol, sn))) + return r; } return CopySymbol(p, n, symbol, sn); } diff --git a/tool/build/lib/elfwriter.c b/tool/build/lib/elfwriter.c index e90bcfad5..3a99c2923 100644 --- a/tool/build/lib/elfwriter.c +++ b/tool/build/lib/elfwriter.c @@ -249,7 +249,8 @@ void elfwriter_commit(struct ElfWriter *elf, size_t size) { void elfwriter_finishsection(struct ElfWriter *elf) { size_t section = FinishSection(elf); - if (elf->relas->j < elf->relas->i) MakeRelaSection(elf, section); + if (elf->relas->j < elf->relas->i) + MakeRelaSection(elf, section); } /** diff --git a/tool/build/lib/elfwriter_zip.c b/tool/build/lib/elfwriter_zip.c index 9afa5a0f7..7264c8f83 100644 --- a/tool/build/lib/elfwriter_zip.c +++ b/tool/build/lib/elfwriter_zip.c @@ -164,7 +164,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *cname, lfilehdrsize = kZipLfileHdrMinSize + namesize; crc = crc32_z(0, data, uncompsize); GetDosLocalTime(mtim.tv_sec, &mtime, &mdate); - if (isutf8(name, namesize)) gflags |= kZipGflagUtf8; + if (isutf8(name, namesize)) + gflags |= kZipGflagUtf8; if (S_ISREG(mode) && istext(data, size)) { iattrs |= kZipIattrText; } diff --git a/tool/build/lib/eztls.c b/tool/build/lib/eztls.c index ea95a53b0..5ae728387 100644 --- a/tool/build/lib/eztls.c +++ b/tool/build/lib/eztls.c @@ -65,8 +65,10 @@ static ssize_t EzWritevAll(int fd, struct iovec *iov, int iovlen) { total = 0; do { if (i) { - while (i < iovlen && !iov[i].iov_len) ++i; - if (i == iovlen) break; + while (i < iovlen && !iov[i].iov_len) + ++i; + if (i == iovlen) + break; } if ((rc = writev(fd, iov + i, iovlen - i)) != -1) { wrote = rc; @@ -99,7 +101,8 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) { 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; + if (bio->c > 0) + bio->c = 0; } else if (errno == EAGAIN) { return MBEDTLS_ERR_SSL_TIMEOUT; } else if (errno == EPIPE || errno == ECONNRESET || errno == ENETRESET) { @@ -121,7 +124,8 @@ static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) { bio->c += len; return len; } - if ((rc = EzTlsFlush(bio, buf, len)) < 0) return rc; + if ((rc = EzTlsFlush(bio, buf, len)) < 0) + return rc; return len; } @@ -130,11 +134,13 @@ static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { int r; struct iovec v[2]; struct EzTlsBio *bio = ctx; - if ((r = EzTlsFlush(bio, 0, 0)) < 0) return r; + if ((r = EzTlsFlush(bio, 0, 0)) < 0) + return r; if (bio->a < bio->b) { r = MIN(n, bio->b - bio->a); memcpy(p, bio->t + bio->a, r); - if ((bio->a += r) == bio->b) bio->a = bio->b = 0; + if ((bio->a += r) == bio->b) + bio->a = bio->b = 0; return r; } v[0].iov_base = p; @@ -153,7 +159,8 @@ static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { return MBEDTLS_ERR_NET_RECV_FAILED; } } - if (r > n) bio->b = r - n; + if (r > n) + bio->b = r - n; return MIN(n, r); } @@ -237,7 +244,8 @@ void EzSetup(char psk[32]) { } void EzDestroy(void) { - if (!mytid) return; + if (!mytid) + return; EzSanity(); mbedtls_ssl_free(&ezssl); mbedtls_ctr_drbg_free(&ezrng); diff --git a/tool/build/lib/getargs.c b/tool/build/lib/getargs.c index f500708ac..3e31da96b 100644 --- a/tool/build/lib/getargs.c +++ b/tool/build/lib/getargs.c @@ -77,7 +77,8 @@ static wontreturn void getargs_fail(const char *path, const char *reason) { const char *errstr; - if (!(errstr = _strerdoc(errno))) errstr = "Unknown error"; + if (!(errstr = _strerdoc(errno))) + errstr = "Unknown error"; tinyprint(2, path, ": ", reason, ": ", errstr, "\n", NULL); exit(1); } @@ -97,7 +98,8 @@ void getargs_init(struct GetArgs *ga, char **args) { */ void getargs_destroy(struct GetArgs *ga) { if (ga->map) { - if (munmap(ga->map, ga->mapsize)) notpossible; + if (munmap(ga->map, ga->mapsize)) + notpossible; } bzero(ga, sizeof(*ga)); } @@ -152,7 +154,8 @@ const char *getargs_next(struct GetArgs *ga) { ga->j += ++k; return p; } - if (munmap(ga->map, ga->mapsize)) notpossible; + if (munmap(ga->map, ga->mapsize)) + notpossible; ga->map = 0; ga->mapsize = 0; ga->j = 0; diff --git a/tool/build/lib/interner.c b/tool/build/lib/interner.c index 85a22d7d2..89d9d9488 100644 --- a/tool/build/lib/interner.c +++ b/tool/build/lib/interner.c @@ -43,7 +43,8 @@ static void rehash(struct InternerObject *it) { p = it->p; it->p = xcalloc((it->n <<= 1), sizeof(struct InternerHash)); for (i = 0; i < n; ++i) { - if (!p[i].hash) continue; + if (!p[i].hash) + continue; step = 0; do { j = (p[i].hash + step * ((step + 1) >> 1)) & (it->n - 1); @@ -120,15 +121,21 @@ size_t internobj(struct Interner *t, const void *data, size_t size) { } while (it->p[i].hash); } off = it->pool.i; - if (ckd_add(&need, off, size)) abort(); - if (ckd_add(&need, need, 1)) abort(); + if (ckd_add(&need, off, size)) + abort(); + if (ckd_add(&need, need, 1)) + abort(); if (need > it->pool.n) { - if (ckd_add(&n2, it->pool.n, 1)) abort(); + if (ckd_add(&n2, it->pool.n, 1)) + abort(); do { - if (ckd_add(&n2, n2, n2 >> 1)) abort(); + if (ckd_add(&n2, n2, n2 >> 1)) + abort(); } while (need > n2); - if (ckd_mul(&bytes, n2, sizeof(*it->pool.p))) abort(); - if (!(p2 = realloc(it->pool.p, bytes))) abort(); + if (ckd_mul(&bytes, n2, sizeof(*it->pool.p))) + abort(); + if (!(p2 = realloc(it->pool.p, bytes))) + abort(); it->pool.p = p2; it->pool.n = n2; } diff --git a/tool/build/lib/javadown.c b/tool/build/lib/javadown.c index 2c46c385e..40c73f738 100644 --- a/tool/build/lib/javadown.c +++ b/tool/build/lib/javadown.c @@ -32,13 +32,16 @@ struct Lines { static char *SkipEmptyFirstLine(char *p) { int i = 0; - while (p[i] == ' ' || p[i] == '\t') ++i; + while (p[i] == ' ' || p[i] == '\t') + ++i; return p[i] == '\n' ? p + i + 1 : p; } static void DeleteLastEmptyLine(char *p, size_t n) { - while (n && (p[n - 1] == ' ' || p[n - 1] == '\t')) --n; - if (n && p[n - 1] == '\n') p[n - 1] = '\0'; + while (n && (p[n - 1] == ' ' || p[n - 1] == '\t')) + --n; + if (n && p[n - 1] == '\n') + p[n - 1] = '\0'; } static void AppendLine(struct Lines *lines) { @@ -88,7 +91,8 @@ static unsigned GetMinPrefixLen(struct Lines *lines, for (m = -1, i = 0; i < lines->n; ++i) { if (lines->p[i].n) { n = GetPrefixLen(lines->p[i].p, lines->p[i].n); - if (n < m) m = n; + if (n < m) + m = n; } } return m == -1 ? 0 : m; @@ -112,7 +116,8 @@ static void SplitLines(struct Lines *lines, char *p) { AppendLine(lines); lines->p[lines->n - 1].p = p; lines->p[lines->n - 1].n = (q = strchr(p, '\n')) ? q - p : strlen(p); - if (!q) break; + if (!q) + break; p = q + 1; } RemovePrefixes(lines, GetMinPrefixLen(lines, GetSpaceStarPrefixLen)); @@ -175,7 +180,8 @@ static int ExtractText(struct Javadown *jd, struct Lines *lines, int i) { char *p; size_t n; for (p = NULL, n = j = 0; i + j < lines->n; ++j) { - if (lines->p[i + j].n && lines->p[i + j].p[0] == '@') break; + if (lines->p[i + j].n && lines->p[i + j].p[0] == '@') + break; if (j) { p = realloc(p, ++n); p[n - 1] = '\n'; @@ -194,11 +200,14 @@ static void ExtractTags(struct Javadown *jd, struct Lines *lines, int i) { char *tag, *text, *p2; unsigned taglen, textlen, n2; for (; i < lines->n; ++i) { - if (!lines->p[i].n) continue; - if (lines->p[i].p[0] != '@') continue; + if (!lines->p[i].n) + continue; + if (lines->p[i].p[0] != '@') + continue; tag = lines->p[i].p + 1; taglen = GetTagLen(tag, lines->p[i].n - 1); - if (!taglen) continue; + if (!taglen) + continue; text = tag + taglen; tag = strndup(tag, taglen); textlen = lines->p[i].n - 1 - taglen; diff --git a/tool/build/lib/panel.c b/tool/build/lib/panel.c index 162cf8a46..976d49aa5 100644 --- a/tool/build/lib/panel.c +++ b/tool/build/lib/panel.c @@ -27,25 +27,30 @@ static int tpdecode(const char *s, wint_t *out) { uint32_t wc, cb, need, msb, j, i = 0; - if ((wc = s[i++] & 255) == -1) return -1; + if ((wc = s[i++] & 255) == -1) + return -1; while ((wc & 0300) == 0200) { - if ((wc = s[i++] & 255) == -1) return -1; + if ((wc = s[i++] & 255) == -1) + return -1; } if (!(0 <= wc && wc <= 0x7F)) { msb = wc < 252 ? bsr(~wc & 0xff) : 1; need = 7 - msb; wc &= ((1u << msb) - 1) | 0003; for (j = 1; j < need; ++j) { - if ((cb = s[i++] & 255) == -1) return -1; + if ((cb = s[i++] & 255) == -1) + return -1; if ((cb & 0300) == 0200) { wc = wc << 6 | (cb & 077); } else { - if (out) *out = 0xFFFD; + if (out) + *out = 0xFFFD; return -1; } } } - if (out) *out = wc; + if (out) + *out = wc; return i; } @@ -71,7 +76,8 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) { bzero(&b, sizeof(b)); AppendStr(&b, "\e[H"); for (y = 0; y < tyn; ++y) { - if (y) AppendFmt(&b, "\e[%dH", y + 1); + if (y) + AppendFmt(&b, "\e[%dH", y + 1); for (x = i = 0; i < pn; ++i) { if (p[i].top <= y && y < p[i].bottom) { j = state = 0; diff --git a/tool/build/lz4toasm.c b/tool/build/lz4toasm.c index 7e548db5a..b13a16926 100644 --- a/tool/build/lz4toasm.c +++ b/tool/build/lz4toasm.c @@ -164,7 +164,8 @@ int main(int argc, char *argv[]) { } /* TODO(jart): Fix Emacs */ glyphs[col] = kCp437[ch == '"' || ch == '#' ? '.' : ch]; - if (col) fputc(',', fout); + if (col) + fputc(',', fout); fprintf(fout, "0x%02x", ch); if (++col == COLS) { col = 0; diff --git a/tool/build/march-native.c b/tool/build/march-native.c index 6b402a9fa..65f5845c4 100644 --- a/tool/build/march-native.c +++ b/tool/build/march-native.c @@ -76,13 +76,20 @@ int main(int argc, char *argv[]) { GetOpts(argc, argv); #ifdef __x86_64__ struct X86ProcessorModel *model; - if (X86_HAVE(XOP)) Puts("-mxop"); - if (X86_HAVE(SSE4A)) Puts("-msse4a"); - if (X86_HAVE(SSE3)) Puts("-msse3"); - if (X86_HAVE(SSSE3)) Puts("-mssse3"); - if (X86_HAVE(SSE4_1)) Puts("-msse4.1"); - if (X86_HAVE(SSE4_2)) Puts("-msse4.2"); - if (X86_HAVE(AVX)) Puts("-mavx"); + if (X86_HAVE(XOP)) + Puts("-mxop"); + if (X86_HAVE(SSE4A)) + Puts("-msse4a"); + if (X86_HAVE(SSE3)) + Puts("-msse3"); + if (X86_HAVE(SSSE3)) + Puts("-mssse3"); + if (X86_HAVE(SSE4_1)) + Puts("-msse4.1"); + if (X86_HAVE(SSE4_2)) + Puts("-msse4.2"); + if (X86_HAVE(AVX)) + Puts("-mavx"); if (X86_HAVE(AVX2)) { Puts("-mavx2"); if (!isclang) { @@ -90,27 +97,48 @@ int main(int argc, char *argv[]) { Puts("-Wa,-msse2avx"); } } - if (X86_HAVE(AVX512F)) Puts("-mavx512f"); - if (X86_HAVE(AVX512PF)) Puts("-mavx512pf"); - if (X86_HAVE(AVX512ER)) Puts("-mavx512er"); - if (X86_HAVE(AVX512CD)) Puts("-mavx512cd"); - if (X86_HAVE(AVX512VL)) Puts("-mavx512vl"); - if (X86_HAVE(AVX512BW)) Puts("-mavx512bw"); - if (X86_HAVE(AVX512DQ)) Puts("-mavx512dq"); - if (X86_HAVE(AVX512IFMA)) Puts("-mavx512ifma"); - if (X86_HAVE(AVX512VBMI)) Puts("-mavx512vbmi"); - if (X86_HAVE(SHA)) Puts("-msha"); - if (X86_HAVE(AES)) Puts("-maes"); - if (X86_HAVE(VAES)) Puts("-mvaes"); - if (X86_HAVE(PCLMUL)) Puts("-mpclmul"); - if (X86_HAVE(FSGSBASE)) Puts("-mfsgsbase"); - if (X86_HAVE(F16C)) Puts("-mf16c"); - if (X86_HAVE(FMA)) Puts("-mfma"); - if (X86_HAVE(POPCNT)) Puts("-mpopcnt"); - if (X86_HAVE(BMI)) Puts("-mbmi"); - if (X86_HAVE(BMI2)) Puts("-mbmi2"); - if (X86_HAVE(ADX)) Puts("-madx"); - if (X86_HAVE(FXSR)) Puts("-mfxsr"); + if (X86_HAVE(AVX512F)) + Puts("-mavx512f"); + if (X86_HAVE(AVX512PF)) + Puts("-mavx512pf"); + if (X86_HAVE(AVX512ER)) + Puts("-mavx512er"); + if (X86_HAVE(AVX512CD)) + Puts("-mavx512cd"); + if (X86_HAVE(AVX512VL)) + Puts("-mavx512vl"); + if (X86_HAVE(AVX512BW)) + Puts("-mavx512bw"); + if (X86_HAVE(AVX512DQ)) + Puts("-mavx512dq"); + if (X86_HAVE(AVX512IFMA)) + Puts("-mavx512ifma"); + if (X86_HAVE(AVX512VBMI)) + Puts("-mavx512vbmi"); + if (X86_HAVE(SHA)) + Puts("-msha"); + if (X86_HAVE(AES)) + Puts("-maes"); + if (X86_HAVE(VAES)) + Puts("-mvaes"); + if (X86_HAVE(PCLMUL)) + Puts("-mpclmul"); + if (X86_HAVE(FSGSBASE)) + Puts("-mfsgsbase"); + if (X86_HAVE(F16C)) + Puts("-mf16c"); + if (X86_HAVE(FMA)) + Puts("-mfma"); + if (X86_HAVE(POPCNT)) + Puts("-mpopcnt"); + if (X86_HAVE(BMI)) + Puts("-mbmi"); + if (X86_HAVE(BMI2)) + Puts("-mbmi2"); + if (X86_HAVE(ADX)) + Puts("-madx"); + if (X86_HAVE(FXSR)) + Puts("-mfxsr"); if ((model = (void *)getx86processormodel(kX86ProcessorModelKey))) { switch (model->march) { case X86_MARCH_CORE2: diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index 3aa2a2b69..8298ede11 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -176,37 +176,44 @@ static wontreturn void DieOom(void) { static unsigned Hash(const void *s, size_t l) { unsigned h; h = crc32c(0, s, l); - if (!h) h = 1; + if (!h) + h = 1; return h; } static void *Malloc(size_t n) { void *p; - if (!(p = malloc(n))) DieOom(); + if (!(p = malloc(n))) + DieOom(); return p; } static void *Calloc(size_t n, size_t z) { void *p; - if (!(p = calloc(n, z))) DieOom(); + if (!(p = calloc(n, z))) + DieOom(); return p; } static void *Realloc(void *p, size_t n) { - if (!(p = realloc(p, n))) DieOom(); + if (!(p = realloc(p, n))) + DieOom(); return p; } static void Appendw(char **b, uint64_t w) { - if (appendw(b, w) == -1) DieOom(); + if (appendw(b, w) == -1) + DieOom(); } static void Appends(char **b, const char *s) { - if (appends(b, s) == -1) DieOom(); + if (appends(b, s) == -1) + DieOom(); } static void Appendd(char **b, const void *p, size_t n) { - if (appendd(b, p, n) == -1) DieOom(); + if (appendd(b, p, n) == -1) + DieOom(); } static unsigned FindFirstFromEdge(unsigned id) { @@ -259,7 +266,8 @@ static void Rehash(void) { sources.n = sources.n ? sources.n << 1 : 16; sources.p = Calloc(sources.n, sizeof(struct Source)); for (i = 0; i < old.n; ++i) { - if (!old.p[i].hash) continue; + if (!old.p[i].hash) + continue; step = 0; do { j = (old.p[i].hash + step * (step + 1) / 2) & (sources.n - 1); @@ -286,7 +294,8 @@ static int HashSource(const char *name, size_t len, bool create) { step++; } while (sources.p[i].hash); } - if (!create) return -1; + if (!create) + return -1; if (++sources.i >= (sources.n >> 1)) { Rehash(); step = 0; @@ -439,17 +448,21 @@ static void LoadRelationships(int argc, char *argv[]) { DieSys(src); } for (p = map, pe = map + size; p < pe; ++p) { - if (!(p = memmem(p, pe - p, "include ", 8))) break; - if (!(path = FindIncludePath(map, size, p, is_assembly))) continue; + if (!(p = memmem(p, pe - p, "include ", 8))) + break; + if (!(path = FindIncludePath(map, size, p, is_assembly))) + continue; // copy the specified include path char right; if (path[-1] == '<') { - if (!systempaths.n) continue; + if (!systempaths.n) + continue; right = '>'; } else { right = '"'; } - if (!(pathend = memchr(path, right, pe - path))) continue; + if (!(pathend = memchr(path, right, pe - path))) + continue; if (pathend - path >= PATH_MAX) { tinyprint(2, src, ": uses really long include path\n", NULL); exit(1); @@ -620,7 +633,8 @@ static const char *StripExt(char pathbuf[hasatleast PATH_MAX], const char *s) { DiePathTooLong(s); } dot = strrchr(pathbuf, '.'); - if (dot) *dot = '\0'; + if (dot) + *dot = '\0'; return pathbuf; } @@ -630,9 +644,12 @@ static uint32_t GetFileExtension(const char *s) { n = s ? strlen(s) : 0; for (i = w = 0; n--;) { wint_t c = s[n]; - if (!IsGraph(c)) return 0; - if (c == '.') break; - if (++i > 4) return 0; + if (!IsGraph(c)) + return 0; + if (c == '.') + break; + if (++i > 4) + return 0; w <<= 8; w |= kToLower[c]; } @@ -655,7 +672,8 @@ static bool IsObjectSource(const char *name) { __funline bool Bts(uint32_t *p, size_t i) { uint32_t k; k = 1u << (i & 31); - if (p[i >> 5] & k) return true; + if (p[i >> 5] & k) + return true; p[i >> 5] |= k; return false; } @@ -663,7 +681,8 @@ __funline bool Bts(uint32_t *p, size_t i) { static void Dive(char **makefile, uint32_t *visited, unsigned id) { int i; for (i = FindFirstFromEdge(id); i < edges.i && edges.p[i].from == id; ++i) { - if (Bts(visited, edges.p[i].to)) continue; + if (Bts(visited, edges.p[i].to)) + continue; Appendw(makefile, READ32LE(" \\\n\t")); Appends(makefile, names + sauces[edges.p[i].to].name); Dive(makefile, visited, edges.p[i].to); @@ -681,8 +700,10 @@ static char *Explore(void) { visited = Malloc(visilen * sizeof(*visited)); for (i = 0; i < sources.i; ++i) { path = names + sauces[i].name; - if (!IsObjectSource(path)) continue; - if (startswith(path, genroot)) continue; + if (!IsObjectSource(path)) + continue; + if (startswith(path, genroot)) + continue; Appendw(&makefile, '\n'); Appends(&makefile, buildroot); Appends(&makefile, StripExt(buf, path)); @@ -707,7 +728,8 @@ int main(int argc, char *argv[]) { ShowCrashReports(); #endif prog = argv[0]; - if (!prog) prog = "mkdeps"; + if (!prog) + prog = "mkdeps"; GetOpts(argc, argv); LoadRelationships(argc, argv); Crunch(); diff --git a/tool/build/mkdir.c b/tool/build/mkdir.c index 28914e8e4..83175d254 100644 --- a/tool/build/mkdir.c +++ b/tool/build/mkdir.c @@ -35,7 +35,8 @@ int main(int argc, char *argv[]) { int (*mkdirp)(const char *, unsigned) = mkdir; prog = argv[0]; - if (!prog) prog = "mkdir"; + if (!prog) + prog = "mkdir"; while ((i = getopt(argc, argv, "hpm:")) != -1) { switch (i) { diff --git a/tool/build/mktemper.c b/tool/build/mktemper.c index 552eb47cb..9fdaf4395 100644 --- a/tool/build/mktemper.c +++ b/tool/build/mktemper.c @@ -45,13 +45,17 @@ static wontreturn void DieSys(const char *thing) { int main(int argc, char *argv[]) { const char *prog = program_invocation_short_name; - if (argc == 1) Die(prog, "missing argument"); - if (argc != 2) Die(prog, "too many arguments"); + if (argc == 1) + Die(prog, "missing argument"); + if (argc != 2) + Die(prog, "too many arguments"); char *template = argv[1]; char *substring = strstr(template, "XXXXXXXXXXXXX"); - if (!substring) Die(prog, "template missing XXXXXXXXXXXXX substring"); + if (!substring) + Die(prog, "template missing XXXXXXXXXXXXX substring"); uint64_t w; - if (getrandom(&w, 8, 0) != 8) DieSys("getrandom"); + if (getrandom(&w, 8, 0) != 8) + DieSys("getrandom"); for (int i = 0; i < 13; ++i) { substring[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[w % 36]; w /= 36; diff --git a/tool/build/mv.c b/tool/build/mv.c index 89932dba6..d1cc31b13 100644 --- a/tool/build/mv.c +++ b/tool/build/mv.c @@ -69,7 +69,8 @@ wontreturn void Die(const char *path, const char *reason) { wontreturn void SysDie(const char *path, const char *func) { const char *errstr; - if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN"; + if (!(errstr = _strerdoc(errno))) + errstr = "EUNKNOWN"; tinyprint(2, path, ": ", func, ": ", errstr, "\n", NULL); exit(1); } @@ -159,8 +160,10 @@ char *Join(const char *a, const char *b) { void Mv(char *src, char *dst) { ssize_t rc; const char *d; - if (strlen(src) + 1 > PATH_MAX) _Exit(2); - if (strlen(dst) + 1 > PATH_MAX) _Exit(2); + if (strlen(src) + 1 > PATH_MAX) + _Exit(2); + if (strlen(dst) + 1 > PATH_MAX) + _Exit(2); basename(src); basename(dst); if (IsDirectory(src)) { @@ -212,9 +215,11 @@ void Mv(char *src, char *dst) { int main(int argc, char *argv[]) { int i; prog = argv[0]; - if (!prog) prog = "mv"; + if (!prog) + prog = "mv"; GetOpts(argc, argv); - if (argc - optind < 2) PrintUsage(1, 2); + if (argc - optind < 2) + PrintUsage(1, 2); for (i = optind; i < argc - 1; ++i) { Mv(argv[i], argv[argc - 1]); } diff --git a/tool/build/objbincopy.c b/tool/build/objbincopy.c index ab3a906b5..ce08d0aed 100644 --- a/tool/build/objbincopy.c +++ b/tool/build/objbincopy.c @@ -130,9 +130,12 @@ static void GetOpts(int argc, char *argv[]) { static int PhdrFlagsToProt(Elf64_Word flags) { int prot = PROT_NONE; - if (flags & PF_R) prot |= PROT_READ; - if (flags & PF_W) prot |= PROT_WRITE; - if (flags & PF_X) prot |= PROT_EXEC; + if (flags & PF_R) + prot |= PROT_READ; + if (flags & PF_W) + prot |= PROT_WRITE; + if (flags & PF_X) + prot |= PROT_EXEC; return prot; } @@ -163,11 +166,13 @@ static void ValidateMachoSection(const char *inpath, // bool found_pagezero; bool found_unixthread; struct MachoLoadCommand *cmd; - if (!shdr) return; + if (!shdr) + return; if (elf->e_machine != EM_NEXGEN32E) { Die(inpath, ".macho section only supported for ELF x86_64"); } - if (!macho) Die(inpath, "corrupted .macho section content"); + if (!macho) + Die(inpath, "corrupted .macho section content"); if (shdr->sh_size < sizeof(struct MachoHeader)) { Die(inpath, ".macho section too small for mach-o header"); } @@ -349,10 +354,14 @@ static void HandleElf(const char *inpath, Elf64_Ehdr *elf, size_t esize) { elf->e_shentsize = 0; for (maxoff = i = 0; i < elf->e_phnum; ++i) { phdr = GetElfProgramHeaderAddress(elf, esize, i); - if (!phdr) Die(inpath, "corrupted elf header"); - if (phdr->p_type == PT_INTERP) Die(inpath, "PT_INTERP isn't supported"); - if (phdr->p_type == PT_DYNAMIC) Die(inpath, "PT_DYNAMIC isn't supported"); - if (!phdr->p_filesz) continue; + if (!phdr) + Die(inpath, "corrupted elf header"); + if (phdr->p_type == PT_INTERP) + Die(inpath, "PT_INTERP isn't supported"); + if (phdr->p_type == PT_DYNAMIC) + Die(inpath, "PT_DYNAMIC isn't supported"); + if (!phdr->p_filesz) + continue; maxoff = MAX(maxoff, phdr->p_offset + phdr->p_filesz); if (macho && phdr->p_type == PT_LOAD) { if (!(loadsegment = GetNextMachoLoadSegment(&loadcommand, &loadcount))) { @@ -417,7 +426,8 @@ static void HandleInput(const char *inpath) { int main(int argc, char *argv[]) { int i; prog = argv[0]; - if (!prog) prog = "objbincopy"; + if (!prog) + prog = "objbincopy"; GetOpts(argc, argv); if ((outfd = creat(outpath, 0755)) == -1) { DieSys(outpath); diff --git a/tool/build/package.c b/tool/build/package.c index dd74c66c4..c18b18248 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -160,7 +160,8 @@ static wontreturn void Die(const char *path, const char *reason) { static wontreturn void SysExit(const char *path, const char *func) { const char *errstr; - if (!(errstr = _strerrno(errno))) errstr = "EUNKNOWN"; + if (!(errstr = _strerrno(errno))) + errstr = "EUNKNOWN"; tinyprint(2, path, ": ", func, " failed with ", errstr, "\n", NULL); exit(1); } @@ -414,8 +415,10 @@ static void IndexSections(struct Package *pkg, struct Object *obj) { static enum SectionKind ClassifySection(struct Package *pkg, struct Object *obj, uint8_t type, Elf64_Section shndx) { - if (shndx == SHN_ABS) return kOther; - if (type == STT_COMMON) return kBss; + if (shndx == SHN_ABS) + return kOther; + if (type == STT_COMMON) + return kBss; return pkg->sections.p[obj->section_offset + shndx].kind; } @@ -476,10 +479,14 @@ static void LoadPriviligedRefsToUndefs(struct Package *pkg, } erela = rela + shdr->sh_size / sizeof(*rela); for (; rela < erela; ++rela) { - if (!ELF64_R_TYPE(rela->r_info)) continue; - if (!(x = ELF64_R_SYM(rela->r_info))) continue; - if (x > obj->symcount) Die("error", "elf overflow"); - if (obj->syms[x].st_shndx) continue; // symbol is defined + if (!ELF64_R_TYPE(rela->r_info)) + continue; + if (!(x = ELF64_R_SYM(rela->r_info))) + continue; + if (x > obj->symcount) + Die("error", "elf overflow"); + if (obj->syms[x].st_shndx) + continue; // symbol is defined if (ELF64_ST_BIND(obj->syms[x].st_info) != STB_WEAK && ELF64_ST_BIND(obj->syms[x].st_info) != STB_GLOBAL) { tinyprint(2, "warning: undefined symbol not global\n", NULL); @@ -526,7 +533,8 @@ static void OpenObject(struct Package *pkg, struct Object *obj, int oid) { } static void CloseObject(struct Object *obj) { - if (munmap(obj->elf, obj->size)) notpossible; + if (munmap(obj->elf, obj->size)) + notpossible; } static void LoadObjects(struct Package *pkg) { @@ -567,14 +575,18 @@ static bool FindSymbol(const char *name, struct Package *pkg, size_t i; struct Symbol *sym; if ((sym = BisectSymbol(pkg, name))) { - if (out_sym) *out_sym = sym; - if (out_pkg) *out_pkg = pkg; + if (out_sym) + *out_sym = sym; + if (out_pkg) + *out_pkg = pkg; return true; } for (i = 0; i < directdeps->i; ++i) { if ((sym = BisectSymbol(directdeps->p[i], name))) { - if (out_sym) *out_sym = sym; - if (out_pkg) *out_pkg = directdeps->p[i]; + if (out_sym) + *out_sym = sym; + if (out_pkg) + *out_pkg = directdeps->p[i]; return true; } } @@ -587,7 +599,8 @@ static void CheckStrictDeps(struct Package *pkg, struct Packages *deps) { struct Symbol *undef; for (i = 0; i < pkg->undefs.i; ++i) { undef = &pkg->undefs.p[i]; - if (undef->bind_ == STB_WEAK) continue; + if (undef->bind_ == STB_WEAK) + continue; if (!FindSymbol(pkg->strings.p + undef->name, pkg, deps, NULL, NULL)) { tinyprint(2, pkg->strings.p + pkg->path, ": undefined symbol '", pkg->strings.p + undef->name, "' (", @@ -621,7 +634,8 @@ static void CheckYourPrivilege(struct Package *pkg, struct Packages *deps) { ++f; } } - if (f) exit(1); + if (f) + exit(1); } static bool IsSymbolDirectlyReachable(struct Package *pkg, @@ -639,7 +653,8 @@ static void Package(int argc, char *argv[], struct Package *pkg, CheckYourPrivilege(pkg, deps); WritePackage(pkg); for (i = 0; i < deps->i; ++i) { - if (munmap(deps->p[i]->addr, deps->p[i]->size)) notpossible; + if (munmap(deps->p[i]->addr, deps->p[i]->size)) + notpossible; } } diff --git a/tool/build/pecheck.c b/tool/build/pecheck.c index e6284a360..f7586b88e 100644 --- a/tool/build/pecheck.c +++ b/tool/build/pecheck.c @@ -300,7 +300,8 @@ static void CheckPe(const char *path, char *map, size_t size) { Die(exe->path, "PE ImportLookupTable and ImportAddressTable should " "have identical content"); } - if (!*ilt) break; + if (!*ilt) + break; CheckPeImportByName(exe, *ilt); } } @@ -317,12 +318,17 @@ int main(int argc, char *argv[]) { #endif for (i = 1; i < argc; ++i) { path = argv[i]; - if ((fd = open(path, O_RDONLY)) == -1) DieSys(path); - if ((size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path); + if ((fd = open(path, O_RDONLY)) == -1) + DieSys(path); + if ((size = lseek(fd, 0, SEEK_END)) == -1) + DieSys(path); map = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (map == MAP_FAILED) DieSys(path); + if (map == MAP_FAILED) + DieSys(path); CheckPe(path, map, size); - if (munmap(map, size)) DieSys(path); - if (close(fd)) DieSys(path); + if (munmap(map, size)) + DieSys(path); + if (close(fd)) + DieSys(path); } } diff --git a/tool/build/pledge.c b/tool/build/pledge.c index 26af168e7..874f76669 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -202,8 +202,10 @@ long ParseSiSize(const char *s, long b) { } void AddPromise(const char *s) { - while (isspace(*s)) ++s; - if (!*s) return; + while (isspace(*s)) + ++s; + if (!*s) + return; if (*g_promises) { strlcat(g_promises, " ", sizeof(g_promises)); } @@ -358,9 +360,12 @@ void NormalizeFileDescriptors(void) { int SetLimit(int r, long lo, long hi) { struct rlimit old; struct rlimit lim = {lo, hi}; - if (r < 0 || r >= RLIM_NLIMITS) return 0; - if (!setrlimit(r, &lim)) return 0; - if (getrlimit(r, &old)) return -1; + if (r < 0 || r >= RLIM_NLIMITS) + return 0; + if (!setrlimit(r, &lim)) + return 0; + if (getrlimit(r, &old)) + return -1; lim.rlim_cur = MIN(lim.rlim_cur, old.rlim_max); lim.rlim_max = MIN(lim.rlim_max, old.rlim_max); return setrlimit(r, &lim); @@ -373,8 +378,10 @@ static int GetBaseCpuFreqMhz(void) { int SetCpuLimit(int secs) { #ifdef __x86_64__ int mhz, lim; - if (secs <= 0) return 0; - if (!(mhz = GetBaseCpuFreqMhz())) return eopnotsupp(); + if (secs <= 0) + return 0; + if (!(mhz = GetBaseCpuFreqMhz())) + return eopnotsupp(); lim = ceil(3100. / mhz * secs); return SetLimit(RLIMIT_CPU, lim, lim); #else @@ -464,8 +471,10 @@ enum Strategy GetStrategy(void) { void ApplyFilesystemPolicy(unsigned long ipromises) { const char *p; - if (g_dontunveil) return; - if (!SupportsLandlock()) return; + if (g_dontunveil) + return; + if (!SupportsLandlock()) + return; Unveil(g_prog, "rx"); @@ -587,7 +596,8 @@ void ApplyFilesystemPolicy(unsigned long ipromises) { void DropCapabilities(void) { int e, i; - if (!IsLinux()) return; + if (!IsLinux()) + return; for (e = errno, i = 0;; ++i) { if (prctl(PR_CAPBSET_DROP, i) == -1) { if (errno == EINVAL || errno == EPERM) { @@ -603,16 +613,21 @@ void DropCapabilities(void) { bool FileExistsAndIsNewerThan(const char *filepath, const char *thanpath) { struct stat st1, st2; - if (stat(filepath, &st1) == -1) return false; - if (stat(thanpath, &st2) == -1) return false; - if (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) return false; - if (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) return true; + if (stat(filepath, &st1) == -1) + return false; + if (stat(thanpath, &st2) == -1) + return false; + if (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) + return false; + if (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) + return true; return st1.st_mtim.tv_nsec >= st2.st_mtim.tv_nsec; } int Extract(const char *from, const char *to, int mode) { int fdin, fdout; - if ((fdin = open(from, O_RDONLY)) == -1) return -1; + if ((fdin = open(from, O_RDONLY)) == -1) + return -1; if ((fdout = creat(to, mode)) == -1) { close(fdin); return -1; @@ -627,7 +642,8 @@ int Extract(const char *from, const char *to, int mode) { int CountEnviron(char **ep) { int res = 0; - while (*ep++) ++res; + while (*ep++) + ++res; return res; } diff --git a/tool/build/rm.c b/tool/build/rm.c index 4df40c8b6..c5a041dbc 100644 --- a/tool/build/rm.c +++ b/tool/build/rm.c @@ -92,7 +92,8 @@ static int OnFile(const char *fpath, const struct stat *st, int typeflag, rc = unlink(fpath); } if (rc == -1) { - if (force && errno == ENOENT) return 0; + if (force && errno == ENOENT) + return 0; perror(fpath); exit(1); } @@ -110,7 +111,8 @@ static void Remove(const char *path) { rc = nftw(path, OnFile, 128, FTW_PHYS | FTW_DEPTH); } else { if (lstat(path, &st)) { - if (force && errno == ENOENT) return; + if (force && errno == ENOENT) + return; perror(path); exit(1); } @@ -125,7 +127,8 @@ static void Remove(const char *path) { } } if (rc == -1) { - if (force && errno == ENOENT) return; + if (force && errno == ENOENT) + return; perror(path); exit(1); } @@ -134,7 +137,8 @@ static void Remove(const char *path) { int main(int argc, char *argv[]) { int i; prog = argv[0]; - if (!prog) prog = "rm"; + if (!prog) + prog = "rm"; GetOpts(argc, argv); if (optind == argc) { tinyprint(2, prog, ": missing operand\n", NULL); diff --git a/tool/build/rollup.c b/tool/build/rollup.c index c1e5fda78..2dcc61596 100644 --- a/tool/build/rollup.c +++ b/tool/build/rollup.c @@ -57,11 +57,13 @@ static wontreturn void DieOom(void) { } static void Appends(char **b, const char *s) { - if (appends(b, s) == -1) DieOom(); + if (appends(b, s) == -1) + DieOom(); } static void Appendd(char **b, const void *p, size_t n) { - if (appendd(b, p, n) == -1) DieOom(); + if (appendd(b, p, n) == -1) + DieOom(); } size_t GetFdSize(int fd) { @@ -84,10 +86,12 @@ void Process(const char *p, const char *pe, const char *path, bool isheader) { p2 = memchr(p, '\n', pe - p); p2 = p2 ? p2 + 1 : pe; if (LOOKINGAT(p, pe, "#if")) { - if (isheader && !level++) continue; + if (isheader && !level++) + continue; } if (LOOKINGAT(p, pe, "#endif")) { - if (isheader && !--level) continue; + if (isheader && !--level) + continue; } if (LOOKINGAT(p, pe, "/* clang-format off */")) { noformat = true; @@ -114,26 +118,37 @@ void Visit(const char *path) { char *map; size_t size; bool isheader; - if (!endswith(path, ".h") && !endswith(path, ".inc")) return; - if (endswith(path, ".internal.h")) return; - if (endswith(path, "/internal.h")) return; - if (endswith(path, ".internal.inc")) return; - if (endswith(path, "/internal.inc")) return; - if (startswith(path, "libc/isystem/")) return; + if (!endswith(path, ".h") && !endswith(path, ".inc")) + return; + if (endswith(path, ".internal.h")) + return; + if (endswith(path, "/internal.h")) + return; + if (endswith(path, ".internal.inc")) + return; + if (endswith(path, "/internal.inc")) + return; + if (startswith(path, "libc/isystem/")) + return; isheader = endswith(path, ".h"); - if (isheader && isinterned(visited, path)) return; + if (isheader && isinterned(visited, path)) + return; Appends(&output, "\n\f\n/*!BEGIN "); Appends(&output, path); Appends(&output, " */\n\n"); intern(visited, path); - if ((fd = open(path, O_RDONLY)) == -1) DieSys(path); + if ((fd = open(path, O_RDONLY)) == -1) + DieSys(path); if ((size = GetFdSize(fd))) { map = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); - if (map == MAP_FAILED) DieSys(path); + if (map == MAP_FAILED) + DieSys(path); Process(map, map + size, path, isheader); - if (munmap(map, size)) DieSys(path); + if (munmap(map, size)) + DieSys(path); } - if (close(fd)) DieSys(path); + if (close(fd)) + DieSys(path); } int main(int argc, char *argv[]) { @@ -141,7 +156,8 @@ int main(int argc, char *argv[]) { const char *src; struct GetArgs ga; prog = argv[0]; - if (!prog) prog = "rollup"; + if (!prog) + prog = "rollup"; visited = newinterner(); Appends(&output, "#ifndef COSMOPOLITAN_H_\n"); Appends(&output, "#define COSMOPOLITAN_H_\n"); diff --git a/tool/build/runit.c b/tool/build/runit.c index 503a0a79f..3c0a55681 100644 --- a/tool/build/runit.c +++ b/tool/build/runit.c @@ -268,7 +268,8 @@ void RelayRequest(void) { rc = read(13, buf, PIPE_BUF); CHECK_NE(-1, rc); have = rc; - if (!rc) break; + if (!rc) + break; transferred += have; for (i = 0; i < have; i += rc) { rc = mbedtls_ssl_write(&ezssl, buf + i, have - i); @@ -288,9 +289,11 @@ void RelayRequest(void) { bool Recv(char *p, int n) { int i, rc; for (i = 0; i < n; i += rc) { - do rc = mbedtls_ssl_read(&ezssl, p + i, n - i); + do + rc = mbedtls_ssl_read(&ezssl, p + i, n - i); while (rc == MBEDTLS_ERR_SSL_WANT_READ); - if (!rc) return false; + if (!rc) + return false; if (rc < 0) { if (rc == MBEDTLS_ERR_NET_CONN_RESET) { EzTlsDie("connection reset", rc); @@ -334,10 +337,12 @@ int ReadResponse(void) { mbedtls_ssl_close_notify(&ezssl); break; } else if (msg[4] == kRunitStdout || msg[4] == kRunitStderr) { - if (!Recv(msg, 4)) goto TruncatedMessage; + if (!Recv(msg, 4)) + goto TruncatedMessage; int n = READ32BE(msg); char *s = malloc(n); - if (!Recv(s, n)) goto TruncatedMessage; + if (!Recv(s, n)) + goto TruncatedMessage; write(2, s, n); free(s); } else { @@ -356,7 +361,8 @@ int RunOnHost(char *spec) { int err; char *p; for (p = spec; *p; ++p) { - if (*p == ':') *p = ' '; + if (*p == ':') + *p = ' '; } int got = sscanf(spec, "%100s %hu %hu", g_hostname, &g_runitdport, &g_sshport); @@ -365,7 +371,8 @@ int RunOnHost(char *spec) { fprintf(stderr, "what on earth %#s -> %d\n", spec, got); exit(1); } - if (!strchr(g_hostname, '.')) strcat(g_hostname, ".test."); + if (!strchr(g_hostname, '.')) + strcat(g_hostname, ".test."); DEBUGF("connecting to %s port %d", g_hostname, g_runitdport); for (;;) { Connect(); @@ -373,7 +380,8 @@ int RunOnHost(char *spec) { struct timespec start = timespec_real(); err = EzHandshake2(); handshake_latency = timespec_tomicros(timespec_sub(timespec_real(), start)); - if (!err) break; + if (!err) + break; WARNF("handshake with %s:%d failed -0x%04x (%s)", // g_hostname, g_runitdport, err, GetTlsError(err)); close(g_sock); @@ -446,22 +454,27 @@ int SpawnSubprocesses(int argc, char *argv[]) { // wait for children to terminate for (;;) { if ((pid = wait(&ws)) == -1) { - if (errno == EINTR) continue; - if (errno == ECHILD) break; + if (errno == EINTR) + continue; + if (errno == ECHILD) + break; FATALF("wait failed"); } for (i = 0; i < argc; ++i) { - if (pids[i] != pid) continue; + if (pids[i] != pid) + continue; if (WIFEXITED(ws)) { if (WEXITSTATUS(ws)) { INFOF("%s exited with %d", argv[i], WEXITSTATUS(ws)); } else { DEBUGF("%s exited with %d", argv[i], WEXITSTATUS(ws)); } - if (!exitcode) exitcode = WEXITSTATUS(ws); + if (!exitcode) + exitcode = WEXITSTATUS(ws); } else { INFOF("%s terminated with %s", argv[i], strsignal(WTERMSIG(ws))); - if (!exitcode) exitcode = 128 + WTERMSIG(ws); + if (!exitcode) + exitcode = 128 + WTERMSIG(ws); } break; } diff --git a/tool/build/runitd.c b/tool/build/runitd.c index 10a830e86..7c8023499 100644 --- a/tool/build/runitd.c +++ b/tool/build/runitd.c @@ -515,8 +515,10 @@ void *ClientWorker(void *arg) { int i = 0; char *args[8] = {0}; args[i++] = client->tmpexepath; - if (use_strace) args[i++] = "--strace"; - if (use_ftrace) args[i++] = "--ftrace"; + if (use_strace) + args[i++] = "--strace"; + if (use_ftrace) + args[i++] = "--ftrace"; // run program, tee'ing stderr to both log and client DEBUF("spawning %s", client->tmpexepath); @@ -776,11 +778,14 @@ int Serve(void) { } void Daemonize(void) { - if (fork() > 0) _exit(0); + if (fork() > 0) + _exit(0); setsid(); - if (fork() > 0) _exit(0); + if (fork() > 0) + _exit(0); dup2(g_bogusfd, 0); - if (!g_sendready) dup2(g_bogusfd, 1); + if (!g_sendready) + dup2(g_bogusfd, 1); close(2); open(kLogFile, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0644); extern long __klog_handle; @@ -796,7 +801,8 @@ int main(int argc, char *argv[]) { signal(SIGPIPE, SIG_IGN); setenv("TZ", "PST", true); gethostname(g_hostname, sizeof(g_hostname)); - for (int i = 3; i < 16; ++i) close(i); + for (int i = 3; i < 16; ++i) + close(i); errno = 0; // poll()'ing /dev/null stdin file descriptor on xnu returns POLLNVAL?! if (IsWindows()) { @@ -805,7 +811,8 @@ int main(int argc, char *argv[]) { g_bogusfd = open("/dev/zero", O_RDONLY | O_CLOEXEC); } mkdir("o", 0700); - if (g_daemonize) Daemonize(); + if (g_daemonize) + Daemonize(); Serve(); free(g_psk); #ifdef MODE_DBG diff --git a/tool/build/sha256sum.c b/tool/build/sha256sum.c index 58d258948..369676127 100644 --- a/tool/build/sha256sum.c +++ b/tool/build/sha256sum.c @@ -102,7 +102,8 @@ static bool IsSupportedPath(const char *path) { for (i = 0;; ++i) { switch (path[i]) { case 0: - if (i) return true; + if (i) + return true; // fallthrough case '\r': case '\n': @@ -137,8 +138,10 @@ static bool ProduceDigest(const char *path, FILE *f) { char hexdigest[65]; char mode[2] = {g_mode}; unsigned char digest[32]; - if (!IsSupportedPath(path)) return false; - if (!GetDigest(path, f, digest)) return false; + if (!IsSupportedPath(path)) + return false; + if (!GetDigest(path, f, digest)) + return false; hexpcpy(hexdigest, digest, 32); tinyprint(1, hexdigest, " ", mode, path, "\n", NULL); return true; @@ -152,17 +155,24 @@ static bool CheckDigests(const char *path, FILE *f) { unsigned char wantdigest[32], gotdigest[32]; char buf[64 + 2 + PATH_MAX + 1 + 1], *p; for (line = 0; fgets(buf, sizeof(buf), f); ++line) { - if (!*chomp(buf)) continue; + if (!*chomp(buf)) + continue; for (p = buf, i = 0; i < 32; ++i) { - if ((a = kHexToInt[*p++ & 255]) == -1) goto InvalidLine; - if ((b = kHexToInt[*p++ & 255]) == -1) goto InvalidLine; + if ((a = kHexToInt[*p++ & 255]) == -1) + goto InvalidLine; + if ((b = kHexToInt[*p++ & 255]) == -1) + goto InvalidLine; wantdigest[i] = a << 4 | b; } - if (*p++ != ' ') goto InvalidLine; - if (!IsModeCharacter(*p++)) goto InvalidLine; + if (*p++ != ' ') + goto InvalidLine; + if (!IsModeCharacter(*p++)) + goto InvalidLine; path2 = p; - if (!*path2) goto InvalidLine; - if (!IsSupportedPath(path2)) continue; + if (!*path2) + goto InvalidLine; + if (!IsSupportedPath(path2)) + continue; if ((f2 = fopen(path2, "rb"))) { if (GetDigest(path2, f2, gotdigest)) { if (!memcmp(wantdigest, gotdigest, 32)) { @@ -210,7 +220,8 @@ int main(int argc, char *argv[]) { FILE *f; bool k = true; prog = argv[0]; - if (!prog) prog = "sha256sum"; + if (!prog) + prog = "sha256sum"; GetOpts(argc, argv); if (optind == argc) { f = stdin; diff --git a/tool/build/summy.c b/tool/build/summy.c index b101c5c05..a98514663 100644 --- a/tool/build/summy.c +++ b/tool/build/summy.c @@ -26,9 +26,11 @@ int main(int argc, char *argv[]) { long x, sum = 0; if (argc == 2 && !strcmp(argv[1], "-x")) { - while (scanf("%lx", &x) > 0) sum += x; + while (scanf("%lx", &x) > 0) + sum += x; } else { - while (scanf("%ld", &x) > 0) sum += x; + while (scanf("%ld", &x) > 0) + sum += x; } printf("%,ld\n", sum); return 0; diff --git a/tool/build/touch.c b/tool/build/touch.c index 41acc5e50..5cc09dad2 100644 --- a/tool/build/touch.c +++ b/tool/build/touch.c @@ -29,7 +29,8 @@ int main(int argc, char *argv[]) { const char *prog; prog = argv[0]; - if (!prog) prog = "touch"; + if (!prog) + prog = "touch"; if (argc < 2) { tinyprint(2, prog, ": missing operand\n", NULL); diff --git a/tool/build/unveil.c b/tool/build/unveil.c index 97b6ee0f2..83020b9b6 100644 --- a/tool/build/unveil.c +++ b/tool/build/unveil.c @@ -91,10 +91,12 @@ int main(int argc, char *argv[]) { p++; continue; } - if (i > 1) errx(1, ":%zu - too many fields", count); + if (i > 1) + errx(1, ":%zu - too many fields", count); fields[i++] = p; } - if (i != 2) errx(1, ":%zu - malformed line", count); + if (i != 2) + errx(1, ":%zu - malformed line", count); if (unveil(fields[0], fields[1]) == -1) err(1, "unveil(%s, %s)", fields[0], fields[1]); @@ -104,7 +106,8 @@ int main(int argc, char *argv[]) { err(1, "getline"); } - if (unveil(NULL, NULL) == -1) err(1, "unveil(NULL, NULL)"); + if (unveil(NULL, NULL) == -1) + err(1, "unveil(NULL, NULL)"); __sys_execve(prog, argv + optind, environ); err(127, "execve"); diff --git a/tool/build/verynice.c b/tool/build/verynice.c index 0c142d866..68de92a4b 100644 --- a/tool/build/verynice.c +++ b/tool/build/verynice.c @@ -38,7 +38,8 @@ static wontreturn void PrintUsage(int rc, int fd) { int main(int argc, char *argv[]) { prog = argv[0]; - if (!prog) prog = "verynice"; + if (!prog) + prog = "verynice"; int opt; while ((opt = getopt(argc, argv, "h")) != -1) { diff --git a/tool/build/zipcopy.c b/tool/build/zipcopy.c index 0fa328896..125ab57ae 100644 --- a/tool/build/zipcopy.c +++ b/tool/build/zipcopy.c @@ -51,7 +51,8 @@ static wontreturn void Die(const char *path, const char *reason) { static wontreturn void SysDie(const char *path, const char *func) { const char *errstr; - if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN"; + if (!(errstr = _strerdoc(errno))) + errstr = "EUNKNOWN"; tinyprint(2, path, ": ", func, " failed with ", errstr, "\n", NULL); exit(1); } @@ -133,7 +134,8 @@ static void CopyZip(void) { eocd = ineof - kZipCdirHdrMinSize; stop = MAX(eocd - 65536, inmap); for (;; --eocd) { - if (eocd < stop) return; + if (eocd < stop) + return; if (READ32LE(eocd) == kZipCdirHdrMagic) { if (IsZipEocd32(inmap, insize, eocd - inmap) != kZipOk) { Die(inpath, "found bad eocd record"); @@ -217,7 +219,8 @@ int main(int argc, char *argv[]) { ShowCrashReports(); #endif prog = argv[0]; - if (!prog) prog = "apelink"; + if (!prog) + prog = "apelink"; GetOpts(argc, argv); if ((infd = open(inpath, O_RDONLY)) == -1) { SysDie(inpath, "open"); diff --git a/tool/build/zipobj.c b/tool/build/zipobj.c index 063447c6c..f07193539 100644 --- a/tool/build/zipobj.c +++ b/tool/build/zipobj.c @@ -189,9 +189,11 @@ void ProcessFile(struct ElfWriter *elf, const char *path) { name = name_; } else { name = path; - if (basenamify_) name = basename(gc(xstrdup(name))); + if (basenamify_) + name = basename(gc(xstrdup(name))); name = StripComponents(name, strip_components_); - if (path_prefix_) name = gc(xjoinpaths(path_prefix_, name)); + if (path_prefix_) + name = gc(xjoinpaths(path_prefix_, name)); } if (S_ISDIR(st.st_mode)) { st.st_size = 0; @@ -225,10 +227,12 @@ void zipobj(int argc, char **argv) { struct ElfWriter *elf; unassert(argc < UINT16_MAX / 3 - 64); /* ELF 64k section limit */ GetOpts(&argc, &argv); - for (i = 0; i < argc; ++i) CheckFilenameKosher(argv[i]); + for (i = 0; i < argc; ++i) + CheckFilenameKosher(argv[i]); elf = elfwriter_open(outpath_, 0644, arch_); elfwriter_cargoculting(elf); - for (i = 0; i < argc; ++i) ProcessFile(elf, argv[i]); + for (i = 0; i < argc; ++i) + ProcessFile(elf, argv[i]); PullEndOfCentralDirectoryIntoLinkage(elf); elfwriter_close(elf); } diff --git a/tool/curl/curl.c b/tool/curl/curl.c index fd9935de8..dee042191 100644 --- a/tool/curl/curl.c +++ b/tool/curl/curl.c @@ -64,7 +64,8 @@ static wontreturn void PrintUsage(int fd, int rc) { static const char *DescribeErrno(void) { const char *reason; - if (!(reason = _strerdoc(errno))) reason = "Unknown error"; + if (!(reason = _strerdoc(errno))) + reason = "Unknown error"; return reason; } @@ -499,7 +500,8 @@ int _curl(int argc, char *argv[]) { break; case kHttpClientStateBody: WriteOutput(p + i - g, g); - if (!g) goto Finished; + if (!g) + goto Finished; break; case kHttpClientStateBodyLengthed: unassert(g); diff --git a/tool/decode/ar.c b/tool/decode/ar.c index cc3471277..b1bd1892c 100644 --- a/tool/decode/ar.c +++ b/tool/decode/ar.c @@ -60,7 +60,8 @@ static void Open(void) { exit(1); } CHECK_NE(-1, fstat(fd, &st)); - if (!(size = st.st_size)) exit(0); + if (!(size = st.st_size)) + exit(0); CHECK_NE(MAP_FAILED, (data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0))); LOGIFNEG1(close(fd)); @@ -136,7 +137,8 @@ static void Print(void) { } int main(int argc, char *argv[]) { - if (argc < 2) return 1; + if (argc < 2) + return 1; path = argv[1]; Open(); Check(); diff --git a/tool/decode/base64.c b/tool/decode/base64.c index d4a811369..1e6512c69 100644 --- a/tool/decode/base64.c +++ b/tool/decode/base64.c @@ -52,8 +52,10 @@ void Encode(void) { b = getchar(); c = getchar(); w = a << 020; - if (b != -1) w |= b << 010; - if (c != -1) w |= c; + if (b != -1) + w |= b << 010; + if (c != -1) + w |= c; putchar(CHARS[(w >> 18) & 077]); putchar(CHARS[(w >> 12) & 077]); putchar(b != -1 ? CHARS[(w >> 6) & 077] : '='); @@ -65,7 +67,8 @@ void Encode(void) { int Get(void) { int c; while ((c = getchar()) != -1) { - if ((c = kBase64[c]) != -1) break; + if ((c = kBase64[c]) != -1) + break; } return c; } @@ -76,11 +79,15 @@ void Decode(void) { c = Get(); d = Get(); w = a << 18 | b << 12; - if (c != -1) w |= c << 6; - if (d != -1) w |= d; + if (c != -1) + w |= c << 6; + if (d != -1) + w |= d; putchar((w & 0xFF0000) >> 020); - if (c != -1) putchar((w & 0x00FF00) >> 010); - if (d != -1) putchar((w & 0x0000FF) >> 000); + if (c != -1) + putchar((w & 0x00FF00) >> 010); + if (d != -1) + putchar((w & 0x0000FF) >> 000); } } diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 2e59203d4..741ad381f 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -109,7 +109,8 @@ static void printelfehdr(void) { static void printelfsegmentheader(int i) { Elf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, i); - if (!phdr) return; + if (!phdr) + return; printf("/\tElf64_Phdr *phdr = GetElfProgramHeaderAddress(elf, st->st_size, " "%d)\n", i); @@ -132,13 +133,15 @@ static void printelfsegmentheader(int i) { static void printelfsegmentheaders(void) { printf("\n"); printf("\t.org\t%#x\n", elf->e_phoff); - for (unsigned i = 0; i < elf->e_phnum; ++i) printelfsegmentheader(i); + for (unsigned i = 0; i < elf->e_phnum; ++i) + printelfsegmentheader(i); } static void printelfsectionheader(int i, char *shstrtab) { Elf64_Shdr *shdr; shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); - if (!shdr) return; + if (!shdr) + return; printf("/\tElf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, " "%d)\n", i); @@ -170,7 +173,8 @@ static void printelfsectionheaders(void) { Elf64_Shdr *shdr, *shshdr; shshdr = GetElfSectionHeaderAddress(elf, st->st_size, elf->e_shstrndx); shstrtab = GetElfSectionNameStringTable(elf, st->st_size); - if (!shshdr || !shstrtab) return; + if (!shshdr || !shstrtab) + return; if (shstrtab) { printf("\n"); printf("\t.org\t%#x\n", elf->e_shoff); @@ -181,7 +185,8 @@ static void printelfsectionheaders(void) { printf("\t.org\t%#x\n", shshdr->sh_offset); for (i = 0; i < elf->e_shnum; ++i) { shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); - if (!shdr) break; + if (!shdr) + break; str = GetElfString(elf, st->st_size, shstrtab, shdr->sh_name); show(".asciz", format(b1, "%`'s", str), NULL); } @@ -191,18 +196,23 @@ static void printelfsectionheaders(void) { static void printelfgroups(void) { for (int i = 0; i < elf->e_shnum; ++i) { Elf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, i); - if (!shdr) break; + if (!shdr) + break; if (shdr->sh_type == SHT_GROUP) { const Elf64_Shdr *symhdr = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link); - if (!symhdr) break; + if (!symhdr) + break; const Elf64_Shdr *strhdr = GetElfSectionHeaderAddress(elf, st->st_size, symhdr->sh_link); - if (!strhdr) break; + if (!strhdr) + break; Elf64_Sym *syms = GetElfSectionAddress(elf, st->st_size, symhdr); - if (!syms) break; + if (!syms) + break; char *strs = GetElfSectionAddress(elf, st->st_size, strhdr); - if (!strs) break; + if (!strs) + break; printf("\n"); printf("//\t%s group\n", GetElfString(elf, st->st_size, strs, syms[shdr->sh_info].st_name)); @@ -276,7 +286,8 @@ static void printelfsymbol(Elf64_Sym *sym, char *strtab, char *shstrtab) { static void printelfsymboltable(void) { size_t i, symcount = 0; Elf64_Sym *symtab = GetElfSymbols(elf, st->st_size, SHT_SYMTAB, &symcount); - if (!symtab) return; + if (!symtab) + return; char *strtab = GetElfStringTable(elf, st->st_size, ".strtab"); char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); printf("\n\n"); @@ -292,7 +303,8 @@ static void printelfsymboltable(void) { static void printelfdynsymboltable(void) { size_t i, symcount = 0; Elf64_Sym *symtab = GetElfSymbols(elf, st->st_size, SHT_DYNSYM, &symcount); - if (!symtab) return; + if (!symtab) + return; char *strtab = GetElfStringTable(elf, st->st_size, ".dynstr"); char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size); printf("\n\n"); @@ -342,7 +354,8 @@ static void printelfrelocations(void) { (uintptr_t)elf + shdr->sh_offset + shdr->sh_size)); ++rela, ++j) { symtab = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link); - if (!symtab) continue; + if (!symtab) + continue; count = symtab->sh_size / symtab->sh_entsize; syms = GetElfSectionAddress(elf, st->st_size, symtab); sym = ELF64_R_SYM(rela->r_info); diff --git a/tool/decode/lib/asmcodegen.c b/tool/decode/lib/asmcodegen.c index c969a53b9..1e4520a3c 100644 --- a/tool/decode/lib/asmcodegen.c +++ b/tool/decode/lib/asmcodegen.c @@ -40,7 +40,8 @@ char *tabpad(const char *s, unsigned width) { l = strlen(s); need = width > l ? (roundup(width, 8) - l - 1) / 8 + 1 : 0; p = memcpy(malloc(l + need + 2), s, l); - for (i = 0; i < need; ++i) p[l + i] = '\t'; + for (i = 0; i < need; ++i) + p[l + i] = '\t'; if (!need) { p[l] = ' '; ++need; diff --git a/tool/decode/lib/disassemblehex.c b/tool/decode/lib/disassemblehex.c index 201cc96a8..77b1a20d1 100644 --- a/tool/decode/lib/disassemblehex.c +++ b/tool/decode/lib/disassemblehex.c @@ -24,7 +24,8 @@ static size_t countzeroes(const uint8_t *data, size_t size) { size_t i; for (i = 0; i < size; ++i) { - if (data[i] != '\0') break; + if (data[i] != '\0') + break; } return i; } @@ -42,19 +43,22 @@ void disassemblehex(uint8_t *data, size_t size, FILE *f) { if (z > 2) { fprintf(f, "\t.%s\t%zu*%d\n", "zero", z, kDisassembleHexColumns); i += z * kDisassembleHexColumns; - if (i == size) break; + if (i == size) + break; } fprintf(f, "\t.%s\t", "byte"); bzero(glyphs, sizeof(glyphs)); } /* TODO(jart): Fix Emacs */ glyphs[col] = kCp437[ch == '"' || ch == '\\' || ch == '#' ? '.' : ch]; - if (col) fputc(',', f); + if (col) + fputc(',', f); fprintf(f, "0x%02x", ch); if (++col == kDisassembleHexColumns) { col = 0; fprintf(f, "\t#%hs\n", glyphs); } } - if (col) fputc('\n', f); + if (col) + fputc('\n', f); } diff --git a/tool/decode/lib/flagger.c b/tool/decode/lib/flagger.c index 51dc8e797..ba22393b2 100644 --- a/tool/decode/lib/flagger.c +++ b/tool/decode/lib/flagger.c @@ -50,7 +50,8 @@ char *RecreateFlags(const struct IdName *names, unsigned long id) { } } if (id) { - if (bufi) APPEND(&bufp, &bufi, &bufn, "|"); + if (bufi) + APPEND(&bufp, &bufi, &bufn, "|"); CONCAT(&bufp, &bufi, &bufn, extrabuf, snprintf(extrabuf, sizeof(extrabuf), "%#x", id)); } else if (!bufi) { diff --git a/tool/decode/lib/titlegen.c b/tool/decode/lib/titlegen.c index d45e064ca..2d45ded1d 100644 --- a/tool/decode/lib/titlegen.c +++ b/tool/decode/lib/titlegen.c @@ -40,14 +40,17 @@ void showtitle(const char *brand, const char *tool, const char *title, printf("/*"); if (modeline) { printf("-*-%-71s-*-│\n│ vi:%-70s:vi │\n╞", modeline->emacs, modeline->vim); - for (unsigned i = 0; i < 78; ++i) printf("═"); + for (unsigned i = 0; i < 78; ++i) + printf("═"); printf("╡\n│ %-76s ", buf); } else { - for (unsigned i = 0; i < 75; ++i) printf("─"); + for (unsigned i = 0; i < 75; ++i) + printf("─"); printf("│─╗\n│ %-73s ─╬─", buf); } printf("│\n╚─"); - for (unsigned i = 0; i < 75; ++i) printf("─"); + for (unsigned i = 0; i < 75; ++i) + printf("─"); printf("%s", modeline ? "─" : "│"); if (description) { /* TODO(jart): paragraph fill */ diff --git a/tool/decode/macho.c b/tool/decode/macho.c index 519179ec0..736ad4078 100644 --- a/tool/decode/macho.c +++ b/tool/decode/macho.c @@ -187,7 +187,8 @@ static void showmacholoadgeneric(struct MachoLoadCommand *lc) { bzero(glyphs, sizeof(glyphs)); } glyphs[col] = kCp437[c]; - if (col) putchar(','); + if (col) + putchar(','); printf("0x%02x", c); if (++col == COLS) { col = 0; @@ -334,7 +335,8 @@ void showall(void) { int main(int argc, char *argv[]) { int64_t fd; struct stat st[1]; - if (argc != 2) fprintf(stderr, "usage: %s FILE\n", argv[0]), exit(1); + if (argc != 2) + fprintf(stderr, "usage: %s FILE\n", argv[0]), exit(1); if ((fd = open((path = argv[1]), O_RDONLY)) == -1 || fstat(fd, st) == -1 || (macho = mmap(NULL, (machosize = st->st_size), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { diff --git a/tool/decode/pe2.c b/tool/decode/pe2.c index f960f29b7..3d8ab4eb2 100644 --- a/tool/decode/pe2.c +++ b/tool/decode/pe2.c @@ -56,7 +56,8 @@ static struct NtImageSectionHeader *sections; static size_t section_count; static void *GetOff(uint32_t off) { - if (off < mzsize) return (char *)mz + off; + if (off < mzsize) + return (char *)mz + off; fprintf(stderr, "%s: off %#x not defined within image\n", path, off); exit(1); } @@ -377,7 +378,8 @@ int main(int argc, char *argv[]) { int64_t fd; struct stat st[1]; ShowCrashReports(); - if (argc != 2) fprintf(stderr, "usage: %s FILE\n", argv[0]), exit(1); + if (argc != 2) + fprintf(stderr, "usage: %s FILE\n", argv[0]), exit(1); if ((fd = open((path = argv[1]), O_RDONLY)) == -1 || fstat(fd, st) == -1 || (mz = mmap(NULL, (mzsize = st->st_size), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { diff --git a/tool/lambda/blcdump.c b/tool/lambda/blcdump.c index 3ece4ae4d..6cd2601ee 100644 --- a/tool/lambda/blcdump.c +++ b/tool/lambda/blcdump.c @@ -95,7 +95,8 @@ void LoadFlags(int argc, char *argv[]) { } void Expand(int c) { - if (end >= TERMS) Error(5, "OUT OF TERMS"); + if (end >= TERMS) + Error(5, "OUT OF TERMS"); mem[end++] = c; } diff --git a/tool/lambda/bru2bin.c b/tool/lambda/bru2bin.c index c45c65d9e..2516ff0f9 100644 --- a/tool/lambda/bru2bin.c +++ b/tool/lambda/bru2bin.c @@ -115,7 +115,8 @@ static int Greed(void) { } else { c = fgetwc(stdin); } - if (c == EOF) return c; + if (c == EOF) + return c; if (!t) { if (c == '#' || c == ';') { t = 1; @@ -218,7 +219,8 @@ static int Greed(void) { static int Need(void) { int c; - if ((c = Greed()) != EOF) return c; + if ((c = Greed()) != EOF) + return c; Error(1, "unfinished expression"); } @@ -227,7 +229,8 @@ static struct Node *Parse1(void) { int i, oldsp; struct Node *r, *p, *q; do { - if ((c = Greed()) == EOF) return 0; + if ((c = Greed()) == EOF) + return 0; } while (iswspace(c)); if (c == L'λ' || c == '\\') { oldsp = sp; @@ -245,7 +248,8 @@ static struct Node *Parse1(void) { } } q = Parse1(); - if (!q) Error(4, "lambda needs body"); + if (!q) + Error(4, "lambda needs body"); p->l = q; while ((q = Parse1())) { p->l = NewNode(2, 0, p->l, q); @@ -261,23 +265,27 @@ static struct Node *Parse1(void) { i *= 10; i += c - '0'; c = Greed(); - if (c == EOF) break; + if (c == EOF) + break; if (!iswdigit(c)) { unget = c; break; } } i -= indexing; - if (i < 0) Error(5, "undefined variable: %lc", c); + if (i < 0) + Error(5, "undefined variable: %lc", c); return NewNode(1, i, 0, 0); } else if (c == '(') { p = r = Parse1(); - if (!p) Error(6, "empty parenthesis"); + if (!p) + Error(6, "empty parenthesis"); while ((q = Parse1())) { r = NewNode(2, 0, r, q); } c = Need(); - if (c != ')') Error(7, "expected closing parenthesis"); + if (c != ')') + Error(7, "expected closing parenthesis"); return r; } else if (c == ')') { unget = c; @@ -290,7 +298,8 @@ static struct Node *Parse1(void) { static struct Node *Parse(void) { struct Node *r, *p, *q; p = r = Parse1(); - if (!p) Error(6, "empty expression"); + if (!p) + Error(6, "empty expression"); while ((q = Parse1())) { r = NewNode(2, 0, r, q); } diff --git a/tool/lambda/lam2bin.c b/tool/lambda/lam2bin.c index 94498e30a..9c8dd8fb5 100644 --- a/tool/lambda/lam2bin.c +++ b/tool/lambda/lam2bin.c @@ -107,7 +107,8 @@ static int Greed(void) { } else { c = fgetwc(stdin); } - if (c == EOF) return c; + if (c == EOF) + return c; if (!t) { if (c == '#' || c == ';') { t = 1; @@ -119,7 +120,8 @@ static int Greed(void) { } continue; } - if (iswspace(c)) continue; + if (iswspace(c)) + continue; if (!str) { switch (c) { case L'⊥': @@ -211,7 +213,8 @@ static int Greed(void) { static int Need(void) { int c; - if ((c = Greed()) != EOF) return c; + if ((c = Greed()) != EOF) + return c; Error(1, "unfinished expression"); } @@ -219,20 +222,24 @@ static struct Node *Parse1(void) { wint_t c; int i, oldsp; struct Node *r, *p, *q; - if ((c = Greed()) == EOF) return 0; + if ((c = Greed()) == EOF) + return 0; if (c == L'λ' || c == '\\') { oldsp = sp; c = Need(); - if (!(isalnum(c) || c == '_')) Error(2, "lambda needs argument"); + if (!(isalnum(c) || c == '_')) + Error(2, "lambda needs argument"); p = r = NewNode(0, 0, 0, 0); args[sp++] = c; while ((c = Need()) != '.') { - if (!(isalnum(c) || c == '_')) Error(3, "lambda needs argument"); + if (!(isalnum(c) || c == '_')) + Error(3, "lambda needs argument"); p = p->l = NewNode(0, 0, 0, 0); args[sp++] = c; } q = Parse1(); - if (!q) Error(4, "lambda needs body"); + if (!q) + Error(4, "lambda needs body"); p->l = q; while ((q = Parse1())) { p->l = NewNode(2, 0, p->l, q); @@ -249,16 +256,19 @@ static struct Node *Parse1(void) { break; } } - if (i < 0) Error(5, "undefined variable: %d %lc", c, c); + if (i < 0) + Error(5, "undefined variable: %d %lc", c, c); return NewNode(1, i, 0, 0); } else if (c == '(') { p = r = Parse1(); - if (!p) Error(6, "empty parenthesis"); + if (!p) + Error(6, "empty parenthesis"); while ((q = Parse1())) { r = NewNode(2, 0, r, q); } c = Need(); - if (c != ')') Error(7, "expected closing parenthesis"); + if (c != ')') + Error(7, "expected closing parenthesis"); return r; } else if (c == ')') { unget = c; @@ -271,7 +281,8 @@ static struct Node *Parse1(void) { static struct Node *Parse(void) { struct Node *r, *p, *q; p = r = Parse1(); - if (!p) Error(6, "empty expression"); + if (!p) + Error(6, "empty expression"); while ((q = Parse1())) { r = NewNode(2, 0, r, q); } diff --git a/tool/lambda/lambda.c b/tool/lambda/lambda.c index 4047c8019..1e0a18135 100644 --- a/tool/lambda/lambda.c +++ b/tool/lambda/lambda.c @@ -101,14 +101,16 @@ int Backref(int x) { } static inline void Expand(int c) { - if (end >= TERMS) Error(5, "OUT OF TERMS"); + if (end >= TERMS) + Error(5, "OUT OF TERMS"); mem[end++] = c; } void Gc(struct Closure *p) { struct Closure *t; while (p && p != &root) { - if (--p->refs) break; + if (--p->refs) + break; Gc(p->next); t = p->envp; p->envp = 0; @@ -123,8 +125,10 @@ void Var(void) { struct Closure *t, *e; e = t = envp; x = mem[ip + 1]; - for (i = 0; i < x && e != &root; ++i) e = e->next; - if (e == &root) Error(10 + x, "UNDEFINED VARIABLE %d", x); + for (i = 0; i < x && e != &root; ++i) + e = e->next; + if (e == &root) + Error(10 + x, "UNDEFINED VARIABLE %d", x); ip = e->term; envp = REF(e->envp); Gc(t); @@ -171,14 +175,17 @@ void Put(void) { void Bye(void) { int rc = mem[ip + 2]; // (λ 0) [exitcode] - if (rc) Error(rc, "CONTINUATIONS EXHAUSTED"); - if (postdump && !rc) Dump(0, end, stderr); + if (rc) + Error(rc, "CONTINUATIONS EXHAUSTED"); + if (postdump && !rc) + Dump(0, end, stderr); exit(0); } // pops continuation and pushes it to environment void Abs(void) { - if (!contp) Bye(); + if (!contp) + Bye(); struct Closure *t = contp; contp = t->next; t->next = envp; @@ -249,7 +256,8 @@ void Iop(void) { } static void Rex(void) { - if (slog) PrintMachineState(stderr); + if (slog) + PrintMachineState(stderr); if (rlog && (alog || mem[ip] != APP)) { PrintExpressions(stderr, alog, vlog); } @@ -288,7 +296,8 @@ void Krivine(void) { fputs("]\n", stderr); } } - for (;;) Rex(); + for (;;) + Rex(); } void LoadFlags(int argc, char *argv[]) { diff --git a/tool/lambda/lib/debug.c b/tool/lambda/lib/debug.c index 47fa93639..f841a1ac3 100644 --- a/tool/lambda/lib/debug.c +++ b/tool/lambda/lib/debug.c @@ -72,7 +72,8 @@ void PrintMachineState(FILE *f) { char buf[256]; static int op; fputc('\n', f); - for (i = 0; i < 80; ++i) fputwc(L'─', f); + for (i = 0; i < 80; ++i) + fputwc(L'─', f); ksnprintf(buf, sizeof(buf), "%d\n ip %ld | op %d %s | arg %d | end %ld\n", op++, ip, mem[ip], GetOpName(mem[ip]), mem[ip + 1], end); @@ -97,7 +98,8 @@ void PrintExpressions(FILE *f, char alog, char vlog) { ps.envp = envp; for (p = &ps; p; p = p->next) { Print(p->term, 1, GetDepth(p->envp), f); - if (p->next) fputc(' ', f); + if (p->next) + fputc(' ', f); } if (alog) { fputs(" ⟹ ", f); diff --git a/tool/lambda/lib/dump.c b/tool/lambda/lib/dump.c index a466303af..a3fd9ee18 100644 --- a/tool/lambda/lib/dump.c +++ b/tool/lambda/lib/dump.c @@ -21,7 +21,8 @@ void Dumper(int i, int j, FILE *f) { char buf[64]; - if (i) fputc('\n', f); + if (i) + fputc('\n', f); for (; i < j; ++i) { switch (mem[i]) { case VAR: diff --git a/tool/lambda/lib/getbit.c b/tool/lambda/lib/getbit.c index ef6d4ccc1..8c64eff0f 100644 --- a/tool/lambda/lib/getbit.c +++ b/tool/lambda/lib/getbit.c @@ -26,14 +26,16 @@ char GetBit(FILE* f) { if (!binary) { for (comment = 0;;) { c = fgetwc(f); - if (c == -1) break; + if (c == -1) + break; if (!comment) { fflush(stdout); if (c == ';') { comment = 1; } else if (!iswspace(c) && c != '(' && c != ')' && c != '[' && c != ']') { - if (c != -1) c &= 1; + if (c != -1) + c &= 1; break; } } else if (c == '\n') { diff --git a/tool/lambda/lib/needbit.c b/tool/lambda/lib/needbit.c index c82df08c9..491f24342 100644 --- a/tool/lambda/lib/needbit.c +++ b/tool/lambda/lib/needbit.c @@ -20,6 +20,7 @@ char NeedBit(FILE* f) { char b = GetBit(f); - if (b == -1) Error(9, "UNEXPECTED EOF"); + if (b == -1) + Error(9, "UNEXPECTED EOF"); return b; } diff --git a/tool/lambda/lib/parse.c b/tool/lambda/lib/parse.c index 968656cfc..f9df3d812 100644 --- a/tool/lambda/lib/parse.c +++ b/tool/lambda/lib/parse.c @@ -26,15 +26,18 @@ struct Parse Parse(int ignored, FILE* f) { char bit, need; struct Parse p; for (need = 0, start = end;;) { - if (end + 2 > TERMS) Error(5, "OUT OF TERMS"); + if (end + 2 > TERMS) + Error(5, "OUT OF TERMS"); if ((bit = GetBit(f)) == -1) { - if (!need) break; + if (!need) + break; fflush(stdout); fputs("---\n", stderr); Print(start, 0, 0, stderr); Error(9, "UNFINISHED EXPRESSION"); } else if (bit) { - for (t = 0; NeedBit(f);) ++t; + for (t = 0; NeedBit(f);) + ++t; mem[end++] = VAR; mem[end++] = t; break; diff --git a/tool/lambda/lib/parserom.c b/tool/lambda/lib/parserom.c index f03774690..4a51fbc1e 100644 --- a/tool/lambda/lib/parserom.c +++ b/tool/lambda/lib/parserom.c @@ -23,12 +23,15 @@ static struct Parse ParseImpl(int tail, int need, FILE *f) { struct Parse p, q; int b, i, j, t, start; for (start = end;;) { - if (end + 2 > TERMS) Error(5, "OUT OF TERMS"); + if (end + 2 > TERMS) + Error(5, "OUT OF TERMS"); if ((b = GetBit(f)) == -1) { - if (need) Error(9, "UNFINISHED EXPRESSION"); + if (need) + Error(9, "UNFINISHED EXPRESSION"); break; } else if (b) { - for (t = 0; NeedBit(f);) ++t; + for (t = 0; NeedBit(f);) + ++t; mem[end++] = VAR; mem[end++] = t; break; diff --git a/tool/lambda/lib/print.c b/tool/lambda/lib/print.c index 5edbb482c..6d314208e 100644 --- a/tool/lambda/lib/print.c +++ b/tool/lambda/lib/print.c @@ -873,11 +873,13 @@ void PrintDebruijn(int x, int head, int depth, FILE* f) { } else { fputwc(L'λ', f); } - if (!(0 <= x && x < TERMS)) goto Overflow; + if (!(0 <= x && x < TERMS)) + goto Overflow; } while (mem[x] == ABS); fputc(' ', f); } - if (!(0 <= (x + 1) && (x + 1) < TERMS)) goto Overflow; + if (!(0 <= (x + 1) && (x + 1) < TERMS)) + goto Overflow; if (mem[x] == APP) { fputc('[', f); PrintDebruijn(x + 2, 1, depth, f); @@ -1162,11 +1164,13 @@ void PrintLambda(int x, int head, int depth, int apps, FILE* f) { do { ++x; fputwc(ALPHABET[depth++], f); - if (!(0 <= x && x < TERMS)) goto Overflow; + if (!(0 <= x && x < TERMS)) + goto Overflow; } while (mem[x] == ABS); fputc('.', f); } - if (!(0 <= (x + 1) && (x + 1) < TERMS)) goto Overflow; + if (!(0 <= (x + 1) && (x + 1) < TERMS)) + goto Overflow; if (mem[x] == VAR) { if (0 <= x + 1 && x + 1 < TERMS) { PrintVar(depth - 1 - mem[x + 1], f); @@ -1182,7 +1186,8 @@ void PrintLambda(int x, int head, int depth, int apps, FILE* f) { } PrintLambda(x + 2, 1, depth, apps + 1, f); if (!(x + 2 + mem[x + 1] < TERMS && mem[x + 2 + mem[x + 1]] == APP)) { - if (safer || !noname) fputc(' ', f); + if (safer || !noname) + fputc(' ', f); } PrintLambda(x + 2 + mem[x + 1], 0, depth, apps + 1, f); } else if (mem[x] == IOP) { @@ -1230,10 +1235,12 @@ void PrintBinary(int x, int head, int depth, FILE* f) { ++depth; fputc('0', f); fputc('0', f); - if (!(0 <= x && x < TERMS)) goto Overflow; + if (!(0 <= x && x < TERMS)) + goto Overflow; } while (mem[x] == ABS); } - if (!(0 <= (x + 1) && (x + 1) < TERMS)) goto Overflow; + if (!(0 <= (x + 1) && (x + 1) < TERMS)) + goto Overflow; if (mem[x] == VAR) { if (0 <= x + 1 && x + 1 < TERMS) { PrintVar(mem[x + 1], f); diff --git a/tool/net/dig.c b/tool/net/dig.c index 6af2bed32..41a6c2d01 100644 --- a/tool/net/dig.c +++ b/tool/net/dig.c @@ -76,6 +76,7 @@ void lookup(const char *name) { int main(int argc, char *argv[]) { int i; ShowCrashReports(); - for (i = 1; i < argc; ++i) lookup(argv[i]); + for (i = 1; i < argc; ++i) + lookup(argv[i]); return 0; } diff --git a/tool/net/echo.c b/tool/net/echo.c index 4a0ffd762..c25452037 100644 --- a/tool/net/echo.c +++ b/tool/net/echo.c @@ -98,7 +98,8 @@ void TcpServer(void) { ip, ntohs(addr2.sin_port)); for (;;) { CHECK_NE(-1, (rc = read(client, buf, sizeof(buf)))); - if (!rc) break; + if (!rc) + break; CHECK_NE(-1, write(client, buf, rc)); } } @@ -117,7 +118,8 @@ void TcpClient(void) { int main(int argc, char *argv[]) { int port = 0; int64_t ip = 0; - if (argc < 3) PrintUsage(argv); + if (argc < 3) + PrintUsage(argv); if (argc >= 4) { if ((ip = ParseIp(argv[3], -1)) == -1) { PrintUsage(argv); diff --git a/tool/net/getadaptersaddresses.c b/tool/net/getadaptersaddresses.c index 7ddfd0f61..91ddbfa94 100644 --- a/tool/net/getadaptersaddresses.c +++ b/tool/net/getadaptersaddresses.c @@ -174,43 +174,53 @@ const char *DescribeIpAdapterFlags(int x) { static char buf[256]; p = buf; if (x & kNtIpAdapterDdnsEnabled) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "DDNS"); } if (x & kNtIpAdapterDhcpv4Enabled) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "DHCPv4"); } if (x & kNtIpAdapterReceiveOnly) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "RECV_ONLY"); } if (x & kNtIpAdapterNoMulticast) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "NO_MULTICAST"); } if (x & kNtIpAdapterIpv4Enabled) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "IPv4"); } if (x & kNtIpAdapterIpv6Enabled) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "IPv6"); } if (x & kNtIpAdapterIpv6Managed) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "IPv6_MANAGED"); } if (x & kNtIpAdapterIpv6OtherStatefulConfig) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "IPv6_OTHER_STATEFUL_CONFIG"); } if (x & kNtIpAdapterNetbiosOverTcpipEnabled) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "NETBIOS_OVER_TCP"); } if (x & kNtIpAdapterRegisterAdapterSuffix) { - if (p > buf) *p++ = ' '; + if (p > buf) + *p++ = ' '; p = stpcpy(p, "REGISTER_ADAPTER_SUFFIX"); } return buf; @@ -252,9 +262,12 @@ char *ConvertIpv6ToStr(const struct in6_addr *addr) { b = (addr->s6_addr[i + 0] & 0x0F) >> 0; c = (addr->s6_addr[i + 1] & 0xF0) >> 4; d = (addr->s6_addr[i + 1] & 0x0F) >> 0; - if (a) *p++ = "0123456789abcdef"[a]; - if (a || b) *p++ = "0123456789abcdef"[b]; - if (a || b || c) *p++ = "0123456789abcdef"[c]; + if (a) + *p++ = "0123456789abcdef"[a]; + if (a || b) + *p++ = "0123456789abcdef"[b]; + if (a || b || c) + *p++ = "0123456789abcdef"[c]; *p++ = "0123456789abcdef"[d]; } *p = '\0'; @@ -406,7 +419,8 @@ void ShowWinNicCidrs(void) { (char16_t *)&lpMsgBuf, 0, NULL)) { printf("\tError: %s", lpMsgBuf); LocalFree(lpMsgBuf); - if (pAddresses) free(pAddresses); + if (pAddresses) + free(pAddresses); exit(1); } } diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index 79f0d1ca0..7629d9e9b 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -475,7 +475,8 @@ int LuaSlurp(lua_State *L) { } if (rc != -1) { got = rc; - if (!got) break; + if (!got) + break; luaL_addlstring(&b, tb, got); } else if (errno == EINTR) { errno = olderr; @@ -617,7 +618,8 @@ dontinline int LuaBase32Impl(lua_State *L, const char *a = luaL_optlstring(L, 2, "", &al); if (!IS2POW(al) || al > 128 || al == 1) return luaL_error(L, "alphabet length is not a power of 2 in range 2..128"); - if (!(p = B32(s, sl, a, al, &sl))) return luaL_error(L, "out of memory"); + if (!(p = B32(s, sl, a, al, &sl))) + return luaL_error(L, "out of memory"); lua_pushlstring(L, p, sl); free(p); return 1; @@ -693,10 +695,12 @@ int LuaGetCryptoHash(lua_State *L) { 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 (!digest) + return luaL_argerror(L, 1, "unknown hash type"); if (kl == 0) { // no key provided, run generic hash function - if ((digest->f_md)(p, pl, d)) return luaL_error(L, "bad input data"); + if ((digest->f_md)(p, pl, d)) + return luaL_error(L, "bad input data"); } else if (mbedtls_md_hmac(digest, k, kl, p, pl, d)) { return luaL_error(L, "bad input data"); } diff --git a/tool/net/libresolv_query.c b/tool/net/libresolv_query.c index 956e0c250..693d64dc4 100644 --- a/tool/net/libresolv_query.c +++ b/tool/net/libresolv_query.c @@ -74,25 +74,30 @@ static void dump_dns_rr(ns_msg *msg, ns_rr *rr, ns_sect sect, FILE *trace) { class = ns_rr_class(*rr); type = ns_rr_type(*rr); fprintf(trace, "%s,%d,%d", ns_rr_name(*rr), class, type); - if (sect == ns_s_qd) return; + if (sect == ns_s_qd) + return; fprintf(trace, ",%lu", (u_long)ns_rr_ttl(*rr)); rd = ns_rr_rdata(*rr); switch (type) { case ns_t_soa: n = ns_name_uncompress(ns_msg_base(*msg), ns_msg_end(*msg), rd, buf, sizeof buf); - if (n < 0) goto error; + if (n < 0) + goto error; putc(',', trace); fputs(buf, trace); rd += n; n = ns_name_uncompress(ns_msg_base(*msg), ns_msg_end(*msg), rd, buf, sizeof buf); - if (n < 0) goto error; + if (n < 0) + goto error; putc(',', trace); fputs(buf, trace); rd += n; - if (ns_msg_end(*msg) - rd < 5 * NS_INT32SZ) goto error; - for (n = 0; n < 5; n++) MY_GET32(soa[n], rd); + if (ns_msg_end(*msg) - rd < 5 * NS_INT32SZ) + goto error; + for (n = 0; n < 5; n++) + MY_GET32(soa[n], rd); sprintf(buf, "%u,%u,%u,%u,%u", soa[0], soa[1], soa[2], soa[3], soa[4]); break; case ns_t_a: @@ -110,7 +115,8 @@ static void dump_dns_rr(ns_msg *msg, ns_rr *rr, ns_sect sect, FILE *trace) { case ns_t_cname: n = ns_name_uncompress(ns_msg_base(*msg), ns_msg_end(*msg), rd, buf, sizeof buf); - if (n < 0) goto error; + if (n < 0) + goto error; break; case ns_t_txt: snprintf(buf, (size_t)rd[0] + 1, "%s", rd + 1); diff --git a/tool/net/ljson.c b/tool/net/ljson.c index 8ac0b5d36..b78367081 100644 --- a/tool/net/ljson.c +++ b/tool/net/ljson.c @@ -132,7 +132,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case 'n': // null - if (context & (KEY | COLON | COMMA)) goto OnColonCommaKey; + if (context & (KEY | COLON | COMMA)) + goto OnColonCommaKey; if (p + 3 <= e && READ32LE(p - 1) == READ32LE("null")) { lua_pushnil(L); return (struct DecodeJson){1, p + 3}; @@ -141,7 +142,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case 'f': // false - if (context & (KEY | COLON | COMMA)) goto OnColonCommaKey; + if (context & (KEY | COLON | COMMA)) + goto OnColonCommaKey; if (p + 4 <= e && READ32LE(p) == READ32LE("alse")) { lua_pushboolean(L, false); return (struct DecodeJson){1, p + 4}; @@ -150,7 +152,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case 't': // true - if (context & (KEY | COLON | COMMA)) goto OnColonCommaKey; + if (context & (KEY | COLON | COMMA)) + goto OnColonCommaKey; if (p + 3 <= e && READ32LE(p - 1) == READ32LE("true")) { lua_pushboolean(L, true); return (struct DecodeJson){1, p + 3}; @@ -162,9 +165,11 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, IllegalCharacter: return (struct DecodeJson){-1, "illegal character"}; OnColonCommaKey: - if (context & KEY) goto BadObjectKey; + if (context & KEY) + goto BadObjectKey; OnColonComma: - if (context & COLON) goto MissingColon; + if (context & COLON) + goto MissingColon; return (struct DecodeJson){-1, "missing ','"}; MissingColon: return (struct DecodeJson){-1, "missing ':'"}; @@ -172,7 +177,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, return (struct DecodeJson){-1, "object key must be string"}; case '-': // negative - if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; + if (context & (COLON | COMMA | KEY)) + goto OnColonCommaKey; if (p < e && isdigit(*p)) { d = -1; break; @@ -181,7 +187,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case '0': // zero or number - if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; + if (context & (COLON | COMMA | KEY)) + goto OnColonCommaKey; if (p < e) { if (*p == '.') { if (p + 1 == e || !isdigit(p[1])) { @@ -198,7 +205,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, return (struct DecodeJson){1, p}; case '1' ... '9': // integer - if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; + if (context & (COLON | COMMA | KEY)) + goto OnColonCommaKey; for (x = (c - '0') * d; p < e; ++p) { c = *p & 255; if (isdigit(c)) { @@ -228,7 +236,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, return (struct DecodeJson){1, a + c}; case '[': // Array - if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; + if (context & (COLON | COMMA | KEY)) + goto OnColonCommaKey; lua_newtable(L); // +1 for (context = ARRAY, i = 0;;) { r = Parse(L, p, e, context, depth - 1); // +2 @@ -265,7 +274,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case '{': // Object - if (context & (COLON | COMMA | KEY)) goto OnColonCommaKey; + if (context & (COLON | COMMA | KEY)) + goto OnColonCommaKey; lua_newtable(L); // +1 context = KEY | OBJECT; for (;;) { @@ -293,7 +303,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, } case '"': // string - if (context & (COLON | COMMA)) goto OnColonComma; + if (context & (COLON | COMMA)) + goto OnColonComma; luaL_buffinit(L, &b); for (;;) { if (UNLIKELY(p >= e)) { @@ -586,7 +597,8 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p, * @return r.p is string describing error if `rc < 0` */ struct DecodeJson DecodeJson(struct lua_State *L, const char *p, size_t n) { - if (n == -1) n = p ? strlen(p) : 0; + if (n == -1) + n = p ? strlen(p) : 0; if (lua_checkstack(L, DEPTH * 3 + LUA_MINSTACK)) { return Parse(L, p, p + n, 0, DEPTH); } else { diff --git a/tool/net/lmaxmind.c b/tool/net/lmaxmind.c index 2200bba93..b52df8b11 100644 --- a/tool/net/lmaxmind.c +++ b/tool/net/lmaxmind.c @@ -203,7 +203,8 @@ static int LuaMaxmindResultGet(lua_State *L) { ep = &(*ur)->mmlr.entry; } else { path = xcalloc(n + 1, sizeof(const char *)); - for (i = 0; i < n; ++i) path[i] = lua_tostring(L, 2 + i); + for (i = 0; i < n; ++i) + path[i] = lua_tostring(L, 2 + i); err = MMDB_aget_value(&(*ur)->mmlr.entry, &edata, path); free(path); if (err) { @@ -223,7 +224,8 @@ static int LuaMaxmindResultGet(lua_State *L) { ep = &entry; } err = MMDB_get_entry_data_list(ep, &dl); - if (err) LuaThrowMaxmindIpError(L, "getlist", (*ur)->ip, err); + if (err) + LuaThrowMaxmindIpError(L, "getlist", (*ur)->ip, err); LuaMaxmindDump(L, dl); MMDB_free_entry_data_list(dl); return 1; diff --git a/tool/net/lpath.c b/tool/net/lpath.c index 81eba4d73..fd146f2f6 100644 --- a/tool/net/lpath.c +++ b/tool/net/lpath.c @@ -32,9 +32,11 @@ static int LuaPathBasename(lua_State *L) { size_t i, n; const char *p; if ((p = luaL_optlstring(L, 1, 0, &n)) && n) { - while (n > 1 && p[n - 1] == '/') --n; + while (n > 1 && p[n - 1] == '/') + --n; i = n - 1; - while (i && p[i - 1] != '/') --i; + while (i && p[i - 1] != '/') + --i; lua_pushlstring(L, p + i, n - i); } else { lua_pushlstring(L, ".", 1); @@ -49,13 +51,16 @@ static int LuaPathDirname(lua_State *L) { const char *p; if ((p = luaL_optlstring(L, 1, 0, &n)) && n--) { for (; p[n] == '/'; n--) { - if (!n) goto ReturnSlash; + if (!n) + goto ReturnSlash; } for (; p[n] != '/'; n--) { - if (!n) goto ReturnDot; + if (!n) + goto ReturnDot; } for (; p[n] == '/'; n--) { - if (!n) goto ReturnSlash; + if (!n) + goto ReturnSlash; } lua_pushlstring(L, p, n + 1); return 1; @@ -82,7 +87,8 @@ static int LuaPathJoin(lua_State *L) { gotstr = false; needslash = false; for (i = 1; i <= n; ++i) { - if (lua_isnoneornil(L, i)) continue; + if (lua_isnoneornil(L, i)) + continue; gotstr = true; c = luaL_checklstring(L, i, &z); if (z) { diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 144e0dcbd..fbfb8d12b 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -644,11 +644,14 @@ static bool ShouldAvoidGzip(void) { static char *MergePaths(const char *p, size_t n, const char *q, size_t m, size_t *z) { char *r; - if (n && p[n - 1] == '/') --n; - if (m && q[0] == '/') ++q, --m; + if (n && p[n - 1] == '/') + --n; + if (m && q[0] == '/') + ++q, --m; r = xmalloc(n + 1 + m + 1); mempcpy(mempcpy(mempcpy(mempcpy(r, p, n), "/", 1), q, m), "", 1); - if (z) *z = n + 1 + m; + if (z) + *z = n + 1 + m; return r; } @@ -698,7 +701,8 @@ static void AppendCert(mbedtls_x509_crt *cert, mbedtls_pk_context *key) { static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { int r; size_t i; - if (cert->next) InternCertificate(cert->next, cert); + if (cert->next) + InternCertificate(cert->next, cert); if (prev) { if (mbedtls_x509_crt_check_parent(prev, cert, 1)) { DEBUGF("(ssl) unbundling %`'s from %`'s", @@ -728,18 +732,22 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { LogCertificate("loaded certificate", cert); if (!cert->next && !IsSelfSigned(cert) && cert->max_pathlen) { for (i = 0; i < certs.n; ++i) { - if (!certs.p[i].cert) continue; + if (!certs.p[i].cert) + continue; if (mbedtls_pk_can_do(&cert->pk, certs.p[i].cert->sig_pk) && !mbedtls_x509_crt_check_parent(cert, certs.p[i].cert, 1) && !IsSelfSigned(certs.p[i].cert)) { - if (ChainCertificate(cert, certs.p[i].cert)) break; + if (ChainCertificate(cert, certs.p[i].cert)) + break; } } } if (!IsSelfSigned(cert)) { for (i = 0; i < certs.n; ++i) { - if (!certs.p[i].cert) continue; - if (certs.p[i].cert->next) continue; + if (!certs.p[i].cert) + continue; + if (certs.p[i].cert->next) + continue; if (certs.p[i].cert->max_pathlen && mbedtls_pk_can_do(&certs.p[i].cert->pk, cert->sig_pk) && !mbedtls_x509_crt_check_parent(certs.p[i].cert, cert, 1)) { @@ -782,7 +790,8 @@ static void ProgramPrivateKey(const char *p, size_t n) { rc = mbedtls_pk_parse_key(key, waqapi, n + 1, 0, 0); mbedtls_platform_zeroize(waqapi, n); free(waqapi); - if (rc != 0) FATALF("(ssl) error: load key (grep -0x%04x)", -rc); + if (rc != 0) + FATALF("(ssl) error: load key (grep -0x%04x)", -rc); for (i = 0; i < certs.n; ++i) { if (certs.p[i].cert && !certs.p[i].key && !mbedtls_pk_check_pair(&certs.p[i].cert->pk, key)) { @@ -811,7 +820,8 @@ static void ProgramPort(long port) { if (!(0 <= port && port <= 65535)) { FATALF("(cfg) error: bad port: %d", port); } - if (port == 443) listeningonport443 = true; + if (port == 443) + listeningonport443 = true; ports.p = realloc(ports.p, ++ports.n * sizeof(*ports.p)); ports.p[ports.n - 1] = port; } @@ -942,13 +952,15 @@ static void DescribeAddress(char buf[40], uint32_t addr, uint16_t port) { static inline int GetServerAddr(uint32_t *ip, uint16_t *port) { *ip = ntohl(serveraddr->sin_addr.s_addr); - if (port) *port = ntohs(serveraddr->sin_port); + if (port) + *port = ntohs(serveraddr->sin_port); return 0; } static inline int GetClientAddr(uint32_t *ip, uint16_t *port) { *ip = ntohl(clientaddr.sin_addr.s_addr); - if (port) *port = ntohs(clientaddr.sin_port); + if (port) + *port = ntohs(clientaddr.sin_port); return 0; } @@ -1038,7 +1050,8 @@ static void ProgramTimeout(long ms) { static void ProgramCache(long x, const char *s) { cacheseconds = x; - if (s) cachedirective = strdup(s); + if (s) + cachedirective = strdup(s); } static void SetDefaults(void) { @@ -1183,9 +1196,11 @@ static void ChangeUser(void) { } static void Daemonize(void) { - if (fork() > 0) exit(0); + if (fork() > 0) + exit(0); setsid(); - if (fork() > 0) _exit(0); + if (fork() > 0) + _exit(0); umask(0); } @@ -1209,7 +1224,8 @@ static void LuaEvalCode(const char *code) { // handle `-F PATH` arg static void LuaEvalFile(const char *path) { char *f = gc(xslurp(path, 0)); - if (!f) FATALF("(cfg) error: failed to read file %`'s", path); + if (!f) + FATALF("(cfg) error: failed to read file %`'s", path); LuaEvalCode(f); } @@ -1465,8 +1481,10 @@ static ssize_t WritevAll(int fd, struct iovec *iov, int iovlen) { total = 0; do { if (i) { - while (i < iovlen && !iov[i].iov_len) ++i; - if (i == iovlen) break; + while (i < iovlen && !iov[i].iov_len) + ++i; + if (i == iovlen) + break; } if ((rc = writev(fd, iov + i, iovlen - i)) != -1) { wrote = rc; @@ -1501,7 +1519,8 @@ static int TlsFlush(struct TlsBio *bio, const unsigned char *buf, size_t len) { 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; + if (bio->c > 0) + bio->c = 0; } else if (errno == EINTR) { errno = 0; return MBEDTLS_ERR_NET_CONN_RESET; @@ -1526,7 +1545,8 @@ static int TlsSend(void *ctx, const unsigned char *buf, size_t len) { bio->c += len; return len; } - if ((rc = TlsFlush(bio, buf, len)) < 0) return rc; + if ((rc = TlsFlush(bio, buf, len)) < 0) + return rc; return len; } @@ -1534,11 +1554,13 @@ static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { int r; struct iovec v[2]; struct TlsBio *bio = ctx; - if ((r = TlsFlush(bio, 0, 0)) < 0) return r; + if ((r = TlsFlush(bio, 0, 0)) < 0) + return r; if (bio->a < bio->b) { r = MIN(n, bio->b - bio->a); memcpy(p, bio->t + bio->a, r); - if ((bio->a += r) == bio->b) bio->a = bio->b = 0; + if ((bio->a += r) == bio->b) + bio->a = bio->b = 0; return r; } v[0].iov_base = p; @@ -1559,7 +1581,8 @@ static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { return MBEDTLS_ERR_NET_RECV_FAILED; } } - if (r > n) bio->b = r - n; + if (r > n) + bio->b = r - n; return MIN(n, r); } @@ -1655,11 +1678,15 @@ static void NotifyClose(void) { static void WipeSigningKeys(void) { size_t i; - if (uniprocess) return; + if (uniprocess) + return; for (i = 0; i < certs.n; ++i) { - if (!certs.p[i].key) continue; - if (!certs.p[i].cert) continue; - if (!certs.p[i].cert->ca_istrue) continue; + if (!certs.p[i].key) + continue; + if (!certs.p[i].cert) + continue; + if (!certs.p[i].cert->ca_istrue) + continue; mbedtls_pk_free(certs.p[i].key); Free(&certs.p[i].key); } @@ -1695,7 +1722,8 @@ static void CertsDestroy(void) { } static void WipeServingKeys(void) { - if (uniprocess) return; + if (uniprocess) + return; mbedtls_ssl_ticket_free(&ssltick); mbedtls_ssl_key_cert_free(conf.key_cert), conf.key_cert = 0; CertsDestroy(); @@ -1897,13 +1925,15 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, // for (int i = 0; i < ips.n; ++i) { uint32_t ip = ips.p[i]; - if (IsLoopbackIp(ip)) continue; + if (IsLoopbackIp(ip)) + continue; char rname[NI_MAXHOST]; struct sockaddr_in addr4 = {AF_INET, 0, {htonl(ip)}}; if (getnameinfo((struct sockaddr *)&addr4, sizeof(addr4), rname, sizeof(rname), 0, 0, NI_NAMEREQD) == 0) { char *s = gc(strdup(rname)); - if (!name) name = s; + if (!name) + name = s; bool isduplicate = false; for (int j = 0; j < nsan; ++j) { if (san[j].tag == MBEDTLS_X509_SAN_DNS_NAME && @@ -1925,7 +1955,8 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, // add san entry to cert for each ip address owned by system for (int i = 0; i < ips.n; ++i) { uint32_t ip = ips.p[i]; - if (IsLoopbackIp(ip)) continue; + if (IsLoopbackIp(ip)) + continue; san = realloc(san, ++nsan * sizeof(*san)); san[nsan - 1].tag = MBEDTLS_X509_SAN_IP_ADDRESS; san[nsan - 1].ip4 = ip; @@ -1974,9 +2005,12 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, static struct Cert GetKeySigningKey(void) { size_t i; for (i = 0; i < certs.n; ++i) { - if (!certs.p[i].key) continue; - if (!certs.p[i].cert) continue; - if (!certs.p[i].cert->ca_istrue) continue; + if (!certs.p[i].key) + continue; + if (!certs.p[i].cert) + continue; + if (!certs.p[i].cert->ca_istrue) + continue; if (mbedtls_x509_crt_check_key_usage(certs.p[i].cert, MBEDTLS_X509_KU_KEY_CERT_SIGN)) { continue; @@ -2059,7 +2093,8 @@ static void LoadCertificates(void) { } #ifdef MBEDTLS_ECP_C ecp = GenerateEcpCertificate(ksk.key ? &ksk : 0); - if (!havecert) UseCertificate(&conf, &ecp, "server"); + if (!havecert) + UseCertificate(&conf, &ecp, "server"); if (!haveclientcert && ksk.key) { UseCertificate(&confcli, &ecp, "client"); } @@ -2068,7 +2103,8 @@ static void LoadCertificates(void) { #ifdef MBEDTLS_RSA_C if (!norsagen) { rsa = GenerateRsaCertificate(ksk.key ? &ksk : 0); - if (!havecert) UseCertificate(&conf, &rsa, "server"); + if (!havecert) + UseCertificate(&conf, &rsa, "server"); if (!haveclientcert && ksk.key) { UseCertificate(&confcli, &rsa, "client"); } @@ -2237,11 +2273,13 @@ static bool OpenZip(bool force) { static struct Asset *GetAssetZip(const char *path, size_t pathlen) { uint32_t i, step, hash; - if (pathlen > 1 && path[0] == '/') ++path, --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); - if (!assets.p[i].hash) return NULL; + if (!assets.p[i].hash) + return NULL; if (hash == assets.p[i].hash && pathlen == ZIP_CFILE_NAMESIZE(zmap + assets.p[i].cf) && memcmp(path, ZIP_CFILE_NAME(zmap + assets.p[i].cf), pathlen) == 0) { @@ -2288,7 +2326,8 @@ static struct Asset *GetAsset(const char *path, size_t pathlen) { } static char *AppendHeader(char *p, const char *k, const char *v) { - if (!v) return p; + if (!v) + return p; return AppendCrlf(stpcpy(stpcpy(stpcpy(p, k), ": "), v)); } @@ -2316,7 +2355,8 @@ static char *AppendExpires(char *p, int64_t t) { } static char *AppendCache(char *p, int64_t seconds, char *directive) { - if (seconds < 0) return p; + if (seconds < 0) + return p; p = stpcpy(p, "Cache-Control: max-age="); p = FormatUint64(p, seconds); if (!seconds) { @@ -2392,7 +2432,8 @@ static void *LoadAsset(struct Asset *a, size_t *out_size) { } if (!a->file) { size = GetZipLfileUncompressedSize(zmap + a->lf); - if (size == SIZE_MAX || !(data = malloc(size + 1))) return NULL; + if (size == SIZE_MAX || !(data = malloc(size + 1))) + return NULL; if (IsCompressed(a)) { if (!Inflate(data, size, ZIP_LFILE_CONTENT(zmap + a->lf), GetZipCfileCompressedSize(zmap + a->cf))) { @@ -2407,7 +2448,8 @@ static void *LoadAsset(struct Asset *a, size_t *out_size) { return NULL; } data[size] = '\0'; - if (out_size) *out_size = size; + if (out_size) + *out_size = size; return data; } else { LockInc(&shared->c.slurps); @@ -2622,7 +2664,8 @@ static ssize_t YieldGenerator(struct iovec v[3]) { int nresults, status; if (cpm.isyielding > 1) { do { - if (!YL || lua_status(YL) != LUA_YIELD) return 0; // done yielding + if (!YL || lua_status(YL) != LUA_YIELD) + return 0; // done yielding cpm.contentlength = 0; status = lua_resume(YL, NULL, 0, &nresults); if (status != LUA_OK && status != LUA_YIELD) { @@ -2631,7 +2674,8 @@ static ssize_t YieldGenerator(struct iovec v[3]) { return -1; } lua_pop(YL, nresults); - if (!cpm.contentlength) UseOutput(); + if (!cpm.contentlength) + UseOutput(); // continue yielding if nothing to return to keep generator running } while (!cpm.contentlength); } @@ -2667,7 +2711,8 @@ static int LuaCallWithYield(lua_State *L) { CHECK_GT(lua_gettop(L), 0); // make sure that coroutine is anchored YL = co; cpm.generator = YieldGenerator; - if (!cpm.isyielding) cpm.isyielding = 1; + if (!cpm.isyielding) + cpm.isyielding = 1; status = LUA_OK; } return status; @@ -2770,7 +2815,8 @@ static ssize_t InflateGenerator(struct iovec v[3]) { dg.s.next_out = dg.b; dg.s.avail_out = dg.z; rc = inflate(&dg.s, Z_NO_FLUSH); - if (rc != Z_OK && rc != Z_STREAM_END) DIEF("(zip) inflate()→%d", rc); + if (rc != Z_OK && rc != Z_STREAM_END) + DIEF("(zip) inflate()→%d", rc); no = dg.z - dg.s.avail_out; if (no) { v[i].iov_base = dg.b; @@ -2877,7 +2923,8 @@ static char *GetAssetPath(uint8_t *zcf, size_t *out_size) { p2[0] = '/'; memcpy(p2 + 1, p1, n1); p2[1 + n1] = '\0'; - if (out_size) *out_size = 1 + n1; + if (out_size) + *out_size = 1 + n1; return p2; } @@ -2928,8 +2975,10 @@ static void LaunchBrowser(const char *path) { port = ntohs(servers.p[0].addr.sin_port); } // assign a loopback address if no server or unknown server address - if (!servers.n || !addr.s_addr) addr.s_addr = htonl(INADDR_LOOPBACK); - if (*path != '/') path = gc(xasprintf("/%s", path)); + if (!servers.n || !addr.s_addr) + addr.s_addr = htonl(INADDR_LOOPBACK); + if (*path != '/') + path = gc(xasprintf("/%s", path)); launch_browser(gc(xasprintf("http://%s:%d%s", inet_ntoa(addr), port, path))); } @@ -3102,11 +3151,13 @@ static const char *MergeNames(const char *a, const char *b) { } static void AppendLong1(const char *a, long x) { - if (x) appendf(&cpm.outbuf, "%s: %ld\r\n", a, x); + if (x) + appendf(&cpm.outbuf, "%s: %ld\r\n", a, x); } static void AppendLong2(const char *a, const char *b, long x) { - if (x) appendf(&cpm.outbuf, "%s.%s: %ld\r\n", a, b, x); + if (x) + appendf(&cpm.outbuf, "%s.%s: %ld\r\n", a, b, x); } static void AppendTimeval(const char *a, struct timeval *tv) { @@ -3282,7 +3333,8 @@ static char *HandleRedirect(struct Redirect *r) { } else { LockInc(&shared->c.redirects); code = r->code; - if (!code) code = 307; + if (!code) + code = 307; DEBUGF("(rsp) %d redirect to %`'s", code, r->location.s); return AppendHeader( SetStatus(code, GetHttpReason(code)), "Location", @@ -3629,8 +3681,10 @@ static void StoreAsset(const char *path, size_t pathlen, const char *data, } INFOF("(srvr) storing asset %`'s", path); disk = gflags = iattrs = 0; - if (isutf8(path, pathlen)) gflags |= kZipGflagUtf8; - if (istext(data, datalen)) iattrs |= kZipIattrText; + if (isutf8(path, pathlen)) + gflags |= kZipGflagUtf8; + if (istext(data, datalen)) + iattrs |= kZipIattrText; crc = crc32_z(0, data, datalen); if (datalen < 100) { method = kZipCompressionNone; @@ -3661,9 +3715,12 @@ static void StoreAsset(const char *path, size_t pathlen, const char *data, OpenZip(false); now = timespec_real(); a = GetAssetZip(path, pathlen); - if (!mode) mode = a ? GetMode(a) : 0644; - if (!(mode & S_IFMT)) mode |= S_IFREG; - if (pathlen > 1 && path[0] == '/') ++path, --pathlen; + if (!mode) + mode = a ? GetMode(a) : 0644; + if (!(mode & S_IFMT)) + mode |= S_IFREG; + if (pathlen > 1 && path[0] == '/') + ++path, --pathlen; dosmode = !(mode & 0200) ? kNtFileAttributeReadonly : 0; ft = (now.tv_sec + MODERNITYSECONDS) * HECTONANOSECONDS; GetDosLocalTime(now.tv_sec, &mtime, &mdate); @@ -3812,12 +3869,14 @@ static void StoreFile(const char *path) { struct stat st; size_t plen, tlen; const char *target = path; - if (startswith(target, "./")) target += 2; + if (startswith(target, "./")) + target += 2; tlen = strlen(target); if (!IsReasonablePath(target, tlen)) FATALF("(cfg) error: can't store %`'s: contains '.' or '..' segments", target); - if (lstat(path, &st) == -1) FATALF("(cfg) error: can't stat %`'s: %m", path); + if (lstat(path, &st) == -1) + FATALF("(cfg) error: can't stat %`'s: %m", path); if (!(p = xslurp(path, &plen))) FATALF("(cfg) error: can't read %`'s: %m", path); StoreAsset(target, tlen, p, plen, st.st_mode & 0777); @@ -3831,10 +3890,13 @@ static void StorePath(const char *dirpath) { if (!isdirectory(dirpath) && !endswith(dirpath, "/")) { return StoreFile(dirpath); } - if (!(d = opendir(dirpath))) FATALF("(cfg) error: can't open %`'s", dirpath); + if (!(d = opendir(dirpath))) + FATALF("(cfg) error: can't open %`'s", dirpath); while ((e = readdir(d))) { - if (strcmp(e->d_name, ".") == 0) continue; - if (strcmp(e->d_name, "..") == 0) continue; + if (strcmp(e->d_name, ".") == 0) + continue; + if (strcmp(e->d_name, "..") == 0) + continue; path = gc(xjoinpaths(dirpath, e->d_name)); if (e->d_type == DT_DIR) { StorePath(path); @@ -3861,7 +3923,8 @@ static int LuaStoreAsset(lua_State *L) { static void ReseedRng(mbedtls_ctr_drbg_context *r, const char *s) { #ifndef UNSECURE - if (unsecure) return; + if (unsecure) + return; CHECK_EQ(0, mbedtls_ctr_drbg_reseed(r, (void *)s, strlen(s))); #endif } @@ -3869,8 +3932,10 @@ static void ReseedRng(mbedtls_ctr_drbg_context *r, const char *s) { static void LogMessage(const char *d, const char *s, size_t n) { size_t n2, n3; char *s2, *s3; - if (!LOGGABLE(kLogInfo)) return; - while (n && (s[n - 1] == '\r' || s[n - 1] == '\n')) --n; + if (!LOGGABLE(kLogInfo)) + return; + while (n && (s[n - 1] == '\r' || s[n - 1] == '\n')) + --n; if ((s2 = DecodeLatin1(s, n, &n2))) { if ((s3 = IndentLines(s2, n2, &n3, 1))) { INFOF("(stat) %s %,ld byte message\r\n%.*s", d, n, n3, s3); @@ -3883,9 +3948,12 @@ static void LogMessage(const char *d, const char *s, size_t n) { static void LogBody(const char *d, const char *s, size_t n) { char *s2, *s3; size_t n2, n3; - if (!n) return; - if (!LOGGABLE(kLogInfo)) return; - while (n && (s[n - 1] == '\r' || s[n - 1] == '\n')) --n; + if (!n) + return; + if (!LOGGABLE(kLogInfo)) + return; + while (n && (s[n - 1] == '\r' || s[n - 1] == '\n')) + --n; if ((s2 = VisualizeControlCodes(s, n, &n2))) { if ((s3 = IndentLines(s2, n2, &n3, 1))) { INFOF("(stat) %s %,ld byte payload\r\n%.*s", d, n, n3, s3); @@ -4107,7 +4175,8 @@ static int LuaGetUser(lua_State *L) { if (url.user.p) { LuaPushUrlView(L, &url.user); } else if ((p = gc(GetBasicAuthorization(&n)))) { - if (!(q = memchr(p, ':', n))) q = p + n; + if (!(q = memchr(p, ':', n))) + q = p + n; lua_pushlstring(L, p, q - p); } else { lua_pushnil(L); @@ -4148,8 +4217,10 @@ static int LuaGetHost(lua_State *L) { static int LuaGetPort(lua_State *L) { int i, x = 0; OnlyCallDuringRequest(L, "GetPort"); - for (i = 0; i < url.port.n; ++i) x = url.port.p[i] - '0' + x * 10; - if (!x) x = ntohs(serveraddr->sin_port); + for (i = 0; i < url.port.n; ++i) + x = url.port.p[i] - '0' + x * 10; + if (!x) + x = ntohs(serveraddr->sin_port); lua_pushinteger(L, x); return 1; } @@ -4219,7 +4290,8 @@ static int LuaSetHeader(lua_State *L) { OnlyCallDuringRequest(L, "SetHeader"); key = luaL_checklstring(L, 1, &keylen); val = luaL_optlstring(L, 2, 0, &vallen); - if (!val) return 0; + if (!val) + return 0; if ((h = GetHttpHeader(key, keylen)) == -1) { if (!IsValidHttpToken(key, keylen)) { luaL_argerror(L, 1, "invalid"); @@ -4283,7 +4355,8 @@ static int LuaGetCookie(lua_State *L) { } else { lua_pushnil(L); } - if (cookie) free(cookie); + if (cookie) + free(cookie); return 1; } @@ -4503,7 +4576,8 @@ static int LuaProgramUniprocess(lua_State *L) { return luaL_argerror(L, 1, "invalid uniprocess mode; boolean expected"); } lua_pushboolean(L, uniprocess); - if (lua_isboolean(L, 1)) uniprocess = lua_toboolean(L, 1); + if (lua_isboolean(L, 1)) + uniprocess = lua_toboolean(L, 1); return 1; } @@ -4525,7 +4599,8 @@ static int LuaProgramMaxWorkers(lua_State *L) { return luaL_argerror(L, 1, "invalid number of workers; integer expected"); } lua_pushinteger(L, maxworkers); - if (lua_isinteger(L, 1)) maxworkers = lua_tointeger(L, 1); + if (lua_isinteger(L, 1)) + maxworkers = lua_tointeger(L, 1); maxworkers = MAX(maxworkers, 1); return 1; } @@ -4803,7 +4878,8 @@ static int LuaIsAssetCompressed(lua_State *L) { static bool Blackhole(uint32_t ip) { char buf[4]; - if (blackhole.fd <= 0) return false; + if (blackhole.fd <= 0) + return false; WRITE32BE(buf, ip); if (sendto(blackhole.fd, &buf, 4, 0, (struct sockaddr *)&blackhole.addr, sizeof(blackhole.addr)) != -1) { @@ -4927,8 +5003,10 @@ static int LuaProgramTokenBucket(lua_State *L) { reject, // ignore, // ban); - if (ignore == -1) ignore = -128; - if (ban == -1) ban = -128; + if (ignore == -1) + ignore = -128; + if (ban == -1) + ban = -128; if (ban >= 0 && (IsLinux() || IsBsd())) { uint32_t testip = 0; blackhole.addr.sun_family = AF_UNIX; @@ -4955,14 +5033,16 @@ static int LuaProgramTokenBucket(lua_State *L) { tokenbucket.replenish = timespec_fromnanos(1 / replenish * 1e9); int pid = fork(); npassert(pid != -1); - if (!pid) Replenisher(); + if (!pid) + Replenisher(); ++shared->workers; return 0; } static const char *GetContentTypeExt(const char *path, size_t n) { const char *r = NULL, *e; - if ((r = FindContentType(path, n))) return r; + if ((r = FindContentType(path, n))) + return r; #ifndef STATIC int top; lua_State *L = GL; @@ -5053,7 +5133,8 @@ static bool LuaRunAsset(const char *path, bool mandatory) { if (status != LUA_OK || LuaCallWithTrace(L, 0, 0, NULL) != LUA_OK) { LogLuaError("lua code", lua_tostring(L, -1)); lua_pop(L, 1); // pop error - if (mandatory) exit(1); + if (mandatory) + exit(1); } } } @@ -5416,7 +5497,8 @@ static void LuaPrint(lua_State *L) { n = lua_gettop(L); if (n > 0) { for (i = 1; i <= n; i++) { - if (i > 1) appendw(&b, '\t'); + if (i > 1) + appendw(&b, '\t'); struct EncoderConfig conf = { .maxdepth = 64, .sorted = true, @@ -5450,12 +5532,14 @@ static int LuaInterpreter(lua_State *L) { const char *script; if (optind < __argc) { script = __argv[optind]; - if (!strcmp(script, "-")) script = 0; + if (!strcmp(script, "-")) + script = 0; if ((status = luaL_loadfile(L, script)) == LUA_OK) { lua_getglobal(L, "arg"); n = luaL_len(L, -1); luaL_checkstack(L, n + 3, "too many script args"); - for (i = 1; i <= n; i++) lua_rawgeti(L, -i, i); + for (i = 1; i <= n; i++) + lua_rawgeti(L, -i, i); lua_remove(L, -i); // remove arg table from stack TRACE_BEGIN; status = lua_runchunk(L, n, LUA_MULTRET); @@ -5469,7 +5553,8 @@ static int LuaInterpreter(lua_State *L) { EnableRawMode(); for (;;) { status = lua_loadline(L); - if (status == -1) break; // eof + if (status == -1) + break; // eof if (status == -2) { if (errno == EINTR) { if ((sig = linenoiseGetInterrupt())) { @@ -5579,10 +5664,14 @@ static void LuaOnServerReload(bool reindex) { } static const char *DescribeClose(void) { - if (killed) return "killed"; - if (meltdown) return "meltdown"; - if (terminated) return "terminated"; - if (connectionclose) return "connection closed"; + if (killed) + return "killed"; + if (meltdown) + return "meltdown"; + if (terminated) + return "terminated"; + if (connectionclose) + return "connection closed"; return "destroyed"; } @@ -5859,7 +5948,8 @@ static char *ReadMore(void) { ssize_t rc; LockInc(&shared->c.frags); if ((rc = reader(client, inbuf.p + amtread, inbuf.n - amtread)) != -1) { - if (!(got = rc)) return HandlePayloadDisconnect(); + if (!(got = rc)) + return HandlePayloadDisconnect(); amtread += got; } else if (errno == EINTR) { LockInc(&shared->c.readinterrupts); @@ -5877,10 +5967,12 @@ static char *ReadMore(void) { static char *SynchronizeLength(void) { char *p; if (hdrsize + payloadlength > amtread) { - if (hdrsize + payloadlength > inbuf.n) return HandleHugePayload(); + if (hdrsize + payloadlength > inbuf.n) + return HandleHugePayload(); SendContinueIfNeeded(); while (amtread < hdrsize + payloadlength) { - if ((p = ReadMore())) return p; + if ((p = ReadMore())) + return p; } } cpm.msgsize = hdrsize + payloadlength; @@ -5894,9 +5986,11 @@ static char *SynchronizeChunked(void) { SendContinueIfNeeded(); while (!(transferlength = Unchunk(&u, inbuf.p + hdrsize, amtread - hdrsize, &payloadlength))) { - if ((p = ReadMore())) return p; + if ((p = ReadMore())) + return p; } - if (transferlength == -1) return HandleHugePayload(); + if (transferlength == -1) + return HandleHugePayload(); cpm.msgsize = hdrsize + transferlength; return NULL; } @@ -5987,8 +6081,10 @@ static char *HandleRequest(void) { } else { return HandleVersionNotSupported(); } - if ((p = SynchronizeStream())) return p; - if (logbodies) LogBody("received", inbuf.p + hdrsize, payloadlength); + if ((p = SynchronizeStream())) + return p; + if (logbodies) + LogBody("received", inbuf.p + hdrsize, payloadlength); if (cpm.msg.version < 11 || HeaderEqualCase(kHttpConnection, "close")) { connectionclose = true; } @@ -6025,7 +6121,8 @@ static char *HandleRequest(void) { } FreeLater(url.params.p); #ifndef STATIC - if (hasonhttprequest) return LuaOnHttpRequest(); + if (hasonhttprequest) + return LuaOnHttpRequest(); #endif return Route(url.host.p, url.host.n, url.path.p, url.path.n); } @@ -6041,7 +6138,8 @@ static char *Route(const char *host, size_t hostlen, const char *path, return p; } if (SlicesEqual(path, pathlen, "/", 1)) { - if ((p = ServeIndex("/", 1))) return p; + if ((p = ServeIndex("/", 1))) + return p; return ServeListing(); } else if ((p = RoutePath(path, pathlen))) { return p; @@ -6090,16 +6188,19 @@ static char *RouteHost(const char *host, size_t hostlen, const char *path, hp = hm <= sizeof(b) ? b : FreeLater(xmalloc(hm)); hp[0] = '/'; mempcpy(mempcpy(hp + 1, host, hostlen), path, pathlen); - if ((p = RoutePath(hp, hn))) return p; + if ((p = RoutePath(hp, hn))) + return p; if (!isdigit(host[0])) { if (hostlen > 4 && READ32LE(host) == ('w' | 'w' << 8 | 'w' << 16 | '.' << 24)) { mempcpy(mempcpy(hp + 1, host + 4, hostlen - 4), path, pathlen); - if ((p = RoutePath(hp, hn - 4))) return p; + if ((p = RoutePath(hp, hn - 4))) + return p; } else { mempcpy(mempcpy(mempcpy(hp + 1, "www.", 4), host, hostlen), path, pathlen); - if ((p = RoutePath(hp, hn + 4))) return p; + if ((p = RoutePath(hp, hn + 4))) + return p; } } } @@ -6123,7 +6224,8 @@ static inline bool IsLua(struct Asset *a) { static char *HandleAsset(struct Asset *a, const char *path, size_t pathlen) { char *p; #ifndef STATIC - if (IsLua(a)) return ServeLua(a, path, pathlen); + if (IsLua(a)) + return ServeLua(a, path, pathlen); #endif if (cpm.msg.method == kHttpGet || cpm.msg.method == kHttpHead) { LockInc(&shared->c.staticrequests); @@ -6150,8 +6252,10 @@ static const char *GetContentType(struct Asset *a, const char *path, size_t n) { } static bool IsNotModified(struct Asset *a) { - if (cpm.msg.version < 10) return false; - if (!HasHeader(kHttpIfModifiedSince)) return false; + if (cpm.msg.version < 10) + return false; + if (!HasHeader(kHttpIfModifiedSince)) + return false; return a->lastmodified <= ParseHttpDateTime(HeaderData(kHttpIfModifiedSince), HeaderLength(kHttpIfModifiedSince)); @@ -6217,8 +6321,10 @@ static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) { static char *SetStatus(unsigned code, const char *reason) { if (cpm.msg.version == 10) { - if (code == 307) code = 302; - if (code == 308) code = 301; + if (code == 307) + code = 302; + if (code == 308) + code = 301; } cpm.statuscode = code; cpm.hascontenttype = false; @@ -6321,7 +6427,8 @@ static bool StreamResponse(char *p) { iov[3].iov_len = 0; iov[4].iov_base = 0; iov[4].iov_len = 0; - if ((rc = cpm.generator(iov + 2)) <= 0) break; + if ((rc = cpm.generator(iov + 2)) <= 0) + break; if (cpm.msg.version >= 11) { s = chunkbuf; s += uint64toarray_radix16(rc, s); @@ -6329,7 +6436,8 @@ static bool StreamResponse(char *p) { iov[1].iov_base = chunkbuf; iov[1].iov_len = s - chunkbuf; } - if (Send(iov, 6) == -1) break; + if (Send(iov, 6) == -1) + break; iov[0].iov_base = 0; iov[0].iov_len = 0; } @@ -6351,7 +6459,8 @@ static bool HandleMessageActual(void) { char *p; struct timespec now; if ((rc = ParseHttpMessage(&cpm.msg, inbuf.p, amtread)) != -1) { - if (!rc) return false; + if (!rc) + return false; hdrsize = rc; if (logmessages) { LogMessage("received", inbuf.p, hdrsize); @@ -6373,8 +6482,10 @@ static bool HandleMessageActual(void) { } if (cpm.msg.version >= 10) { p = AppendCrlf(stpcpy(stpcpy(p, "Date: "), shared->currentdate)); - if (!cpm.branded) p = stpcpy(p, serverheader); - if (extrahdrs) p = stpcpy(p, extrahdrs); + if (!cpm.branded) + p = stpcpy(p, serverheader); + if (extrahdrs) + p = stpcpy(p, extrahdrs); if (connectionclose) { p = stpcpy(p, "Connection: close\r\n"); } else if (timeout.tv_sec < 0 && cpm.msg.version >= 11) { @@ -6395,7 +6506,8 @@ static bool HandleMessageActual(void) { now = timespec_real(); reqtime = timespec_tomicros(timespec_sub(now, startrequest)); contime = timespec_tomicros(timespec_sub(now, startconnection)); - if (hasonloglatency) LuaOnLogLatency(reqtime, contime); + if (hasonloglatency) + LuaOnLogLatency(reqtime, contime); if (loglatency || LOGGABLE(kLogDebug)) LOGF(kLogDebug, "(stat) %`'.*s latency r: %,ldµs c: %,ldµs", cpm.msg.uri.b - cpm.msg.uri.a, inbuf.p + cpm.msg.uri.a, reqtime, @@ -6422,8 +6534,10 @@ static void InitRequest(void) { } static bool IsSsl(unsigned char c) { - if (c == 22) return true; - if (!(c & 128)) return false; + if (c == 22) + return true; + if (!(c & 128)) + return false; /* RHEL5 sends SSLv2 hello but supports TLS */ DEBUGF("(ssl) %s SSLv2 hello D:", DescribeClient()); return true; @@ -6440,7 +6554,8 @@ static void HandleMessages(void) { for (;;) { if (!cpm.msg.i && amtread) { startrequest = timespec_real(); - if (HandleMessage()) break; + if (HandleMessage()) + break; } if ((rc = reader(client, inbuf.p + amtread, inbuf.n - amtread)) != -1) { startrequest = timespec_real(); @@ -6483,7 +6598,8 @@ static void HandleMessages(void) { errno = 0; } else if (errno == EAGAIN) { LockInc(&shared->c.readtimeouts); - if (amtread) SendTimeout(); + if (amtread) + SendTimeout(); NotifyClose(); LogClose("read timeout"); return; @@ -6646,7 +6762,8 @@ static void *MemoryMonitor(void *arg) { if (tty != -1) { for (gen = 0, mi = 0, b = 0; !terminatemonitor;) { workers = atomic_load_explicit(&shared->workers, memory_order_relaxed); - if (id) id = MAX(1, MIN(id, workers)); + if (id) + id = MAX(1, MIN(id, workers)); if (!id && workers) { usleep(50000); continue; @@ -6931,11 +7048,16 @@ static int HandleConnection(size_t i) { static void MakeExecutableModifiable(void) { #ifdef __x86_64__ int ft; - if (!(SUPPORT_VECTOR & (_HOSTMETAL | _HOSTWINDOWS | _HOSTXNU))) return; - if (IsWindows()) return; // TODO - if (IsOpenbsd()) return; // TODO - if (IsNetbsd()) return; // TODO - if (endswith(zpath, ".dbg")) return; + if (!(SUPPORT_VECTOR & (_HOSTMETAL | _HOSTWINDOWS | _HOSTXNU))) + return; + if (IsWindows()) + return; // TODO + if (IsOpenbsd()) + return; // TODO + if (IsNetbsd()) + return; // TODO + if (endswith(zpath, ".dbg")) + return; close(zfd); ft = ftrace_enabled(0); if ((zfd = __open_executable()) == -1) { @@ -6999,8 +7121,10 @@ static int HandlePoll(int ms) { if (nfds) { // handle pollid/o events for (pollid = 0; pollid < 1 + servers.n; ++pollid) { - if (!polls[pollid].revents) continue; - if (polls[pollid].fd < 0) continue; + if (!polls[pollid].revents) + continue; + if (polls[pollid].fd < 0) + continue; if (polls[pollid].fd) { // handle listen socket lua_repl_lock(); @@ -7011,12 +7135,14 @@ static int HandlePoll(int ms) { rc = HandleConnection(serverid); ishandlingconnection = false; lua_repl_unlock(); - if (rc == -1) return -1; + if (rc == -1) + return -1; #ifndef STATIC } else { // handle standard input rc = HandleReadline(); - if (rc == -1) return rc; + if (rc == -1) + return rc; #endif } } @@ -7024,7 +7150,8 @@ static int HandlePoll(int ms) { } else if (__ttyconf.replmode) { // handle refresh repl line rc = HandleReadline(); - if (rc < 0) return rc; + if (rc < 0) + return rc; #endif } } else { @@ -7094,7 +7221,8 @@ static void Listen(void) { } port = ntohs(servers.p[n].addr.sin_port); ip = ntohl(servers.p[n].addr.sin_addr.s_addr); - if (ip == INADDR_ANY) ip = INADDR_LOOPBACK; + if (ip == INADDR_ANY) + ip = INADDR_LOOPBACK; INFOF("(srvr) listen http://%hhu.%hhu.%hhu.%hhu:%d", ip >> 24, ip >> 16, ip >> 8, ip, port); if (printport && !ports.p[j]) { @@ -7122,7 +7250,8 @@ static void HandleShutdown(void) { CloseServerFds(); INFOF("(srvr) received %s", strsignal(shutdownsig)); if (shutdownsig != SIGINT && shutdownsig != SIGQUIT) { - if (!killed) terminated = false; + if (!killed) + terminated = false; INFOF("(srvr) killing process group"); KillGroup(); } @@ -7193,7 +7322,8 @@ static void SigInit(void) { static void TlsInit(void) { #ifndef UNSECURE int suite; - if (unsecure) return; + if (unsecure) + return; if (suiteb && !mbedtls_aes_uses_hardware()) { WARNF("(srvr) requested suiteb crypto, but hardware aes not present"); @@ -7227,7 +7357,8 @@ static void TlsInit(void) { mbedtls_ssl_ticket_parse, &ssltick); } - if (sslinitialized) return; + if (sslinitialized) + return; sslinitialized = true; LoadCertificates(); @@ -7257,7 +7388,8 @@ static void TlsInit(void) { static void TlsDestroy(void) { #ifndef UNSECURE - if (unsecure) return; + if (unsecure) + return; mbedtls_ssl_free(&ssl); mbedtls_ssl_free(&sslcli); mbedtls_ctr_drbg_free(&rng); @@ -7352,9 +7484,11 @@ static void GetOpts(int argc, char *argv[]) { } } // if storing asset(s) is requested, don't need to continue - if (storeasset) exit(0); + if (storeasset) + exit(0); // we don't want to drop into a repl after using -e in -i mode - if (interpretermode && got_e_arg) exit(0); + if (interpretermode && got_e_arg) + exit(0); } void RedBean(int argc, char *argv[]) { @@ -7362,7 +7496,8 @@ void RedBean(int argc, char *argv[]) { int fd; // don't complain about --assimilate if it's the only parameter, // as it can only get here if it's already native or assimilated - if (argc == 2 && strcmp(argv[1], "--assimilate") == 0) return; + if (argc == 2 && strcmp(argv[1], "--assimilate") == 0) + return; if (IsLinux()) { // disable weird linux capabilities for (int e = errno, i = 0;; ++i) { @@ -7415,7 +7550,8 @@ void RedBean(int argc, char *argv[]) { shared->workers = 1; } if (daemonize) { - if (!logpath) ProgramLogPath("/dev/null"); + if (!logpath) + ProgramLogPath("/dev/null"); dup2(2, 1); } SigInit(); diff --git a/tool/plinko/lib/char.c b/tool/plinko/lib/char.c index 4a1dd48b5..fa746560e 100644 --- a/tool/plinko/lib/char.c +++ b/tool/plinko/lib/char.c @@ -24,9 +24,12 @@ pureconst bool IsHex(int c) { } pureconst int GetDiglet(int c) { - if (IsDigit(c)) return c - L'0'; - if (IsUpper(c)) return c - L'A' + 10; - if (IsLower(c)) return c - L'a' + 10; + if (IsDigit(c)) + return c - L'0'; + if (IsUpper(c)) + return c - L'A' + 10; + if (IsLower(c)) + return c - L'a' + 10; return -1; } diff --git a/tool/plinko/lib/cmp.c b/tool/plinko/lib/cmp.c index 790923521..5de4f466c 100644 --- a/tool/plinko/lib/cmp.c +++ b/tool/plinko/lib/cmp.c @@ -50,20 +50,29 @@ int Cmp(int x, int y) { int c; dword t, u; - if (x == y) return 0; + if (x == y) + return 0; if (x > 1 && y > 1) { - if (LO(Get(x)) < LO(Get(x))) return -1; - if (LO(Get(x)) > LO(Get(x))) return +1; + if (LO(Get(x)) < LO(Get(x))) + return -1; + if (LO(Get(x)) > LO(Get(x))) + return +1; } for (;; x = Cdr(x), y = Cdr(y)) { - if (x == y) return 0; - if (!x) return -1; - if (!y) return +1; + if (x == y) + return 0; + if (!x) + return -1; + if (!y) + return +1; if (x < 0) { - if (y >= 0) return +1; - if ((c = Cmp(Car(x), Car(y)))) return c; + if (y >= 0) + return +1; + if ((c = Cmp(Car(x), Car(y)))) + return c; } else { - if (y < 0) return -1; + if (y < 0) + return -1; for (;;) { t = x != 1 ? Get(x) : MAKE(L'T', TERM); u = y != 1 ? Get(y) : MAKE(L'T', TERM); @@ -72,9 +81,12 @@ int Cmp(int x, int y) { } x = HI(t); y = HI(u); - if (x == y) return 0; - if (x == TERM) return -1; - if (y == TERM) return +1; + if (x == y) + return 0; + if (x == TERM) + return -1; + if (y == TERM) + return +1; } if (Car(x) != Car(y)) { return Car(x) < Car(y) ? -1 : +1; diff --git a/tool/plinko/lib/cons.c b/tool/plinko/lib/cons.c index c42ea3980..6343d8a54 100644 --- a/tool/plinko/lib/cons.c +++ b/tool/plinko/lib/cons.c @@ -38,7 +38,8 @@ int Shadow(int p, int s) { int GetCommonCons(int x, int y) { if (!y) { - if (!x) return -1; + if (!x) + return -1; if (x > 0 && cFrost < -1 && IsUpper(LO(Get(x))) && HI(Get(x)) == TERM) { return kConsAlphabet[LO(Get(x)) - L'A']; } @@ -48,7 +49,8 @@ int GetCommonCons(int x, int y) { int ShareCons(int x, int y) { int i; - if ((i = GetCommonCons(x, y))) return i; + if ((i = GetCommonCons(x, y))) + return i; #if 0 t = MAKE(x, y); for (i = cx, n = MIN(0, i + 64); i < n; ++i) { diff --git a/tool/plinko/lib/countatoms.c b/tool/plinko/lib/countatoms.c index a05232a2e..4eb9132bd 100644 --- a/tool/plinko/lib/countatoms.c +++ b/tool/plinko/lib/countatoms.c @@ -19,7 +19,9 @@ #include "tool/plinko/lib/plinko.h" nosideeffect int CountAtoms(int x, int max, int res) { - if (!x || res >= max) return res; - if (x > 0) return res + 1; + if (!x || res >= max) + return res; + if (x > 0) + return res + 1; return CountAtoms(Cdr(x), max, CountAtoms(Car(x), max, res)); } diff --git a/tool/plinko/lib/define.c b/tool/plinko/lib/define.c index 7a1a0dfd0..837c102a7 100644 --- a/tool/plinko/lib/define.c +++ b/tool/plinko/lib/define.c @@ -36,8 +36,10 @@ int Define(int e, int a) { struct Gc *G; int k, v, x, r, o; DCHECK_EQ(kDefine, Car(e)); - if (Cdr(e) >= 0) Error("bad define: %S", e); - if (Cadr(e) <= 0) Error("scheme define: %S", e); + if (Cdr(e) >= 0) + Error("bad define: %S", e); + if (Cadr(e) <= 0) + Error("scheme define: %S", e); if (Cddr(e) >= 0 || Caddr(e) == kLambda) { /* * compatibility with sectorlisp friendly branch, e.g. diff --git a/tool/plinko/lib/dispatchycombine.c b/tool/plinko/lib/dispatchycombine.c index 4c2bea324..1c63170b2 100644 --- a/tool/plinko/lib/dispatchycombine.c +++ b/tool/plinko/lib/dispatchycombine.c @@ -55,7 +55,8 @@ struct T DispatchYcombine(dword ea, dword tm, dword r, dword p1, dword p2, lambda = recurse(MAKE(Cadr(ea), HI(ea)), p1, p2); closure = recurse(MAKE(Caddr(ycomb), Alist(Car(Cadr(ycomb)), lambda, 0)), 0, 0); - if (Car(lambda) == kClosure) lambda = Car(Cdr(lambda)); + if (Car(lambda) == kClosure) + lambda = Car(Cdr(lambda)); DCHECK_EQ(kClosure, Car(closure)); DCHECK_EQ(kLambda, Car(lambda)); DCHECK_EQ(kLambda, Car(Car(Cdr(closure)))); diff --git a/tool/plinko/lib/error.c b/tool/plinko/lib/error.c index 128122521..9f17201ca 100644 --- a/tool/plinko/lib/error.c +++ b/tool/plinko/lib/error.c @@ -51,7 +51,8 @@ relegated wontreturn void StackOverflow(void) { } relegated wontreturn void React(int e, int x, int k) { - if (!sp || e != LO(GetCurrentFrame())) Push(e); + if (!sp || e != LO(GetCurrentFrame())) + Push(e); Push(x); Raise(k); } diff --git a/tool/plinko/lib/evlis.c b/tool/plinko/lib/evlis.c index 6ec7734af..3c96bb7c0 100644 --- a/tool/plinko/lib/evlis.c +++ b/tool/plinko/lib/evlis.c @@ -20,8 +20,10 @@ #include "tool/plinko/lib/plinko.h" int Evlis(int x, int a, dword p1, dword p2) { - if (!x) return x; - if (x > 0) return FasterRecurse(x, a, p1, p2); + if (!x) + return x; + if (x > 0) + return FasterRecurse(x, a, p1, p2); int y = FasterRecurse(Car(x), a, p1, p2); return Cons(y, Evlis(Cdr(x), a, p1, p2)); } diff --git a/tool/plinko/lib/expand.c b/tool/plinko/lib/expand.c index a698aa5c6..c9916013e 100644 --- a/tool/plinko/lib/expand.c +++ b/tool/plinko/lib/expand.c @@ -26,8 +26,10 @@ int Exlis(int x, int a) { int y; - if (!x) return x; - if (x > 0) return expand(x, a); + if (!x) + return x; + if (x > 0) + return expand(x, a); y = expand(Car(x), a); return Keep(x, Cons(y, Exlis(Cdr(x), a))); } @@ -37,10 +39,13 @@ static int Expander(int e, int a) { for (s = 0;;) { DCHECK_LT(e, TERM); DCHECK_LE(a, 0); - if (e >= 0) return e; + if (e >= 0) + return e; if ((f = Car(e)) > 0) { - if (f == kQuote) return e; - if (f == kClosure) return e; + if (f == kQuote) + return e; + if (f == kClosure) + return e; if (f == kTrace) { START_TRACE; x = Cadr(e); @@ -49,14 +54,17 @@ static int Expander(int e, int a) { END_TRACE; return e; } - if (HasAtom(f, s)) return e; + if (HasAtom(f, s)) + return e; s = Cons(f, s); } e = Exlis(e, a); if (f >= 0) { - if (!(f = Assoc(f, a))) return e; + if (!(f = Assoc(f, a))) + return e; f = Cdr(f); - if (f >= 0) return e; + if (f >= 0) + return e; } if (Car(f) == kClosure) { u = Cddr(f); @@ -64,7 +72,8 @@ static int Expander(int e, int a) { } else { u = a; } - if (Head(f) != kMacro) return e; + if (Head(f) != kMacro) + return e; e = eval(Caddr(f), pairlis(Cadr(f), Cdr(e), u)); } } diff --git a/tool/plinko/lib/gc.c b/tool/plinko/lib/gc.c index 53bb04891..08ef948a8 100644 --- a/tool/plinko/lib/gc.c +++ b/tool/plinko/lib/gc.c @@ -48,7 +48,8 @@ struct Gc *NewGc(int A) { struct Gc *G; DCHECK_LE(B, A); DCHECK_LE(A, 0); - if (B < cHeap) cHeap = B; + if (B < cHeap) + cHeap = B; n = ROUNDUP(A - B, DWBITS) / DWBITS; G = Addr(BANE); bzero(G->M, n * sizeof(G->M[0])); @@ -65,7 +66,8 @@ void Marker(const dword M[], int A, int x) { dword t; do { i = ~(x - A); - if (HasBit(M, i)) return; + if (HasBit(M, i)) + return; SetBit((void *)M, i); if (HI(GetShadow(x)) < A) { Marker(M, A, HI(GetShadow(x))); @@ -118,7 +120,8 @@ int Relocater(const dword M[], const unsigned P[], int A, int x) { void Sweep(struct Gc *G) { dword m; int a, b, d, i, j; - if (G->noop) return; + if (G->noop) + return; i = 0; b = d = G->A; for (; i < G->n; ++i) { @@ -146,7 +149,8 @@ void Sweep(struct Gc *G) { int MarkSweep(int A, int x) { struct Gc *G; - if (x >= A) return cx = A, x; + if (x >= A) + return cx = A, x; G = NewGc(A); Mark(G, x); Census(G); diff --git a/tool/plinko/lib/hasatom.c b/tool/plinko/lib/hasatom.c index cdd776284..c070b8c4e 100644 --- a/tool/plinko/lib/hasatom.c +++ b/tool/plinko/lib/hasatom.c @@ -19,7 +19,9 @@ #include "tool/plinko/lib/plinko.h" nosideeffect bool HasAtom(int v, int x) { - if (!x) return false; - if (x > 0) return v == x; + if (!x) + return false; + if (x > 0) + return v == x; return HasAtom(v, Car(x)) || HasAtom(v, Cdr(x)); } diff --git a/tool/plinko/lib/histo.c b/tool/plinko/lib/histo.c index d8dc55fc6..48d62dcaf 100644 --- a/tool/plinko/lib/histo.c +++ b/tool/plinko/lib/histo.c @@ -27,10 +27,12 @@ void PrintHistogram(int fd, const char *s, const long *h, size_t n) { int j, p, m; char buf[101]; size_t i, logos; - if (!(t = GetLongSum(h, n))) return; + if (!(t = GetLongSum(h, n))) + return; Fprintf(fd, "%s%n", s); for (i = 0; i < n; ++i) { - if (!h[i]) continue; + if (!h[i]) + continue; p = h[i] * 1000000 / t; assert(0 <= p && p <= 1000000); for (j = 0, m = p / 10000; j < m; ++j) { diff --git a/tool/plinko/lib/iscar.c b/tool/plinko/lib/iscar.c index 1de478623..67861e8d1 100644 --- a/tool/plinko/lib/iscar.c +++ b/tool/plinko/lib/iscar.c @@ -28,16 +28,20 @@ */ int IsCar(int x_) { dword w_; - if (x_ >= 0) return 0; + if (x_ >= 0) + return 0; w_ = Get(x_); // (⍅ X) int ax_ = LO(w_); int dx_ = HI(w_); - if (ax_ != kCar) return 0; - if (dx_ >= 0) return 0; + if (ax_ != kCar) + return 0; + if (dx_ >= 0) + return 0; w_ = Get(dx_); // (X) int adx_ = LO(w_); int ddx_ = HI(w_); int X = adx_; - if (ddx_) return 0; + if (ddx_) + return 0; return X; } diff --git a/tool/plinko/lib/iscdr.c b/tool/plinko/lib/iscdr.c index 45f594b32..0b70cf68e 100644 --- a/tool/plinko/lib/iscdr.c +++ b/tool/plinko/lib/iscdr.c @@ -28,16 +28,20 @@ */ int IsCdr(int x_) { dword w_; - if (x_ >= 0) return 0; + if (x_ >= 0) + return 0; w_ = Get(x_); // (⍆ X) int ax_ = LO(w_); int dx_ = HI(w_); - if (ax_ != kCdr) return 0; - if (dx_ >= 0) return 0; + if (ax_ != kCdr) + return 0; + if (dx_ >= 0) + return 0; w_ = Get(dx_); // (X) int adx_ = LO(w_); int ddx_ = HI(w_); int X = adx_; - if (ddx_) return 0; + if (ddx_) + return 0; return X; } diff --git a/tool/plinko/lib/isconstant.c b/tool/plinko/lib/isconstant.c index e1d37a5c4..92fd0fd5f 100644 --- a/tool/plinko/lib/isconstant.c +++ b/tool/plinko/lib/isconstant.c @@ -20,9 +20,13 @@ pureconst bool IsConstant(int e) { unsigned f = LO(GetShadow(e)); - if (f == EncodeDispatchFn(DispatchNil)) return true; - if (f == EncodeDispatchFn(DispatchTrue)) return true; - if (f == EncodeDispatchFn(DispatchPrecious)) return true; - if (f == EncodeDispatchFn(DispatchQuote)) return true; + if (f == EncodeDispatchFn(DispatchNil)) + return true; + if (f == EncodeDispatchFn(DispatchTrue)) + return true; + if (f == EncodeDispatchFn(DispatchPrecious)) + return true; + if (f == EncodeDispatchFn(DispatchQuote)) + return true; return false; } diff --git a/tool/plinko/lib/isdelegate.c b/tool/plinko/lib/isdelegate.c index 06a7ae9c3..241429189 100644 --- a/tool/plinko/lib/isdelegate.c +++ b/tool/plinko/lib/isdelegate.c @@ -30,25 +30,32 @@ */ int IsDelegate(int x_) { dword w_; - if (x_ >= 0) return 0; + if (x_ >= 0) + return 0; w_ = Get(x_); // (λ V (F . V) . Q) int ax_ = LO(w_); int dx_ = HI(w_); - if (ax_ != kLambda) return 0; - if (dx_ >= 0) return 0; + if (ax_ != kLambda) + return 0; + if (dx_ >= 0) + return 0; w_ = Get(dx_); // (V (F . V) . Q) int adx_ = LO(w_); int ddx_ = HI(w_); int V = adx_; - if (V <= 0) return 0; - if (ddx_ >= 0) return 0; + if (V <= 0) + return 0; + if (ddx_ >= 0) + return 0; w_ = Get(ddx_); // ((F . V) . Q) int addx_ = LO(w_); - if (addx_ >= 0) return 0; + if (addx_ >= 0) + return 0; w_ = Get(addx_); // (F . V) int aaddx_ = LO(w_); int daddx_ = HI(w_); int F = aaddx_; - if (daddx_ != V) return 0; + if (daddx_ != V) + return 0; return F; } diff --git a/tool/plinko/lib/isif.c b/tool/plinko/lib/isif.c index e872ff7d7..0b141c68f 100644 --- a/tool/plinko/lib/isif.c +++ b/tool/plinko/lib/isif.c @@ -28,36 +28,46 @@ */ struct qword IsIf(int x_) { dword w_; - if (x_ >= 0) return ZERO4; + if (x_ >= 0) + return ZERO4; w_ = Get(x_); // (ζ (X Y) (Z)) int ax_ = LO(w_); int dx_ = HI(w_); - if (ax_ != kCond) return ZERO4; - if (dx_ >= 0) return ZERO4; + if (ax_ != kCond) + return ZERO4; + if (dx_ >= 0) + return ZERO4; w_ = Get(dx_); // ((X Y) (Z)) int adx_ = LO(w_); int ddx_ = HI(w_); - if (adx_ >= 0) return ZERO4; + if (adx_ >= 0) + return ZERO4; w_ = Get(adx_); // (X Y) int aadx_ = LO(w_); int dadx_ = HI(w_); - if (ddx_ >= 0) return ZERO4; + if (ddx_ >= 0) + return ZERO4; w_ = Get(ddx_); // ((Z)) int addx_ = LO(w_); int dddx_ = HI(w_); int X = aadx_; - if (addx_ >= 0) return ZERO4; + if (addx_ >= 0) + return ZERO4; w_ = Get(addx_); // (Z) int aaddx_ = LO(w_); int daddx_ = HI(w_); - if (dadx_ >= 0) return ZERO4; + if (dadx_ >= 0) + return ZERO4; w_ = Get(dadx_); // (Y) int adadx_ = LO(w_); int ddadx_ = HI(w_); - if (dddx_) return ZERO4; + if (dddx_) + return ZERO4; int Y = adadx_; int Z = aaddx_; - if (ddadx_) return ZERO4; - if (daddx_) return ZERO4; + if (ddadx_) + return ZERO4; + if (daddx_) + return ZERO4; return MAKE4(X, Y, Z, 0); } diff --git a/tool/plinko/lib/isycombinator.c b/tool/plinko/lib/isycombinator.c index 032b8714e..47b1849cb 100644 --- a/tool/plinko/lib/isycombinator.c +++ b/tool/plinko/lib/isycombinator.c @@ -34,138 +34,190 @@ */ bool IsYcombinator(int x_) { dword w_; - if (x_ >= 0) return false; + if (x_ >= 0) + return false; w_ = Get(x_); int ax_ = LO(w_); int dx_ = HI(w_); - if (ax_ != kClosure) return false; - if (dx_ >= 0) return false; + if (ax_ != kClosure) + return false; + if (dx_ >= 0) + return false; w_ = Get(dx_); // ((λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) . Q) int adx_ = LO(w_); - if (adx_ >= 0) return false; + if (adx_ >= 0) + return false; w_ = Get(adx_); // (λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) int aadx_ = LO(w_); int dadx_ = HI(w_); - if (aadx_ != kLambda) return false; - if (dadx_ >= 0) return false; + if (aadx_ != kLambda) + return false; + if (dadx_ >= 0) + return false; w_ = Get(dadx_); // ((N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) int adadx_ = LO(w_); int ddadx_ = HI(w_); - if (adadx_ >= 0) return false; + if (adadx_ >= 0) + return false; w_ = Get(adadx_); // (N) int aadadx_ = LO(w_); int dadadx_ = HI(w_); - if (ddadx_ >= 0) return false; + if (ddadx_ >= 0) + return false; w_ = Get(ddadx_); // (((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) int addadx_ = LO(w_); int dddadx_ = HI(w_); int N = aadadx_; - if (N <= 0) return false; - if (addadx_ >= 0) return false; + if (N <= 0) + return false; + if (addadx_ >= 0) + return false; w_ = Get(addadx_); // ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))) int aaddadx_ = LO(w_); int daddadx_ = HI(w_); - if (dadadx_) return false; - if (dddadx_) return false; - if (aaddadx_ >= 0) return false; + if (dadadx_) + return false; + if (dddadx_) + return false; + if (aaddadx_ >= 0) + return false; w_ = Get(aaddadx_); // (λ (W) (W W)) int aaaddadx_ = LO(w_); int daaddadx_ = HI(w_); - if (daddadx_ >= 0) return false; + if (daddadx_ >= 0) + return false; w_ = Get(daddadx_); // ((λ (V) (N (λ M ((V V) . M))))) int adaddadx_ = LO(w_); int ddaddadx_ = HI(w_); - if (aaaddadx_ != kLambda) return false; - if (adaddadx_ >= 0) return false; + if (aaaddadx_ != kLambda) + return false; + if (adaddadx_ >= 0) + return false; w_ = Get(adaddadx_); // (λ (V) (N (λ M ((V V) . M)))) int aadaddadx_ = LO(w_); int dadaddadx_ = HI(w_); - if (daaddadx_ >= 0) return false; + if (daaddadx_ >= 0) + return false; w_ = Get(daaddadx_); // ((W) (W W)) int adaaddadx_ = LO(w_); int ddaaddadx_ = HI(w_); - if (ddaddadx_) return false; - if (adaaddadx_ >= 0) return false; + if (ddaddadx_) + return false; + if (adaaddadx_ >= 0) + return false; w_ = Get(adaaddadx_); // (W) int aadaaddadx_ = LO(w_); int dadaaddadx_ = HI(w_); - if (aadaddadx_ != kLambda) return false; - if (ddaaddadx_ >= 0) return false; + if (aadaddadx_ != kLambda) + return false; + if (ddaaddadx_ >= 0) + return false; w_ = Get(ddaaddadx_); // ((W W)) int addaaddadx_ = LO(w_); int dddaaddadx_ = HI(w_); - if (dadaddadx_ >= 0) return false; + if (dadaddadx_ >= 0) + return false; w_ = Get(dadaddadx_); // ((V) (N (λ M ((V V) . M)))) int adadaddadx_ = LO(w_); int ddadaddadx_ = HI(w_); int W = aadaaddadx_; - if (W <= 0) return false; - if (adadaddadx_ >= 0) return false; + if (W <= 0) + return false; + if (adadaddadx_ >= 0) + return false; w_ = Get(adadaddadx_); // (V) int aadadaddadx_ = LO(w_); int dadadaddadx_ = HI(w_); - if (addaaddadx_ >= 0) return false; + if (addaaddadx_ >= 0) + return false; w_ = Get(addaaddadx_); // (W W) int aaddaaddadx_ = LO(w_); int daddaaddadx_ = HI(w_); - if (ddadaddadx_ >= 0) return false; + if (ddadaddadx_ >= 0) + return false; w_ = Get(ddadaddadx_); // ((N (λ M ((V V) . M)))) int addadaddadx_ = LO(w_); int dddadaddadx_ = HI(w_); - if (dadaaddadx_) return false; + if (dadaaddadx_) + return false; int V = aadadaddadx_; - if (V <= 0) return false; - if (dddaaddadx_) return false; - if (addadaddadx_ >= 0) return false; + if (V <= 0) + return false; + if (dddaaddadx_) + return false; + if (addadaddadx_ >= 0) + return false; w_ = Get(addadaddadx_); // (N (λ M ((V V) . M))) int aaddadaddadx_ = LO(w_); int daddadaddadx_ = HI(w_); - if (aaddaaddadx_ != W) return false; - if (dadadaddadx_) return false; - if (daddaaddadx_ >= 0) return false; + if (aaddaaddadx_ != W) + return false; + if (dadadaddadx_) + return false; + if (daddaaddadx_ >= 0) + return false; w_ = Get(daddaaddadx_); // (W) int adaddaaddadx_ = LO(w_); int ddaddaaddadx_ = HI(w_); - if (dddadaddadx_) return false; - if (adaddaaddadx_ != W) return false; - if (aaddadaddadx_ != N) return false; - if (ddaddaaddadx_) return false; - if (daddadaddadx_ >= 0) return false; + if (dddadaddadx_) + return false; + if (adaddaaddadx_ != W) + return false; + if (aaddadaddadx_ != N) + return false; + if (ddaddaaddadx_) + return false; + if (daddadaddadx_ >= 0) + return false; w_ = Get(daddadaddadx_); // ((λ M ((V V) . M))) int adaddadaddadx_ = LO(w_); int ddaddadaddadx_ = HI(w_); - if (adaddadaddadx_ >= 0) return false; + if (adaddadaddadx_ >= 0) + return false; w_ = Get(adaddadaddadx_); // (λ M ((V V) . M)) int aadaddadaddadx_ = LO(w_); int dadaddadaddadx_ = HI(w_); - if (ddaddadaddadx_) return false; - if (aadaddadaddadx_ != kLambda) return false; - if (dadaddadaddadx_ >= 0) return false; + if (ddaddadaddadx_) + return false; + if (aadaddadaddadx_ != kLambda) + return false; + if (dadaddadaddadx_ >= 0) + return false; w_ = Get(dadaddadaddadx_); // (M ((V V) . M)) int adadaddadaddadx_ = LO(w_); int ddadaddadaddadx_ = HI(w_); int M = adadaddadaddadx_; - if (M <= 0) return false; - if (ddadaddadaddadx_ >= 0) return false; + if (M <= 0) + return false; + if (ddadaddadaddadx_ >= 0) + return false; w_ = Get(ddadaddadaddadx_); // (((V V) . M)) int addadaddadaddadx_ = LO(w_); int dddadaddadaddadx_ = HI(w_); - if (addadaddadaddadx_ >= 0) return false; + if (addadaddadaddadx_ >= 0) + return false; w_ = Get(addadaddadaddadx_); // ((V V) . M) int aaddadaddadaddadx_ = LO(w_); int daddadaddadaddadx_ = HI(w_); - if (dddadaddadaddadx_) return false; - if (aaddadaddadaddadx_ >= 0) return false; + if (dddadaddadaddadx_) + return false; + if (aaddadaddadaddadx_ >= 0) + return false; w_ = Get(aaddadaddadaddadx_); // (V V) int aaaddadaddadaddadx_ = LO(w_); int daaddadaddadaddadx_ = HI(w_); - if (daddadaddadaddadx_ != M) return false; - if (aaaddadaddadaddadx_ != V) return false; - if (daaddadaddadaddadx_ >= 0) return false; + if (daddadaddadaddadx_ != M) + return false; + if (aaaddadaddadaddadx_ != V) + return false; + if (daaddadaddadaddadx_ >= 0) + return false; w_ = Get(daaddadaddadaddadx_); // (V) int adaaddadaddadaddadx_ = LO(w_); int ddaaddadaddadaddadx_ = HI(w_); - if (adaaddadaddadaddadx_ != V) return false; - if (ddaaddadaddadaddadx_) return false; + if (adaaddadaddadaddadx_ != V) + return false; + if (ddaaddadaddadaddadx_) + return false; return true; } diff --git a/tool/plinko/lib/makesclosures.c b/tool/plinko/lib/makesclosures.c index 52da8133c..6fd33f0cb 100644 --- a/tool/plinko/lib/makesclosures.c +++ b/tool/plinko/lib/makesclosures.c @@ -21,14 +21,18 @@ bool MakesClosures(int x) { int h; if (x < 0 && (h = Car(x)) != kQuote && h != kClosure) { - if (h == kMacro) return true; - if (h == kLambda) return true; + if (h == kMacro) + return true; + if (h == kLambda) + return true; if (h == kCond) { while ((x = Cdr(x)) < 0) { if ((h = Car(x)) < 0) { - if (MakesClosures(Car(h))) return true; + if (MakesClosures(Car(h))) + return true; if ((h = Cdr(h)) < 0) { - if (MakesClosures(Car(h))) return true; + if (MakesClosures(Car(h))) + return true; } } } diff --git a/tool/plinko/lib/pairlis.c b/tool/plinko/lib/pairlis.c index 3dadd0c97..2384b252f 100644 --- a/tool/plinko/lib/pairlis.c +++ b/tool/plinko/lib/pairlis.c @@ -21,8 +21,10 @@ #include "tool/plinko/lib/plinko.h" int Pairlis(int x, int y, int a) { - if (!x) return a; - if (x > 0) return Alist(x, y, a); + if (!x) + return a; + if (x > 0) + return Alist(x, y, a); if (y <= 0) { a = pairlis(Cdr(x), Cdr(y), a); return Car(x) ? pairlis(Car(x), Car(y), a) : a; diff --git a/tool/plinko/lib/plan.c b/tool/plinko/lib/plan.c index 3c412007e..3a383c1a7 100644 --- a/tool/plinko/lib/plan.c +++ b/tool/plinko/lib/plan.c @@ -28,9 +28,12 @@ nosideeffect int CountSimpleParameters(int x) { int i; for (i = 0; x; ++i, x = Cdr(x)) { - if (x > 0) return -1; // variadic args aren't simple - if (!Car(x)) return -1; // nil parameters aren't simple - if (Car(x) < 0) return -1; // destructured parameters aren't simple + if (x > 0) + return -1; // variadic args aren't simple + if (!Car(x)) + return -1; // nil parameters aren't simple + if (Car(x) < 0) + return -1; // destructured parameters aren't simple } return i; } @@ -38,157 +41,201 @@ nosideeffect int CountSimpleParameters(int x) { nosideeffect int CountSimpleArguments(int x) { int i; for (i = 0; x; ++i, x = Cdr(x)) { - if (x > 0) return -1; // apply isn't simple + if (x > 0) + return -1; // apply isn't simple } return i; } static dword PlanQuote(int e, int a, int s) { - if (Cdr(e) >= 0) React(e, e, kQuote); // one normal parameter required + if (Cdr(e) >= 0) + React(e, e, kQuote); // one normal parameter required return MAKE(DF(DispatchQuote), Cadr(e)); // >1 prms is sectorlisp comment } static dword PlanCar(int e, int a, int s) { - if (!Cdr(e)) return DF(DispatchNil); // (⍅) ⟺ (⍅ ⊥) - if (Cddr(e)) React(e, e, kCar); // too many args - if (!Cadr(e)) return DF(DispatchNil); + if (!Cdr(e)) + return DF(DispatchNil); // (⍅) ⟺ (⍅ ⊥) + if (Cddr(e)) + React(e, e, kCar); // too many args + if (!Cadr(e)) + return DF(DispatchNil); return MAKE(DF(DispatchCar), Cadr(e)); } static dword PlanCdr(int e, int a, int s) { - if (!Cdr(e)) return DF(DispatchNil); // (⍆) ⟺ (⍆ ⊥) - if (Cddr(e)) React(e, e, kCdr); // too many args - if (!ARG1(e)) return DF(DispatchNil); + if (!Cdr(e)) + return DF(DispatchNil); // (⍆) ⟺ (⍆ ⊥) + if (Cddr(e)) + React(e, e, kCdr); // too many args + if (!ARG1(e)) + return DF(DispatchNil); return MAKE(DF(DispatchCdr), Cadr(e)); } static dword PlanAtom(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kAtom); + if (CountSimpleArguments(Cdr(e)) != 1) + React(e, e, kAtom); return MAKE(DF(DispatchAtom), Cadr(e)); } static dword PlanEq(int e, int a, int s) { int n = CountSimpleArguments(Cdr(e)); - if (n != 2 && n != 1) React(e, e, kAtom); // (≡ 𝑥) is our (null 𝑥) + if (n != 2 && n != 1) + React(e, e, kAtom); // (≡ 𝑥) is our (null 𝑥) return MAKE(DF(DispatchEq), Caddr(e)); } static dword PlanCmp(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 2) React(e, e, kCmp); + if (CountSimpleArguments(Cdr(e)) != 2) + React(e, e, kCmp); return MAKE(DF(DispatchCmp), Caddr(e)); } static dword PlanOrder(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 2) React(e, e, kOrder); + if (CountSimpleArguments(Cdr(e)) != 2) + React(e, e, kOrder); return MAKE(DF(DispatchOrder), Caddr(e)); } static dword PlanCons(int e, int a, int s) { int p = CountSimpleArguments(Cdr(e)); - if (p == -1) Error("cons dot arg"); - if (p > 2) Error("too many args"); + if (p == -1) + Error("cons dot arg"); + if (p > 2) + Error("too many args"); return MAKE(DF(DispatchCons), Caddr(e)); } static dword PlanLambda(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) == -1) Error("bad lambda: %S", e); + if (CountSimpleArguments(Cdr(e)) == -1) + Error("bad lambda: %S", e); return DF(DispatchLambda); } static dword PlanCond(int e, int a, int s) { int x; - if (!Cdr(e)) return DF(DispatchNil); // (ζ) ⟺ ⊥ + if (!Cdr(e)) + return DF(DispatchNil); // (ζ) ⟺ ⊥ for (x = e; (x = Cdr(x));) { - if (x > 0) React(e, e, kCond); // (ζ . 𝑣) not allowed - if (Car(x) >= 0) React(e, e, kCond); // (ζ 𝑣) not allowed - if (Cdr(Car(x)) > 0) React(e, e, kCond); // (ζ (𝑥 . 𝑣)) not allowed + if (x > 0) + React(e, e, kCond); // (ζ . 𝑣) not allowed + if (Car(x) >= 0) + React(e, e, kCond); // (ζ 𝑣) not allowed + if (Cdr(Car(x)) > 0) + React(e, e, kCond); // (ζ (𝑥 . 𝑣)) not allowed } return MAKE(DF(DispatchCond), Cdr(e)); } static dword PlanProgn(int e, int a, int s) { - if (!Cdr(e)) return DF(DispatchNil); // (progn) ⟺ ⊥ - if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kProgn); + if (!Cdr(e)) + return DF(DispatchNil); // (progn) ⟺ ⊥ + if (CountSimpleArguments(Cdr(e)) == -1) + React(e, e, kProgn); return MAKE(DF(DispatchProgn), Cdr(e)); } static dword PlanQuiet(int e, int a, int s) { - if (Cdr(e) > 0) React(e, e, kQuiet); // apply not allowed - if (!Cdr(e)) React(e, e, kQuiet); // zero args not allowed - if (Cdr(Cdr(e))) React(e, e, kQuiet); // >1 args not allowed + if (Cdr(e) > 0) + React(e, e, kQuiet); // apply not allowed + if (!Cdr(e)) + React(e, e, kQuiet); // zero args not allowed + if (Cdr(Cdr(e))) + React(e, e, kQuiet); // >1 args not allowed return DF(DispatchQuiet); } static dword PlanTrace(int e, int a, int s) { - if (Cdr(e) > 0) React(e, e, kTrace); // apply not allowed - if (!Cdr(e)) React(e, e, kTrace); // zero args not allowed - if (Cdr(Cdr(e))) React(e, e, kTrace); // >1 args not allowed + if (Cdr(e) > 0) + React(e, e, kTrace); // apply not allowed + if (!Cdr(e)) + React(e, e, kTrace); // zero args not allowed + if (Cdr(Cdr(e))) + React(e, e, kTrace); // >1 args not allowed return DF(DispatchTrace); } static dword PlanFtrace(int e, int a, int s) { - if (Cdr(e) > 0) React(e, e, kFtrace); // apply not allowed - if (!Cdr(e)) React(e, e, kFtrace); // zero args not allowed - if (Cdr(Cdr(e))) React(e, e, kFtrace); // >1 args not allowed + if (Cdr(e) > 0) + React(e, e, kFtrace); // apply not allowed + if (!Cdr(e)) + React(e, e, kFtrace); // zero args not allowed + if (Cdr(Cdr(e))) + React(e, e, kFtrace); // >1 args not allowed return DF(DispatchFtrace); } static dword PlanFunction(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 1) Raise(kFunction); + if (CountSimpleArguments(Cdr(e)) != 1) + Raise(kFunction); return MAKE(DF(DispatchFunction), Cadr(e)); } static dword PlanBeta(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 1) Raise(kBeta); + if (CountSimpleArguments(Cdr(e)) != 1) + Raise(kBeta); return MAKE(DF(DispatchBeta), Cadr(e)); } static dword PlanIgnore(int e, int a, int s) { - if (!Cdr(e)) return DF(DispatchIgnore0); - if (Cdr(e) > 0) React(e, e, kIgnore); // apply not allowed - if (!Cdr(e)) React(e, e, kIgnore); // zero args not allowed - if (Cdr(Cdr(e))) React(e, e, kIgnore); // >1 args not allowed + if (!Cdr(e)) + return DF(DispatchIgnore0); + if (Cdr(e) > 0) + React(e, e, kIgnore); // apply not allowed + if (!Cdr(e)) + React(e, e, kIgnore); // zero args not allowed + if (Cdr(Cdr(e))) + React(e, e, kIgnore); // >1 args not allowed return DF(DispatchIgnore1); } static dword PlanExpand(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kExpand); + if (CountSimpleArguments(Cdr(e)) != 1) + React(e, e, kExpand); return MAKE(DF(DispatchExpand), Cadr(e)); } static dword PlanPrint(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPrint); + if (CountSimpleArguments(Cdr(e)) == -1) + React(e, e, kPrint); return DF(DispatchPrint); } static dword PlanGensym(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e))) React(e, e, kGensym); + if (CountSimpleArguments(Cdr(e))) + React(e, e, kGensym); return DF(DispatchGensym); } static dword PlanPprint(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPprint); + if (CountSimpleArguments(Cdr(e)) == -1) + React(e, e, kPprint); return DF(DispatchPprint); } static dword PlanPrintheap(int e, int a, int s) { int p = CountSimpleArguments(Cdr(e)); - if (p != 0 && p != 1) React(e, e, kPrintheap); + if (p != 0 && p != 1) + React(e, e, kPrintheap); return DF(DispatchPrintheap); } static dword PlanGc(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) != 1) React(e, e, kGc); + if (CountSimpleArguments(Cdr(e)) != 1) + React(e, e, kGc); return MAKE(DF(DispatchGc), Cadr(e)); } static dword PlanPrinc(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kPrinc); + if (CountSimpleArguments(Cdr(e)) == -1) + React(e, e, kPrinc); return DF(DispatchPrinc); } static dword PlanFlush(int e, int a, int s) { - if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kFlush); + if (CountSimpleArguments(Cdr(e)) == -1) + React(e, e, kFlush); return DF(DispatchFlush); } @@ -197,12 +244,14 @@ static dword PlanError(int e, int a, int s) { } static dword PlanExit(int e, int a, int s) { - if (Cdr(e)) React(e, e, kExit); + if (Cdr(e)) + React(e, e, kExit); return DF(DispatchExit); } static dword PlanRead(int e, int a, int s) { - if (Cdr(e)) React(e, e, kRead); + if (Cdr(e)) + React(e, e, kRead); return DF(DispatchRead); } @@ -216,16 +265,20 @@ static dword PlanClosure(int e, int a, int s) { static dword PlanLet(int e, int a, int s) { int n; - if ((n = CountSimpleArguments(Cdr(e))) == -1) return DF(DispatchFuncall); - if (CountSimpleArguments(Car(e)) < 3) React(e, e, kLambda); // need (λ 𝑥 𝑦) + if ((n = CountSimpleArguments(Cdr(e))) == -1) + return DF(DispatchFuncall); + if (CountSimpleArguments(Car(e)) < 3) + React(e, e, kLambda); // need (λ 𝑥 𝑦) switch (CountSimpleParameters(Cadr(Car(e)))) { case -1: return DF(DispatchFuncall); case 0: - if (n != 0) Error("let argument count mismatch: %S", e); + if (n != 0) + Error("let argument count mismatch: %S", e); return MAKE(DF(DispatchShortcut), Caddr(Car(e))); // ((λ ⊥ 𝑦)) becomes 𝑦 case 1: - if (n != 1) Error("let argument count mismatch: %S", e); + if (n != 1) + Error("let argument count mismatch: %S", e); return MAKE(DF(DispatchLet1), Cdar(e)); default: return MAKE(DF(DispatchFuncall), 0); @@ -234,37 +287,68 @@ static dword PlanLet(int e, int a, int s) { static dontinline dword PlanPrecious(int e, int a, int s, int f) { DCHECK_GT(f, 0); - if (f == kCar) return PlanCar(e, a, s); - if (f == kCdr) return PlanCdr(e, a, s); - if (f == kGc) return PlanGc(e, a, s); - if (f == kEq) return PlanEq(e, a, s); - if (f == kCmp) return PlanCmp(e, a, s); - if (f == kBeta) return PlanBeta(e, a, s); - if (f == kCond) return PlanCond(e, a, s); - if (f == kAtom) return PlanAtom(e, a, s); - if (f == kCons) return PlanCons(e, a, s); - if (f == kExit) return PlanExit(e, a, s); - if (f == kRead) return PlanRead(e, a, s); - if (f == kOrder) return PlanOrder(e, a, s); - if (f == kQuote) return PlanQuote(e, a, s); - if (f == kProgn) return PlanProgn(e, a, s); - if (f == kQuiet) return PlanQuiet(e, a, s); - if (f == kTrace) return PlanTrace(e, a, s); - if (f == kPrint) return PlanPrint(e, a, s); - if (f == kPrinc) return PlanPrinc(e, a, s); - if (f == kFlush) return PlanFlush(e, a, s); - if (f == kError) return PlanError(e, a, s); - if (f == kMacro) return PlanLambda(e, a, s); - if (f == kFtrace) return PlanFtrace(e, a, s); - if (f == kLambda) return PlanLambda(e, a, s); - if (f == kGensym) return PlanGensym(e, a, s); - if (f == kPprint) return PlanPprint(e, a, s); - if (f == kIgnore) return PlanIgnore(e, a, s); - if (f == kExpand) return PlanExpand(e, a, s); - if (f == kDefine) return PlanDefine(e, a, s); - if (f == kClosure) return PlanClosure(e, a, s); - if (f == kFunction) return PlanFunction(e, a, s); - if (f == kPrintheap) return PlanPrintheap(e, a, s); + if (f == kCar) + return PlanCar(e, a, s); + if (f == kCdr) + return PlanCdr(e, a, s); + if (f == kGc) + return PlanGc(e, a, s); + if (f == kEq) + return PlanEq(e, a, s); + if (f == kCmp) + return PlanCmp(e, a, s); + if (f == kBeta) + return PlanBeta(e, a, s); + if (f == kCond) + return PlanCond(e, a, s); + if (f == kAtom) + return PlanAtom(e, a, s); + if (f == kCons) + return PlanCons(e, a, s); + if (f == kExit) + return PlanExit(e, a, s); + if (f == kRead) + return PlanRead(e, a, s); + if (f == kOrder) + return PlanOrder(e, a, s); + if (f == kQuote) + return PlanQuote(e, a, s); + if (f == kProgn) + return PlanProgn(e, a, s); + if (f == kQuiet) + return PlanQuiet(e, a, s); + if (f == kTrace) + return PlanTrace(e, a, s); + if (f == kPrint) + return PlanPrint(e, a, s); + if (f == kPrinc) + return PlanPrinc(e, a, s); + if (f == kFlush) + return PlanFlush(e, a, s); + if (f == kError) + return PlanError(e, a, s); + if (f == kMacro) + return PlanLambda(e, a, s); + if (f == kFtrace) + return PlanFtrace(e, a, s); + if (f == kLambda) + return PlanLambda(e, a, s); + if (f == kGensym) + return PlanGensym(e, a, s); + if (f == kPprint) + return PlanPprint(e, a, s); + if (f == kIgnore) + return PlanIgnore(e, a, s); + if (f == kExpand) + return PlanExpand(e, a, s); + if (f == kDefine) + return PlanDefine(e, a, s); + if (f == kClosure) + return PlanClosure(e, a, s); + if (f == kFunction) + return PlanFunction(e, a, s); + if (f == kPrintheap) + return PlanPrintheap(e, a, s); if (!a) { Push(e); Push(f); @@ -280,26 +364,34 @@ dontinline dword Plan(int e, int a, int s) { if ((x1 = IsCar(e))) { if ((x2 = IsCar(x1))) { if ((x3 = IsCar(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaaaar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCaaadr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCaaaar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCaaadr), x4); return MAKE(DF(DispatchCaaar), x3); } if ((x3 = IsCdr(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaadar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCaaddr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCaadar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCaaddr), x4); return MAKE(DF(DispatchCaaar), x3); } return MAKE(DF(DispatchCaar), x2); } if ((x2 = IsCdr(x1))) { if ((x3 = IsCar(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCadaar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCadadr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCadaar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCadadr), x4); return MAKE(DF(DispatchCadar), x3); } if ((x3 = IsCdr(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCaddar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCadddr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCaddar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCadddr), x4); return MAKE(DF(DispatchCaddr), x3); } return MAKE(DF(DispatchCadr), x2); @@ -310,26 +402,34 @@ dontinline dword Plan(int e, int a, int s) { if ((x1 = IsCdr(e))) { if ((x2 = IsCar(x1))) { if ((x3 = IsCar(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdaaar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCdaadr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCdaaar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCdaadr), x4); return MAKE(DF(DispatchCdaar), x3); } if ((x3 = IsCdr(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdadar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCdaddr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCdadar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCdaddr), x4); return MAKE(DF(DispatchCdadr), x3); } return MAKE(DF(DispatchCdar), x2); } if ((x2 = IsCdr(x1))) { if ((x3 = IsCar(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCddaar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCddadr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCddaar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCddadr), x4); return MAKE(DF(DispatchCddar), x3); } if ((x3 = IsCdr(x2))) { - if ((x4 = IsCar(x3))) return MAKE(DF(DispatchCdddar), x4); - if ((x4 = IsCdr(x3))) return MAKE(DF(DispatchCddddr), x4); + if ((x4 = IsCar(x3))) + return MAKE(DF(DispatchCdddar), x4); + if ((x4 = IsCdr(x3))) + return MAKE(DF(DispatchCddddr), x4); return MAKE(DF(DispatchCdddr), x3); } return MAKE(DF(DispatchCddr), x2); diff --git a/tool/plinko/lib/plinko.c b/tool/plinko/lib/plinko.c index a088e7736..9766469b8 100644 --- a/tool/plinko/lib/plinko.c +++ b/tool/plinko/lib/plinko.c @@ -83,8 +83,10 @@ static void Backtrace(int S) { forceinline bool ShouldIgnoreGarbage(int A) { static unsigned cadence; - if (DEBUG_GARBAGE) return false; - if (!(++cadence & AVERSIVENESS)) return false; + if (DEBUG_GARBAGE) + return false; + if (!(++cadence & AVERSIVENESS)) + return false; return true; } @@ -101,13 +103,16 @@ static relegated dontinline int ErrorExpr(void) { } static int Order(int x, int y) { - if (x < y) return -1; - if (x > y) return +1; + if (x < y) + return -1; + if (x > y) + return +1; return 0; } static int Append(int x, int y) { - if (!x) return y; + if (!x) + return y; return Cons(Car(x), Append(Cdr(x), y)); } @@ -129,21 +134,25 @@ static int ReconstructAlist(int a) { static bool AtomEquals(int x, const char *s) { dword t; do { - if (!*s) return false; + if (!*s) + return false; t = Get(x); - if (LO(t) != *s++) return false; // xxx: ascii + if (LO(t) != *s++) + return false; // xxx: ascii } while ((x = HI(t)) != TERM); return !*s; } static pureconst int LastCons(int x) { - while (Cdr(x)) x = Cdr(x); + while (Cdr(x)) + x = Cdr(x); return x; } static pureconst int LastChar(int x) { dword e; - do e = Get(x); + do + e = Get(x); while ((x = HI(e)) != TERM); return LO(e); } @@ -157,13 +166,16 @@ forceinline pureconst bool IsQuote(int x) { } static int Quote(int x) { - if (IsClosure(x)) return x; - if (IsPrecious(x)) return x; + if (IsClosure(x)) + return x; + if (IsPrecious(x)) + return x; return List(kQuote, x); } static int QuoteList(int x) { - if (!x) return x; + if (!x) + return x; return Cons(Quote(Car(x)), QuoteList(Cdr(x))); } @@ -171,7 +183,8 @@ static int GetAtom(const char *s) { int x, y; ax = y = TERM; x = *s++ & 255; - if (*s) y = GetAtom(s); + if (*s) + y = GetAtom(s); return Intern(x, y); } @@ -182,7 +195,8 @@ static int Gensym(void) { n = 0; x = g++; B[n++] = L'G'; - do B[n++] = L'0' + (x & 7); + do + B[n++] = L'0' + (x & 7); while ((x >>= 3)); B[n] = 0; for (a = 1, b = n - 1; a < b; ++a, --b) { @@ -195,8 +209,10 @@ static int Gensym(void) { static nosideeffect bool Member(int v, int x) { while (x) { - if (x > 0) return v == x; - if (v == Car(x)) return true; + if (x > 0) + return v == x; + if (v == Car(x)) + return true; x = Cdr(x); } return false; @@ -216,8 +232,10 @@ static int GetBindings(int x, int a) { static int Lambda(int e, int a, dword p1, dword p2) { int u; - if (p1) a = Alist(LO(p1), HI(p1), a); - if (p2) a = Alist(LO(p2), HI(p2), a); + if (p1) + a = Alist(LO(p1), HI(p1), a); + if (p2) + a = Alist(LO(p2), HI(p2), a); if (DEBUG_CLOSURE || logc) { u = FindFreeVariables(e, 0, 0); a = GetBindings(u, a); @@ -227,8 +245,10 @@ static int Lambda(int e, int a, dword p1, dword p2) { static int Function(int e, int a, dword p1, dword p2) { int u; - if (e < 0 && Car(e) == kLambda) e = Lambda(e, a, p1, p2); - if (e >= 0 || Car(e) != kClosure) Error("not a closure"); + if (e < 0 && Car(e) == kLambda) + e = Lambda(e, a, p1, p2); + if (e >= 0 || Car(e) != kClosure) + Error("not a closure"); a = Cddr(e); e = Cadr(e); u = FindFreeVariables(e, 0, 0); @@ -421,8 +441,10 @@ struct T DispatchLookup(dword ea, dword tm, dword r, dword p1, dword p2, DCHECK(!IsPrecious(e)); DCHECK_GT(e, 0); DCHECK_LE(a, 0); - if (LO(p1) == LO(ea)) return Ret(MAKE(HI(p1), 0), tm, r); - if (LO(p2) == LO(ea)) return Ret(MAKE(HI(p2), 0), tm, r); + if (LO(p1) == LO(ea)) + return Ret(MAKE(HI(p1), 0), tm, r); + if (LO(p2) == LO(ea)) + return Ret(MAKE(HI(p2), 0), tm, r); if ((kv = Assoc(e, a))) { return Ret(MAKE(Cdr(kv), 0), tm, r); // (eval 𝑘 (…(𝑘 𝑣)…)) ⟹ 𝑣 } else { @@ -473,10 +495,12 @@ struct T DispatchOrder(dword ea, dword tm, dword r, dword p1, dword p2, struct T DispatchCons(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { int x; - if (cx < cHeap) cHeap = cx; + if (cx < cHeap) + cHeap = cx; x = Car(Cdr(LO(ea))); x = FasterRecurse(x, HI(ea), p1, p2); - if (!HI(d)) return Ret(MAKE(Cons(x, 0), 0), tm, r); + if (!HI(d)) + return Ret(MAKE(Cons(x, 0), 0), tm, r); if (~r & NEED_POP) { r |= NEED_POP; Push(LO(ea)); @@ -720,7 +744,8 @@ struct T DispatchExpand(dword ea, dword tm, dword r, dword p1, dword p2, } static int GrabArgs(int x, int a, dword p1, dword p2) { - if (x >= 0) return x; + if (x >= 0) + return x; return Cons(recurse(MAKE(Car(x), a), p1, p2), GrabArgs(Cdr(x), a, p1, p2)); } @@ -991,7 +1016,8 @@ int Plinko(int argc, char *argv[]) { kTail[5] = DispatchTailGc; kTail[6] = DispatchTailImpossible; kTail[7] = DispatchTailTmcGc; - if (trace) EnableTracing(); + if (trace) + EnableTracing(); cx = -1; cFrost = cx; @@ -1006,7 +1032,8 @@ int Plinko(int argc, char *argv[]) { if (!(x = setjmp(crash))) { x = Read(0); x = expand(x, globals); - if (stats) ResetStats(); + if (stats) + ResetStats(); if (x < 0 && Car(x) == kDefine) { globals = Define(x, globals); cFrost = cx; diff --git a/tool/plinko/lib/preplan.c b/tool/plinko/lib/preplan.c index 63318679b..e1715656a 100644 --- a/tool/plinko/lib/preplan.c +++ b/tool/plinko/lib/preplan.c @@ -25,7 +25,8 @@ static int CopyTree(int x) { int a, b; - if (x >= 0) return x; + if (x >= 0) + return x; b = CopyTree(Cdr(x)); a = CopyTree(Car(x)); return Cons(a, b); @@ -33,7 +34,8 @@ static int CopyTree(int x) { static int PreplanCond(int e, int a, int s) { int f, g; - if (!(e = Cdr(e))) return 0; + if (!(e = Cdr(e))) + return 0; if ((f = Car(e)) < 0) { if ((g = Cdr(f)) < 0) { f = List(Preplan(Car(f), a, s), Preplan(Car(g), a, s)); @@ -45,14 +47,16 @@ static int PreplanCond(int e, int a, int s) { } static int PreplanList(int e, int a, int s) { - if (e >= 0) return e; + if (e >= 0) + return e; return Cons(Preplan(Car(e), a, s), PreplanList(Cdr(e), a, s)); } int Preplan(int e, int a, int s) { int f, x; struct qword q; - if (e >= 0) return e; + if (e >= 0) + return e; f = Car(e); if (f != kQuote) { if (f == kClosure) { diff --git a/tool/plinko/lib/prettyprint.c b/tool/plinko/lib/prettyprint.c index 8c47441cf..32e8d48d6 100644 --- a/tool/plinko/lib/prettyprint.c +++ b/tool/plinko/lib/prettyprint.c @@ -85,15 +85,18 @@ static void PrettyPrintList(int fd, int x, int n) { if (y >= 0) { argwidth += PrintSpace(fd); argwidth += PrintAtom(fd, y); - if (!once) n += argwidth; + if (!once) + n += argwidth; } else { if (once && (y < 0 || mode)) { mode = 1; PrintNewline(fd); - if (depth >= 0) PrintDepth(fd, depth); + if (depth >= 0) + PrintDepth(fd, depth); PrintIndent(fd, n); } else { - if (y < 0) mode = 1; + if (y < 0) + mode = 1; PrintSpace(fd); } once = 1; diff --git a/tool/plinko/lib/printchar.c b/tool/plinko/lib/printchar.c index a396be4de..1d63aa007 100644 --- a/tool/plinko/lib/printchar.c +++ b/tool/plinko/lib/printchar.c @@ -25,15 +25,18 @@ int PrintChar(int fd, int s) { unsigned c; int d, e, i, n; c = s & 0xffffffff; - if (bp[fd] + 6 > sizeof(g_buffer[fd])) Flush(fd); + if (bp[fd] + 6 > sizeof(g_buffer[fd])) + Flush(fd); if (c < 0200) { g_buffer[fd][bp[fd]++] = c; - if (c == L'\n') Flush(fd); + if (c == L'\n') + Flush(fd); } else { d = c; e = kTpEnc[bsrl(d) - 7]; i = n = e & 255; - do g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077); + do + g_buffer[fd][bp[fd] + i--] = 0200 | (d & 077); while (d >>= 6, i); g_buffer[fd][bp[fd]] = d | e >> 8; bp[fd] += n + 1; diff --git a/tool/plinko/lib/printf.c b/tool/plinko/lib/printf.c index 60720d3a2..ddc4c50be 100644 --- a/tool/plinko/lib/printf.c +++ b/tool/plinko/lib/printf.c @@ -27,7 +27,8 @@ #include "tool/plinko/lib/print.h" static inline long GetVarInt(va_list va, signed char t) { - if (t <= 0) return va_arg(va, int); + if (t <= 0) + return va_arg(va, int); return va_arg(va, long); } @@ -35,7 +36,8 @@ static int PrintStr(int fd, const char *s, int cols) { int n, k = 0, i = 0; n = strlen(s); k += PrintIndent(fd, +cols - n); - while (i < n) k += PrintChar(fd, s[i++]); + while (i < n) + k += PrintChar(fd, s[i++]); k += PrintIndent(fd, -cols - n); return k; } @@ -85,7 +87,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { ++recursive; for (ansi = 0;;) { for (;;) { - if (!(c = *f++ & 0377) || c == L'%') break; + if (!(c = *f++ & 0377) || c == L'%') + break; if (c >= 0300) { for (b = 0200; c & b; b >>= 1) { c ^= b; @@ -123,7 +126,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { EmitFormatByte: PrintChar(fd, c); } - if (!c) break; + if (!c) + break; prec = 0; pdot = 0; cols = 0; @@ -221,7 +225,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { } break; case L'p': - if (simpler) goto SimplePrint; + if (simpler) + goto SimplePrint; // fallthrough case L'P': n += PrettyPrint(fd, va_arg(va, int), @@ -251,7 +256,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { PrintChar(fd, L'('); for (;;) { n += Print(fd, Car(Car(b))); - if ((b = Cdr(b)) >= 0) break; + if ((b = Cdr(b)) >= 0) + break; PrintChar(fd, L' '); } PrintChar(fd, L')'); @@ -279,7 +285,8 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { break; case L's': s = va_arg(va, const char *); - if (!s) s = "NULL"; + if (!s) + s = "NULL"; n += PrintStr(fd, s, cols * sign); break; case L'c': diff --git a/tool/plinko/lib/printheap.c b/tool/plinko/lib/printheap.c index eaf2437e5..b6ca2c5f6 100644 --- a/tool/plinko/lib/printheap.c +++ b/tool/plinko/lib/printheap.c @@ -40,7 +40,8 @@ static const char *GetElfSymbol(uintptr_t funcaddr) { static const char *GetDispatchName(int x) { const char *s; s = GetElfSymbol(LO(GetShadow(x))); - if (startswith(s, "Dispatch")) s += 8; + if (startswith(s, "Dispatch")) + s += 8; return s; } diff --git a/tool/plinko/lib/printint.c b/tool/plinko/lib/printint.c index a11c34fe5..88f524059 100644 --- a/tool/plinko/lib/printint.c +++ b/tool/plinko/lib/printint.c @@ -29,7 +29,8 @@ int PrintInt(int fd, long x, int cols, char quot, char zero, int base, i = j = 0; y = x < 0 && issigned ? -x : x; do { - if (quot && j == 3) z[i++ & 31] = quot, j = 0; + if (quot && j == 3) + z[i++ & 31] = quot, j = 0; z[i++ & 31] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[y % base]; } while (++j, (y /= base)); k = i + (x < 0 && issigned); @@ -38,8 +39,10 @@ int PrintInt(int fd, long x, int cols, char quot, char zero, int base, } else { n = PrintIndent(fd, +cols - k); } - if (x < 0 && issigned) n += PrintChar(fd, L'-'); - while (i) n += PrintChar(fd, z[--i & 31]); + if (x < 0 && issigned) + n += PrintChar(fd, L'-'); + while (i) + n += PrintChar(fd, z[--i & 31]); PrintIndent(fd, -cols - n); return n; } diff --git a/tool/plinko/lib/printvars.c b/tool/plinko/lib/printvars.c index 66b73aa22..ddcd1d220 100644 --- a/tool/plinko/lib/printvars.c +++ b/tool/plinko/lib/printvars.c @@ -20,7 +20,8 @@ #include "tool/plinko/lib/print.h" int PrintArgs(int fd, int keys, int vals, int n) { - if (!keys) return n; + if (!keys) + return n; if (keys > 0) { if (!(vals < 0 && Car(vals) == kClosure)) { if (n) { @@ -46,6 +47,7 @@ int PrintArgs(int fd, int keys, int vals, int n) { } else { n += PrintArgs(fd, Car(keys), Car(vals), n); } - if (!Cdr(keys)) return n; + if (!Cdr(keys)) + return n; return PrintArgs(fd, Cdr(keys), Cdr(vals), n); } diff --git a/tool/plinko/lib/read.c b/tool/plinko/lib/read.c index 18a09db9d..04dd889a0 100644 --- a/tool/plinko/lib/read.c +++ b/tool/plinko/lib/read.c @@ -66,7 +66,8 @@ dontinstrument int ReadSpaces(int fd) { dontinstrument int ReadByte(int fd) { int c; - if ((c = g_buffer[fd][bp[fd]++] & 255)) return c; + if ((c = g_buffer[fd][bp[fd]++] & 255)) + return c; return ReadSpaces(fd); } @@ -77,7 +78,8 @@ dontinstrument int ReadChar(int fd) { if (dx != ';') { break; } else { - do b = ReadByte(fd); + do + b = ReadByte(fd); while ((b != '\n')); } } @@ -100,7 +102,8 @@ dontinstrument int ReadChar(int fd) { static int ReadListItem(int fd, int closer, int f(int)) { int x, y; if ((x = f(fd)) > 0) { - if (Get(x) == MAKE(closer, TERM)) return -0; + if (Get(x) == MAKE(closer, TERM)) + return -0; if (Get(x) == MAKE(L'.', TERM)) { x = f(fd); if ((y = ReadListItem(fd, closer, Read1))) { @@ -138,16 +141,20 @@ static void ConsumeComment(int fd) { int c, t = 1; for (;;) { c = ReadChar(fd); - if (c == '#' && dx == '|') ++t; - if (!t) return; - if (c == '|' && dx == '#') --t; + if (c == '#' && dx == '|') + ++t; + if (!t) + return; + if (c == '|' && dx == '#') + --t; } } static int ReadAtomRest(int fd, int x) { int y; ax = y = TERM; - if (x == L'\\') x = ReadChar(fd); + if (x == L'\\') + x = ReadChar(fd); if (!IsSpace(dx) && !IsParen(dx) && !IsMathAlnum(x) && !IsMathAlnum(dx)) { y = ReadAtomRest(fd, ReadChar(fd)); } @@ -157,7 +164,8 @@ static int ReadAtomRest(int fd, int x) { static int ReadAtom(int fd) { int a, s, x; x = ReadChar(fd); - if ((s = Desymbolize(x)) != -1) return s; + if ((s = Desymbolize(x)) != -1) + return s; a = ReadAtomRest(fd, x); if (LO(Get(a)) == L'T' && HI(Get(a)) == TERM) { a = 1; @@ -194,7 +202,8 @@ static int TokenizeComplicated(int fd) { static int Read2(int fd) { int r, l; - while (IsSpace((l = dx))) ReadChar(fd); + while (IsSpace((l = dx))) + ReadChar(fd); switch (dx) { case L'#': r = TokenizeComplicated(fd); @@ -263,13 +272,15 @@ static int ReadLambda(int fd, int n) { } else { q = List(q, r); } - if (!n && dx == L')') break; + if (!n && dx == L')') + break; } while (!IsSpace(dx)); return q; } static int Read1(int fd) { - while (IsSpace(dx)) ReadChar(fd); + while (IsSpace(dx)) + ReadChar(fd); // todo: fix horrible i/o if (dx == 0xCE && (g_buffer[fd][bp[fd]] & 255) == 0xbb) { return ReadLambda(fd, 0); diff --git a/tool/plinko/lib/symbolize.c b/tool/plinko/lib/symbolize.c index 96eb58995..07b247357 100644 --- a/tool/plinko/lib/symbolize.c +++ b/tool/plinko/lib/symbolize.c @@ -19,92 +19,139 @@ #include "tool/plinko/lib/plinko.h" pureconst int Symbolize(int x) { - if (literally) return -1; - if (x == TERM) return -1; + if (literally) + return -1; + if (x == TERM) + return -1; DCHECK_LT(x, TERM); switch (LO(Get(x))) { case L'A': - if (x == kAtom) return L'α'; - if (x == kAnd) return L'∧'; - if (x == kAppend) return L'║'; + if (x == kAtom) + return L'α'; + if (x == kAnd) + return L'∧'; + if (x == kAppend) + return L'║'; return -1; case L'B': - if (x == kBeta) return L'β'; - if (x == kBecause) return L'∵'; + if (x == kBeta) + return L'β'; + if (x == kBecause) + return L'∵'; return -1; case L'C': - if (x == kCar) return L'⍅'; - if (x == kCdr) return L'⍆'; - if (x == kClosure) return L'⅄'; - if (x == kCond) return L'ζ'; - if (x == kCons) return L'ℶ'; - if (x == kCmp) return L'≷'; - if (x == kCycle) return L'⟳'; + if (x == kCar) + return L'⍅'; + if (x == kCdr) + return L'⍆'; + if (x == kClosure) + return L'⅄'; + if (x == kCond) + return L'ζ'; + if (x == kCons) + return L'ℶ'; + if (x == kCmp) + return L'≷'; + if (x == kCycle) + return L'⟳'; return -1; case L'D': - if (x == kDefine) return L'≝'; - if (x == kDefmacro) return L'Ψ'; - if (x == kDefun) return L'Λ'; + if (x == kDefine) + return L'≝'; + if (x == kDefmacro) + return L'Ψ'; + if (x == kDefun) + return L'Λ'; return -1; case L'E': - if (x == kEq) return L'≡'; - if (x == kExpand) return L'ə'; + if (x == kEq) + return L'≡'; + if (x == kExpand) + return L'ə'; return -1; case L'F': - if (x == kFunction) return L'𝑓'; - if (x == kFork) return L'⋔'; + if (x == kFunction) + return L'𝑓'; + if (x == kFork) + return L'⋔'; return -1; case L'P': - if (x == kPartial) return L'∂'; + if (x == kPartial) + return L'∂'; return -1; case L'I': - if (x == kIff) return L'⟺'; - if (x == kImplies) return L'⟶'; - if (x == kIntegrate) return L'∫'; - if (x == kIntersection) return L'∩'; + if (x == kIff) + return L'⟺'; + if (x == kImplies) + return L'⟶'; + if (x == kIntegrate) + return L'∫'; + if (x == kIntersection) + return L'∩'; return -1; case L'L': - if (x == kLambda) return L'λ'; - if (x == kList) return L'ℒ'; + if (x == kLambda) + return L'λ'; + if (x == kList) + return L'ℒ'; return -1; case L'M': - if (x == kMacro) return L'ψ'; - if (x == kMember) return L'∊'; + if (x == kMacro) + return L'ψ'; + if (x == kMember) + return L'∊'; return -1; case L'N': - if (!x) return L'⊥'; - if (x == kNand) return L'⊼'; - if (x == kNor) return L'⊽'; - if (x == kNot) return L'¬'; + if (!x) + return L'⊥'; + if (x == kNand) + return L'⊼'; + if (x == kNor) + return L'⊽'; + if (x == kNot) + return L'¬'; return -1; case L'O': - if (x == kOr) return L'∨'; - if (x == kOrder) return L'⊙'; + if (x == kOr) + return L'∨'; + if (x == kOrder) + return L'⊙'; return -1; case L'Q': - if (x == kQuote) return L'Ω'; + if (x == kQuote) + return L'Ω'; return -1; case L'R': - if (x == kReverse) return L'Я'; + if (x == kReverse) + return L'Я'; return -1; case L'S': - if (x == kSqrt) return L'√'; - if (x == kSubset) return L'⊂'; - if (x == kSuperset) return L'⊃'; + if (x == kSqrt) + return L'√'; + if (x == kSubset) + return L'⊂'; + if (x == kSuperset) + return L'⊃'; return -1; case L'T': - if (x == 1) return L'⊤'; - if (x == kTherefore) return L'∴'; + if (x == 1) + return L'⊤'; + if (x == kTherefore) + return L'∴'; return -1; case L'U': - if (x == kUnion) return L'∪'; - if (x == kImpossible) return L'∅'; + if (x == kUnion) + return L'∪'; + if (x == kImpossible) + return L'∅'; return -1; case L'X': - if (x == kXor) return L'⊻'; + if (x == kXor) + return L'⊻'; return -1; case L'Y': - if (x == kYcombinator) return L'𝕐'; + if (x == kYcombinator) + return L'𝕐'; return -1; default: return -1; diff --git a/tool/plinko/lib/tree.c b/tool/plinko/lib/tree.c index 9466f5869..2ca833699 100644 --- a/tool/plinko/lib/tree.c +++ b/tool/plinko/lib/tree.c @@ -31,9 +31,12 @@ int Nod(int E, int L, int R, int C) { static void CheckTreeImpl(int N) { 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); + 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); if ((L = Lit(N))) { if ((p = Cmp(Key(Ent(L)), Key(Ent(N)))) != -1) { Error("Cmp(Key(L), Key(N)) != -1%n" @@ -65,7 +68,8 @@ static void CheckTreeImpl(int N) { static int CheckTree(int N) { #if DEBUG_TREE if (N) { - if (Red(N)) Error("tree root is red%n%T", N); + if (Red(N)) + Error("tree root is red%n%T", N); CheckTreeImpl(N); } #endif @@ -163,11 +167,15 @@ static int InsTree(int E, int N, int KEEP) { if (N) { P = Cmp(Key(E), Key(Ent(N))); if (P < 0) { - if ((L = InsTree(E, Lit(N), KEEP)) > 0) return L; // rethrow - if (L != Lit(N)) N = BalTree(Ent(N), L, Rit(N), Tail(N)); + if ((L = InsTree(E, Lit(N), KEEP)) > 0) + return L; // rethrow + if (L != Lit(N)) + N = BalTree(Ent(N), L, Rit(N), Tail(N)); } else if (P > 0) { - if ((R = InsTree(E, Rit(N), KEEP)) > 0) return R; // rethrow - if (R != Rit(N)) N = BalTree(Ent(N), Lit(N), R, Tail(N)); + if ((R = InsTree(E, Rit(N), KEEP)) > 0) + return R; // rethrow + if (R != Rit(N)) + N = BalTree(Ent(N), Lit(N), R, Tail(N)); } else if (KEEP < 0 || (!KEEP && !Equal(Val(E), Val(Ent(N))))) { N = Cons(Cons(E, Chl(N)), Red(N)); } else if (KEEP > 1) { diff --git a/tool/viz/ascii2utf8.c b/tool/viz/ascii2utf8.c index d895b7bf1..781aa5311 100644 --- a/tool/viz/ascii2utf8.c +++ b/tool/viz/ascii2utf8.c @@ -61,9 +61,11 @@ const wint_t kCombiningLowLine = L'\u0332'; const wint_t kCombiningDoubleMacronBelow = L'\u035f'; forceinline int PutChar(wint_t (*buf)[3], size_t *i, wint_t *cc, FILE *out) { - if (fputwc((*buf)[0], out) == -1) return -1; + if (fputwc((*buf)[0], out) == -1) + return -1; if (*cc != -1) { - if (fputwc(*cc, out) == -1) return -1; + if (fputwc(*cc, out) == -1) + return -1; *cc = -1; } (*buf)[0] = (*buf)[1]; @@ -77,7 +79,8 @@ int CombineAsciiMarks(FILE *in, FILE *out) { size_t i = 0; for (;;) { while (i < 3) { - if ((wc = fgetwc(in)) == -1) goto InputBreak; + if ((wc = fgetwc(in)) == -1) + goto InputBreak; buf[i++] = wc; } if (buf[1] == '\b' && cc == -1) { @@ -104,12 +107,14 @@ int CombineAsciiMarks(FILE *in, FILE *out) { } } if (i == 3) { - if (PutChar(&buf, &i, &cc, out) == -1) goto OutputBreak; + if (PutChar(&buf, &i, &cc, out) == -1) + goto OutputBreak; } } InputBreak: while (i) { - if (PutChar(&buf, &i, &cc, out) == -1) goto OutputBreak; + if (PutChar(&buf, &i, &cc, out) == -1) + goto OutputBreak; } OutputBreak: return (fclose(in) | fclose(out)) != -1 ? 0 : -1; diff --git a/tool/viz/basicidea.c b/tool/viz/basicidea.c index 9b0153f7b..053604a9f 100644 --- a/tool/viz/basicidea.c +++ b/tool/viz/basicidea.c @@ -37,9 +37,10 @@ #define SQR(X) ((X) * (X)) #define UNCUBE(x) x < 48 ? 0 : x < 115 ? 1 : (x - 35) / 40 -#define ORDIE(X) \ - do { \ - if (!(X)) perror(#X), exit(1); \ +#define ORDIE(X) \ + do { \ + if (!(X)) \ + perror(#X), exit(1); \ } while (0) int want24bit_; diff --git a/tool/viz/bd.c b/tool/viz/bd.c index bc5d21bbb..b37f506a4 100644 --- a/tool/viz/bd.c +++ b/tool/viz/bd.c @@ -58,10 +58,12 @@ int main(int argc, char *argv[]) { return 1; } for (b = o = 0;;) { - if (!(n = fread(R, 1, 16, f))) break; + if (!(n = fread(R, 1, 16, f))) + break; p = A, q = B; for (c = i = 0; i < n; ++i) { - if (i == 8) *p++ = ' '; + if (i == 8) + *p++ = ' '; *p++ = "0123456789abcdef"[(R[i] & 0xF0) >> 4]; *p++ = "0123456789abcdef"[(R[i] & 0x0F) >> 0]; *p++ = ' '; @@ -77,6 +79,7 @@ int main(int argc, char *argv[]) { } o += n; } - if (o) printf("%08x\n", o); + if (o) + printf("%08x\n", o); return !feof(f); } diff --git a/tool/viz/bin2asm.c b/tool/viz/bin2asm.c index f547c3821..37496fd93 100644 --- a/tool/viz/bin2asm.c +++ b/tool/viz/bin2asm.c @@ -33,7 +33,8 @@ int main(int argc, char *argv[]) { bzero(glyphs, sizeof(glyphs)); } glyphs[col] = kCp437[c]; - if (col) putchar(','); + if (col) + putchar(','); printf("0x%02x", c); if (++col == COLS) { col = 0; diff --git a/tool/viz/cpuid.c b/tool/viz/cpuid.c index e1eb63b4a..657296118 100644 --- a/tool/viz/cpuid.c +++ b/tool/viz/cpuid.c @@ -102,9 +102,12 @@ int main(int argc, char *argv[]) { if (KCPUIDS(16H, EAX)) { printf("\n"); - if ((x = KCPUIDS(16H, EAX) & 0x7fff)) decimal("frequency", x, "mhz"); - if ((x = KCPUIDS(16H, EBX) & 0x7fff)) decimal("turbo", x, "mhz"); - if ((x = KCPUIDS(16H, ECX) & 0x7fff)) decimal("bus", x, "mhz"); + if ((x = KCPUIDS(16H, EAX) & 0x7fff)) + decimal("frequency", x, "mhz"); + if ((x = KCPUIDS(16H, EBX) & 0x7fff)) + decimal("turbo", x, "mhz"); + if ((x = KCPUIDS(16H, ECX) & 0x7fff)) + decimal("bus", x, "mhz"); } if (X86_HAVE(HYPERVISOR)) { diff --git a/tool/viz/datauri.c b/tool/viz/datauri.c index 8f8c92d3f..38094da08 100644 --- a/tool/viz/datauri.c +++ b/tool/viz/datauri.c @@ -36,7 +36,8 @@ void PrintUsage(int rc, FILE *f) { void PrintUri(const char *path) { size_t n; void *img; - if (!(img = gc(xslurp(path, &n)))) exit(2); + if (!(img = gc(xslurp(path, &n)))) + exit(2); fputs("data:", stdout); fputs(FindContentType(path, -1), stdout); fputs(";base64,", stdout); diff --git a/tool/viz/derasterize.c b/tool/viz/derasterize.c index 8a0e1d829..484511c16 100644 --- a/tool/viz/derasterize.c +++ b/tool/viz/derasterize.c @@ -136,7 +136,8 @@ extern const char16_t kRunes[]; */ static char *tptoa(char *p, wchar_t x) { unsigned long w; - for (w = tpenc(x); w; w >>= 010) *p++ = w & 0xff; + for (w = tpenc(x); w; w >>= 010) + *p++ = w & 0xff; return p; } @@ -163,8 +164,10 @@ static float frgb2std(float x) { */ static void rgb2float(unsigned n, float *f, const unsigned char *u) { unsigned i; - for (i = 0; i < n; ++i) f[i] = u[i]; - for (i = 0; i < n; ++i) f[i] /= 255; + for (i = 0; i < n; ++i) + f[i] = u[i]; + for (i = 0; i < n; ++i) + f[i] /= 255; } /** @@ -172,9 +175,12 @@ static void rgb2float(unsigned n, float *f, const unsigned char *u) { */ static void float2rgb(unsigned n, unsigned char *u, float *f) { unsigned i; - for (i = 0; i < n; ++i) f[i] *= 256; - for (i = 0; i < n; ++i) f[i] = roundf(f[i]); - for (i = 0; i < n; ++i) u[i] = MAX(0, MIN(255, f[i])); + for (i = 0; i < n; ++i) + f[i] *= 256; + for (i = 0; i < n; ++i) + f[i] = roundf(f[i]); + for (i = 0; i < n; ++i) + u[i] = MAX(0, MIN(255, f[i])); } /** @@ -186,7 +192,8 @@ static void float2rgb(unsigned n, unsigned char *u, float *f) { static dontinline void rgb2lin(unsigned n, float *f, const unsigned char *u) { unsigned i; rgb2float(n, f, u); - for (i = 0; i < n; ++i) f[i] = frgb2lin(f[i]); + for (i = 0; i < n; ++i) + f[i] = frgb2lin(f[i]); } /** @@ -194,7 +201,8 @@ static dontinline void rgb2lin(unsigned n, float *f, const unsigned char *u) { */ static dontinline void rgb2std(unsigned n, unsigned char *u, float *f) { unsigned i; - for (i = 0; i < n; ++i) f[i] = frgb2std(f[i]); + for (i = 0; i < n; ++i) + f[i] = frgb2std(f[i]); float2rgb(n, u, f); } @@ -288,25 +296,31 @@ static unsigned combinecolors(unsigned char bf[1u << MC][2], /** * Computes distance between synthetic block and actual. */ -#define ADJUDICATE(SYMBOL, ARCH) \ - ARCH static float SYMBOL(unsigned b, unsigned f, unsigned g, \ - const float lb[CN][YS * XS]) { \ - unsigned i, k, gu; \ - float p[BN], q[BN], fu, bu, r; \ - bzero(q, sizeof(q)); \ - for (k = 0; k < CN; ++k) { \ - gu = kGlyphs[g]; \ - bu = lb[k][b]; \ - fu = lb[k][f]; \ - for (i = 0; i < BN; ++i) p[i] = (gu & (1u << i)) ? fu : bu; \ - for (i = 0; i < BN; ++i) p[i] -= lb[k][i]; \ - for (i = 0; i < BN; ++i) p[i] *= p[i]; \ - for (i = 0; i < BN; ++i) q[i] += p[i]; \ - } \ - r = 0; \ - for (i = 0; i < BN; ++i) q[i] = sqrtf(q[i]); \ - for (i = 0; i < BN; ++i) r += q[i]; \ - return r; \ +#define ADJUDICATE(SYMBOL, ARCH) \ + ARCH static float SYMBOL(unsigned b, unsigned f, unsigned g, \ + const float lb[CN][YS * XS]) { \ + unsigned i, k, gu; \ + float p[BN], q[BN], fu, bu, r; \ + bzero(q, sizeof(q)); \ + for (k = 0; k < CN; ++k) { \ + gu = kGlyphs[g]; \ + bu = lb[k][b]; \ + fu = lb[k][f]; \ + for (i = 0; i < BN; ++i) \ + p[i] = (gu & (1u << i)) ? fu : bu; \ + for (i = 0; i < BN; ++i) \ + p[i] -= lb[k][i]; \ + for (i = 0; i < BN; ++i) \ + p[i] *= p[i]; \ + for (i = 0; i < BN; ++i) \ + q[i] += p[i]; \ + } \ + r = 0; \ + for (i = 0; i < BN; ++i) \ + q[i] = sqrtf(q[i]); \ + for (i = 0; i < BN; ++i) \ + r += q[i]; \ + return r; \ } ADJUDICATE(adjudicate_avx2, _Microarchitecture("avx2,fma")) @@ -339,14 +353,20 @@ static float adjudicate(unsigned b, unsigned f, unsigned g, gu = kGlyphs[g]; bu = lb[k][b]; fu = lb[k][f]; - for (i = 0; i < BN; ++i) p[i] = (gu & (1u << i)) ? fu : bu; - for (i = 0; i < BN; ++i) p[i] -= lb[k][i]; - for (i = 0; i < BN; ++i) p[i] *= p[i]; - for (i = 0; i < BN; ++i) q[i] += p[i]; + for (i = 0; i < BN; ++i) + p[i] = (gu & (1u << i)) ? fu : bu; + for (i = 0; i < BN; ++i) + p[i] -= lb[k][i]; + for (i = 0; i < BN; ++i) + p[i] *= p[i]; + for (i = 0; i < BN; ++i) + q[i] += p[i]; } r = 0; - for (i = 0; i < BN; ++i) q[i] = sqrtf(q[i]); - for (i = 0; i < BN; ++i) r += q[i]; + for (i = 0; i < BN; ++i) + q[i] = sqrtf(q[i]); + for (i = 0; i < BN; ++i) + r += q[i]; return r; } @@ -376,7 +396,8 @@ static struct Cell derasterize(unsigned char block[CN][YS * XS]) { cell.fg[0] = block[0][f]; cell.fg[1] = block[1][f]; cell.fg[2] = block[2][f]; - if (!r) return cell; + if (!r) + return cell; } } } @@ -464,7 +485,8 @@ static int ReadAll(int fd, void *data, size_t size) { p = data; n = size; do { - if ((rc = read(fd, p, n)) == -1) return -1; + if ((rc = read(fd, p, n)) == -1) + return -1; got = rc; assert(got || !n); p += got; @@ -605,7 +627,8 @@ int main(int argc, char *argv[]) { size = y_ * YS * x_ * XS * CN; CHECK_NOTNULL((rgb = _mapanon(ROUNDUP(size, FRAMESIZE)))); for (i = optind; i < argc; ++i) { - if (!argv[i]) continue; + if (!argv[i]) + continue; if (m_) { LoadFileViaImageMagick(argv[i], y_, x_, rgb); } else { diff --git a/tool/viz/getglyph.c b/tool/viz/getglyph.c index 10dcad506..4a7d30f68 100644 --- a/tool/viz/getglyph.c +++ b/tool/viz/getglyph.c @@ -59,7 +59,8 @@ static char *Raster(int yn, int xn, unsigned char Y[yn][xn], int *dw) { int y, x, i, j, k, s, w, bi, bs; *dw = 0; for (y = 0; y < yn; y += 4) { - if (y) appendw(&r, '\n'); + if (y) + appendw(&r, '\n'); for (w = x = 0; x < xn; x += 4) { for (i = 0; i < 4; ++i) { for (j = 0; j < 4; ++j) { @@ -87,7 +88,8 @@ static char *Raster(int yn, int xn, unsigned char Y[yn][xn], int *dw) { appendw(&r, tpenc(kBlocks[bi].c)); ++w; } - if (w > *dw) *dw = w; + if (w > *dw) + *dw = w; } return r; } @@ -171,7 +173,8 @@ int main(int argc, char *argv[]) { strcmp(rasters[j], rasters[j - 1])) { isdifferent = true; } - if (dw > maxw) maxw = dw; + if (dw > maxw) + maxw = dw; } } free(bmap); @@ -189,7 +192,8 @@ int main(int argc, char *argv[]) { continue; } p = strchrnul(rasters[j], '\n'); - if (p - rasters[j]) gotsome = true; + if (p - rasters[j]) + gotsome = true; printf("%-*.*s ", maxw, p - rasters[j], rasters[j]); rasters[j] = *p ? p + 1 : p; } diff --git a/tool/viz/hwcap.c b/tool/viz/hwcap.c index b2123f07a..8885bc058 100644 --- a/tool/viz/hwcap.c +++ b/tool/viz/hwcap.c @@ -26,60 +26,111 @@ int main(int argc, char *argv[]) { long x = getauxval(AT_HWCAP); - if (x & HWCAP_FP) puts("HWCAP_FP"); - if (x & HWCAP_ASIMD) puts("HWCAP_ASIMD"); - if (x & HWCAP_EVTSTRM) puts("HWCAP_EVTSTRM"); - if (x & HWCAP_AES) puts("HWCAP_AES"); - if (x & HWCAP_PMULL) puts("HWCAP_PMULL"); - if (x & HWCAP_SHA1) puts("HWCAP_SHA1"); - if (x & HWCAP_SHA2) puts("HWCAP_SHA2"); - if (x & HWCAP_CRC32) puts("HWCAP_CRC32"); - if (x & HWCAP_ATOMICS) puts("HWCAP_ATOMICS"); - if (x & HWCAP_FPHP) puts("HWCAP_FPHP"); - if (x & HWCAP_ASIMDHP) puts("HWCAP_ASIMDHP"); - if (x & HWCAP_CPUID) puts("HWCAP_CPUID"); - if (x & HWCAP_ASIMDRDM) puts("HWCAP_ASIMDRDM"); - if (x & HWCAP_JSCVT) puts("HWCAP_JSCVT"); - if (x & HWCAP_FCMA) puts("HWCAP_FCMA"); - if (x & HWCAP_LRCPC) puts("HWCAP_LRCPC"); - if (x & HWCAP_DCPOP) puts("HWCAP_DCPOP"); - if (x & HWCAP_SHA3) puts("HWCAP_SHA3"); - if (x & HWCAP_SM3) puts("HWCAP_SM3"); - if (x & HWCAP_SM4) puts("HWCAP_SM4"); - if (x & HWCAP_ASIMDDP) puts("HWCAP_ASIMDDP"); - if (x & HWCAP_SHA512) puts("HWCAP_SHA512"); - if (x & HWCAP_SVE) puts("HWCAP_SVE"); - if (x & HWCAP_ASIMDFHM) puts("HWCAP_ASIMDFHM"); - if (x & HWCAP_DIT) puts("HWCAP_DIT"); - if (x & HWCAP_USCAT) puts("HWCAP_USCAT"); - if (x & HWCAP_ILRCPC) puts("HWCAP_ILRCPC"); - if (x & HWCAP_FLAGM) puts("HWCAP_FLAGM"); - if (x & HWCAP_SSBS) puts("HWCAP_SSBS"); - if (x & HWCAP_SB) puts("HWCAP_SB"); - if (x & HWCAP_PACA) puts("HWCAP_PACA"); - if (x & HWCAP_PACG) puts("HWCAP_PACG"); + if (x & HWCAP_FP) + puts("HWCAP_FP"); + if (x & HWCAP_ASIMD) + puts("HWCAP_ASIMD"); + if (x & HWCAP_EVTSTRM) + puts("HWCAP_EVTSTRM"); + if (x & HWCAP_AES) + puts("HWCAP_AES"); + if (x & HWCAP_PMULL) + puts("HWCAP_PMULL"); + if (x & HWCAP_SHA1) + puts("HWCAP_SHA1"); + if (x & HWCAP_SHA2) + puts("HWCAP_SHA2"); + if (x & HWCAP_CRC32) + puts("HWCAP_CRC32"); + if (x & HWCAP_ATOMICS) + puts("HWCAP_ATOMICS"); + if (x & HWCAP_FPHP) + puts("HWCAP_FPHP"); + if (x & HWCAP_ASIMDHP) + puts("HWCAP_ASIMDHP"); + if (x & HWCAP_CPUID) + puts("HWCAP_CPUID"); + if (x & HWCAP_ASIMDRDM) + puts("HWCAP_ASIMDRDM"); + if (x & HWCAP_JSCVT) + puts("HWCAP_JSCVT"); + if (x & HWCAP_FCMA) + puts("HWCAP_FCMA"); + if (x & HWCAP_LRCPC) + puts("HWCAP_LRCPC"); + if (x & HWCAP_DCPOP) + puts("HWCAP_DCPOP"); + if (x & HWCAP_SHA3) + puts("HWCAP_SHA3"); + if (x & HWCAP_SM3) + puts("HWCAP_SM3"); + if (x & HWCAP_SM4) + puts("HWCAP_SM4"); + if (x & HWCAP_ASIMDDP) + puts("HWCAP_ASIMDDP"); + if (x & HWCAP_SHA512) + puts("HWCAP_SHA512"); + if (x & HWCAP_SVE) + puts("HWCAP_SVE"); + if (x & HWCAP_ASIMDFHM) + puts("HWCAP_ASIMDFHM"); + if (x & HWCAP_DIT) + puts("HWCAP_DIT"); + if (x & HWCAP_USCAT) + puts("HWCAP_USCAT"); + if (x & HWCAP_ILRCPC) + puts("HWCAP_ILRCPC"); + if (x & HWCAP_FLAGM) + puts("HWCAP_FLAGM"); + if (x & HWCAP_SSBS) + puts("HWCAP_SSBS"); + if (x & HWCAP_SB) + puts("HWCAP_SB"); + if (x & HWCAP_PACA) + puts("HWCAP_PACA"); + if (x & HWCAP_PACG) + puts("HWCAP_PACG"); x = getauxval(AT_HWCAP2); - if (x & HWCAP2_DCPODP) puts("HWCAP2_DCPODP"); - if (x & HWCAP2_SVE2) puts("HWCAP2_SVE2"); - if (x & HWCAP2_SVEAES) puts("HWCAP2_SVEAES"); - if (x & HWCAP2_SVEPMULL) puts("HWCAP2_SVEPMULL"); - if (x & HWCAP2_SVEBITPERM) puts("HWCAP2_SVEBITPERM"); - if (x & HWCAP2_SVESHA3) puts("HWCAP2_SVESHA3"); - if (x & HWCAP2_SVESM4) puts("HWCAP2_SVESM4"); - if (x & HWCAP2_FLAGM2) puts("HWCAP2_FLAGM2"); - if (x & HWCAP2_FRINT) puts("HWCAP2_FRINT"); - if (x & HWCAP2_SVEI8MM) puts("HWCAP2_SVEI8MM"); - if (x & HWCAP2_SVEF32MM) puts("HWCAP2_SVEF32MM"); - if (x & HWCAP2_SVEF64MM) puts("HWCAP2_SVEF64MM"); - if (x & HWCAP2_SVEBF16) puts("HWCAP2_SVEBF16"); - if (x & HWCAP2_I8MM) puts("HWCAP2_I8MM"); - if (x & HWCAP2_BF16) puts("HWCAP2_BF16"); - if (x & HWCAP2_DGH) puts("HWCAP2_DGH"); - if (x & HWCAP2_RNG) puts("HWCAP2_RNG"); - if (x & HWCAP2_BTI) puts("HWCAP2_BTI"); - if (x & HWCAP2_MTE) puts("HWCAP2_MTE"); + if (x & HWCAP2_DCPODP) + puts("HWCAP2_DCPODP"); + if (x & HWCAP2_SVE2) + puts("HWCAP2_SVE2"); + if (x & HWCAP2_SVEAES) + puts("HWCAP2_SVEAES"); + if (x & HWCAP2_SVEPMULL) + puts("HWCAP2_SVEPMULL"); + if (x & HWCAP2_SVEBITPERM) + puts("HWCAP2_SVEBITPERM"); + if (x & HWCAP2_SVESHA3) + puts("HWCAP2_SVESHA3"); + if (x & HWCAP2_SVESM4) + puts("HWCAP2_SVESM4"); + if (x & HWCAP2_FLAGM2) + puts("HWCAP2_FLAGM2"); + if (x & HWCAP2_FRINT) + puts("HWCAP2_FRINT"); + if (x & HWCAP2_SVEI8MM) + puts("HWCAP2_SVEI8MM"); + if (x & HWCAP2_SVEF32MM) + puts("HWCAP2_SVEF32MM"); + if (x & HWCAP2_SVEF64MM) + puts("HWCAP2_SVEF64MM"); + if (x & HWCAP2_SVEBF16) + puts("HWCAP2_SVEBF16"); + if (x & HWCAP2_I8MM) + puts("HWCAP2_I8MM"); + if (x & HWCAP2_BF16) + puts("HWCAP2_BF16"); + if (x & HWCAP2_DGH) + puts("HWCAP2_DGH"); + if (x & HWCAP2_RNG) + puts("HWCAP2_RNG"); + if (x & HWCAP2_BTI) + puts("HWCAP2_BTI"); + if (x & HWCAP2_MTE) + puts("HWCAP2_MTE"); #endif /* __aarch64__ */ } diff --git a/tool/viz/img.c b/tool/viz/img.c index 99da68b44..888e622d8 100644 --- a/tool/viz/img.c +++ b/tool/viz/img.c @@ -46,8 +46,10 @@ void PrintImg(const char *path) { size_t n; int yn, xn, cn, w, h; void *img, *pix, *src; - if (!(img = gc(xslurp(path, &n)))) exit(2); - if (!(pix = gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3); + if (!(img = gc(xslurp(path, &n)))) + exit(2); + if (!(pix = gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) + exit(3); if (linktag) { printf("", path); } @@ -71,7 +73,8 @@ void PrintImg(const char *path) { } int main(int argc, char *argv[]) { - if (!NoDebug()) ShowCrashReports(); + if (!NoDebug()) + ShowCrashReports(); int i; while ((i = getopt(argc, argv, "?huas01234")) != -1) { switch (i) { diff --git a/tool/viz/lib/convoindex.c b/tool/viz/lib/convoindex.c index 97a8914e3..f21391f70 100644 --- a/tool/viz/lib/convoindex.c +++ b/tool/viz/lib/convoindex.c @@ -31,9 +31,12 @@ unsigned *convoindex(unsigned leftpad, unsigned n, unsigned rightpad) { unsigned i, j, *p; if ((p = malloc(sizeof(unsigned) * (leftpad + n + rightpad)))) { i = 0; - for (j = 0; j < leftpad; ++j) p[i++] = 0; - for (j = 0; j < n; ++j) p[i++] = j; - for (j = 0; j < rightpad; ++j) p[i++] = n - 1; + for (j = 0; j < leftpad; ++j) + p[i++] = 0; + for (j = 0; j < n; ++j) + p[i++] = j; + for (j = 0; j < rightpad; ++j) + p[i++] = n - 1; } return p; } diff --git a/tool/viz/lib/formatstringtable-assembly.c b/tool/viz/lib/formatstringtable-assembly.c index 267b50e3e..b126c60bc 100644 --- a/tool/viz/lib/formatstringtable-assembly.c +++ b/tool/viz/lib/formatstringtable-assembly.c @@ -112,7 +112,8 @@ void *FormatStringTableAsAssembly(long yn, long xn, const char *const T[yn][xn], EmitSection(yn, xn, w, GetArrayAlignment(yn, xn, w, align), emit, a); emit(name, a); emit(":", a); - if (strwidth(name, 0) >= 8) emit("\n", a); + if (strwidth(name, 0) >= 8) + emit("\n", a); FormatStringTable(yn, xn, T, emit, a, gc(xstrcat("\t.", storage, "\t")), ",", "\n"); emit("\t.endobj\t", a); diff --git a/tool/viz/lib/formatstringtable.c b/tool/viz/lib/formatstringtable.c index f3db79284..af74d3b3b 100644 --- a/tool/viz/lib/formatstringtable.c +++ b/tool/viz/lib/formatstringtable.c @@ -51,8 +51,10 @@ void *FormatStringTable(long yn, long xn, const char *const T[yn][xn], for (y = 0; y < yn; ++y) { emit(startrow, a); for (x = 0; x < xn; ++x) { - if (x) emit(comma, a); - for (n = w - strwidth(T[y][x], 0), i = 0; i < n; ++i) emit(" ", a); + if (x) + emit(comma, a); + for (n = w - strwidth(T[y][x], 0), i = 0; i < n; ++i) + emit(" ", a); emit(T[y][x], a); } emit(endrow, a); diff --git a/tool/viz/lib/sharpen.c b/tool/viz/lib/sharpen.c index 548298a37..55bd5cdd0 100644 --- a/tool/viz/lib/sharpen.c +++ b/tool/viz/lib/sharpen.c @@ -61,8 +61,10 @@ long sharpen(long cn, long yw, long xw, unsigned char p[cn][yw][xw], long yn, rc = enomem(); } free(ta); - if (ix) free(ix - 1); - if (iy) free(iy - 1); + if (ix) + free(ix - 1); + if (iy) + free(iy - 1); } else { rc = einval(); } diff --git a/tool/viz/lib/sobel.c b/tool/viz/lib/sobel.c index b3b43049f..bab9e5f71 100644 --- a/tool/viz/lib/sobel.c +++ b/tool/viz/lib/sobel.c @@ -40,8 +40,10 @@ forceinline void ConvolveGradient(unsigned yn, unsigned xn, tmp = _mapanon((size = ROUNDUP(sizeof(float) * 4 * xn * yn, FRAMESIZE))); for (y = 0; y < yn - KW + 1; ++y) { for (x = 0; x < xn - KW + 1; ++x) { - for (k = 0; k < 4; ++k) py[k] = 0; - for (k = 0; k < 4; ++k) px[k] = 0; + for (k = 0; k < 4; ++k) + py[k] = 0; + for (k = 0; k < 4; ++k) + px[k] = 0; for (i = 0; i < KW; ++i) { for (j = 0; j < KW; ++j) { for (k = 0; k < 4; ++k) { diff --git a/tool/viz/lib/stringbuilder.c b/tool/viz/lib/stringbuilder.c index 79c13c604..6f0771f52 100644 --- a/tool/viz/lib/stringbuilder.c +++ b/tool/viz/lib/stringbuilder.c @@ -26,7 +26,8 @@ static dontinline void StringBuilderGrow(size_t need, struct StringBuilder *sb) { size_t n2; n2 = MAX(16, sb->n); - while (sb->i + need > n2) n2 += n2 >> 1; + while (sb->i + need > n2) + n2 += n2 >> 1; sb->p = xrealloc(sb->p, n2); sb->n = n2; } @@ -39,7 +40,8 @@ int StringBuilderAppend(const char *s, struct StringBuilder *sb) { size_t size; CHECK_LE(sb->i, sb->n); size = strlen(s); - if (sb->i + size + 1 > sb->n) StringBuilderGrow(size + 1, sb); + if (sb->i + size + 1 > sb->n) + StringBuilderGrow(size + 1, sb); memcpy(sb->p + sb->i, s, size + 1); sb->i += size; return 0; diff --git a/tool/viz/lib/unsharp.c b/tool/viz/lib/unsharp.c index 2626f9b0b..1c1eb9cb4 100644 --- a/tool/viz/lib/unsharp.c +++ b/tool/viz/lib/unsharp.c @@ -66,7 +66,9 @@ long unsharp(long cn, long yw, long xw, unsigned char img[cn][yw][xw], long yn, rc = enomem(); } free(t); - if (ix) free(ix - 2); - if (iy) free(iy - 2); + if (ix) + free(ix - 2); + if (iy) + free(iy - 2); return rc; } diff --git a/tool/viz/lib/writetoframebuffer.c b/tool/viz/lib/writetoframebuffer.c index 6eb6c8cb2..f46d95387 100644 --- a/tool/viz/lib/writetoframebuffer.c +++ b/tool/viz/lib/writetoframebuffer.c @@ -27,11 +27,16 @@ void WriteToFrameBuffer(size_t dyn, size_t dxn, unsigned char dst[dyn][dxn][4], unsigned y, x, k, upix[4]; for (y = 0; y < yn; ++y) { for (x = 0; x < xn; ++x) { - for (k = 0; k < 4; ++k) fpix[k] = src[y][x][k]; - for (k = 0; k < 4; ++k) fpix[k] *= 255; - for (k = 0; k < 4; ++k) ipix[k] = fpix[k] + .5f; - for (k = 0; k < 4; ++k) upix[k] = MAX(0, ipix[k]); - for (k = 0; k < 4; ++k) upix[k] = MIN(255, upix[k]); + for (k = 0; k < 4; ++k) + fpix[k] = src[y][x][k]; + for (k = 0; k < 4; ++k) + fpix[k] *= 255; + for (k = 0; k < 4; ++k) + ipix[k] = fpix[k] + .5f; + for (k = 0; k < 4; ++k) + upix[k] = MAX(0, ipix[k]); + for (k = 0; k < 4; ++k) + upix[k] = MIN(255, upix[k]); dst[y][x][0] = upix[2]; dst[y][x][1] = upix[1]; dst[y][x][2] = upix[0]; diff --git a/tool/viz/lib/ycbcr2rgb3.c b/tool/viz/lib/ycbcr2rgb3.c index c038dd4a5..4e8e84b63 100644 --- a/tool/viz/lib/ycbcr2rgb3.c +++ b/tool/viz/lib/ycbcr2rgb3.c @@ -163,7 +163,8 @@ void YCbCrComputeCoefficients(int swing, double gamma, void YCbCrInit(struct YCbCr **ycbcr, bool yonly, int swing, double gamma, const double gamut[3], const double illuminant[3]) { int i; - if (!*ycbcr) *ycbcr = xcalloc(1, sizeof(struct YCbCr)); + if (!*ycbcr) + *ycbcr = xcalloc(1, sizeof(struct YCbCr)); (*ycbcr)->yonly = yonly; bzero((*ycbcr)->magnums, sizeof((*ycbcr)->magnums)); bzero((*ycbcr)->lighting, sizeof((*ycbcr)->lighting)); @@ -318,8 +319,10 @@ void YCbCr2RgbScaler(struct YCbCr *me, long dyn, long dxn, yox, pry, prx); YCbCrComputeSamplingSolution(&me->chroma, dyn, dxn, scyn, scxn, cry, crx, coy, cox, pry, prx); - if (pf8_) sharpen(1, yys, yxs, (void *)Y, yyn, yxn); - if (pf9_) unsharp(1, yys, yxs, (void *)Y, yyn, yxn); + if (pf8_) + sharpen(1, yys, yxs, (void *)Y, yyn, yxn); + if (pf9_) + unsharp(1, yys, yxs, (void *)Y, yyn, yxn); GyaradosUint8(yys, yxs, Y, yys, yxs, Y, dyn, dxn, syn, sxn, 0, 255, me->luma.cy, me->luma.cx, true); GyaradosUint8(cys, cxs, Cb, cys, cxs, Cb, dyn, dxn, scyn, scxn, 0, 255, diff --git a/tool/viz/life.c b/tool/viz/life.c index c01118719..a57ebbe6c 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -313,7 +313,8 @@ static void AppendData(char *data, unsigned len) { unsigned n; if (buffer.i + len + 1 > buffer.n) { n = MAX(buffer.i + len + 1, MAX(16, buffer.n + (buffer.n >> 1))); - if (!(p = realloc(buffer.p, n))) return; + if (!(p = realloc(buffer.p, n))) + return; buffer.p = p; buffer.n = n; } @@ -393,7 +394,8 @@ static void OnTurbo(void) { static void OnSlowmo(void) { --speed; - if (speed < 1) speed = 1; + if (speed < 1) + speed = 1; } static void SetZoom(long y, long x, int d) { @@ -417,15 +419,18 @@ static void OnUnzoom(long y, long x) { static void OnMouseLeftDrag(long y, long x) { int i; - if (y == save_y && x == save_x) return; + if (y == save_y && x == save_x) + return; save_y = y; save_x = x; y = top + (y << (zoom + !!zoom)); x = left + (x << zoom); y += _rand64() & ((1ul << (zoom + !!zoom)) - 1); x += _rand64() & ((1ul << zoom) - 1); - if (y < 0 || y >= byn) return; - if (x < 0 || x >= bxn) return; + if (y < 0 || y >= byn) + return; + if (x < 0 || x >= bxn) + return; if (erase) { Unset(y, x); } else { @@ -447,8 +452,10 @@ static void OnMouseLeftDown(long y, long x) { y = top + (y << (zoom + !!zoom)); x = left + (x << zoom); erase = false; - if (y < 0 || y >= byn) return; - if (x < 0 || x >= bxn) return; + if (y < 0 || y >= byn) + return; + if (x < 0 || x >= bxn) + return; if ((erase = Test(y, x))) { Unset(y, x); } else { @@ -472,7 +479,8 @@ static void OnMouseRightDrag(long y, long x) { long dy, dx, h, w; dy = (save_y - y) << zoom; dx = (save_x - x) << zoom; - if (zoom) dy <<= 1; + if (zoom) + dy <<= 1; if (natural) { dy = -dy; dx = -dx; @@ -494,7 +502,8 @@ static void *NewBoard(size_t *out_size) { p = _mapanon(n); mprotect(p, getauxval(AT_PAGESZ), 0); mprotect(p + k, n - k, 0); - if (out_size) *out_size = n; + if (out_size) + *out_size = n; return p + getauxval(AT_PAGESZ); } @@ -524,7 +533,8 @@ static void GenerateStatusLine(void) { static void OnHeader(void) { size_t n; - if (!buffer.i) return; + if (!buffer.i) + return; switch (buffer.p[0]) { case 'N': if (buffer.i > 2) { @@ -541,7 +551,8 @@ static void OnHeader(void) { static int ReadChar(FILE *f) { int c; ++column; - if ((c = fgetc(f)) == -1) return -1; + if ((c = fgetc(f)) == -1) + return -1; if (c == '\n') { ++line; column = 0; @@ -552,10 +563,12 @@ static int ReadChar(FILE *f) { static int GetChar(FILE *f) { int c; for (;;) { - if ((c = ReadChar(f)) == -1) return -1; + if ((c = ReadChar(f)) == -1) + return -1; if (c == '#' && column == 1) { for (;;) { - if ((c = ReadChar(f)) == -1) return -1; + if ((c = ReadChar(f)) == -1) + return -1; if (c == '\r') { continue; } else if (c == '\n') { @@ -575,30 +588,40 @@ static int LoadFile(const char *path) { long c, y, x, i, n, yn, xn, yo, xo; line = 0; f = fopen(path, "r"); - if (GetChar(f) != 'x') goto ReadError; - if (GetChar(f) != ' ') goto ReadError; - if (GetChar(f) != '=') goto ReadError; - if (GetChar(f) != ' ') goto ReadError; + if (GetChar(f) != 'x') + goto ReadError; + if (GetChar(f) != ' ') + goto ReadError; + if (GetChar(f) != '=') + goto ReadError; + if (GetChar(f) != ' ') + goto ReadError; xn = 0; for (;;) { - if ((c = GetChar(f)) == -1) goto ReadError; - if (!isdigit(c)) break; + if ((c = GetChar(f)) == -1) + goto ReadError; + if (!isdigit(c)) + break; xn *= 10; xn += c - '0'; } do { - if ((c = GetChar(f)) == -1) goto ReadError; + if ((c = GetChar(f)) == -1) + goto ReadError; } while (!isdigit(c)); yn = 0; do { yn *= 10; yn += c - '0'; - if ((c = GetChar(f)) == -1) goto ReadError; + if ((c = GetChar(f)) == -1) + goto ReadError; } while (isdigit(c)); while (c != '\n') { - if ((c = ReadChar(f)) == -1) goto ReadError; + if ((c = ReadChar(f)) == -1) + goto ReadError; } - if (yn > byn || xn > bxn) goto ReadError; + if (yn > byn || xn > bxn) + goto ReadError; SwapBoards(); bzero(board, (byn * bxn) >> 3); yo = byn / 2 - yn / 2; @@ -606,7 +629,8 @@ static int LoadFile(const char *path) { y = 0; x = 0; for (;;) { - if ((c = GetChar(f)) == -1) goto ReadError; + if ((c = GetChar(f)) == -1) + goto ReadError; if (c == '!') { break; } else if (isspace(c)) { @@ -615,8 +639,10 @@ static int LoadFile(const char *path) { if (isdigit(c)) { n = c - '0'; for (;;) { - if ((c = GetChar(f)) == -1) goto ReadError; - if (!isdigit(c)) break; + if ((c = GetChar(f)) == -1) + goto ReadError; + if (!isdigit(c)) + break; n *= 10; n += c - '0'; } @@ -624,12 +650,14 @@ static int LoadFile(const char *path) { n = 1; } if (c == '$') { - if (++y == yn) y = 0; + if (++y == yn) + y = 0; x = 0; } else if (c == 'b' || c == 'o') { for (i = 0; i < n; ++i) { if (x >= xn) { - if (++y == yn) y = 0; + if (++y == yn) + y = 0; x = 0; } if (c == 'o') { @@ -758,9 +786,11 @@ static void OnSigWinch(int sig) { static void OnMouse(char *p) { int e, x, y; e = strtol(p, &p, 10); - if (*p == ';') ++p; + if (*p == ';') + ++p; x = min(txn, max(1, strtol(p, &p, 10))) - 1; - if (*p == ';') ++p; + if (*p == ';') + ++p; y = min(tyn, max(1, strtol(p, &p, 10))) - 1; e |= (*p == 'm') << 2; switch (e) { @@ -847,7 +877,8 @@ static void ReadKeyboard(void) { char buf[32], *p = buf; bzero(buf, sizeof(buf)); if (readansi(0, buf, sizeof(buf)) == -1) { - if (errno == EINTR) return; + if (errno == EINTR) + return; exit(errno); } switch (*p++) { @@ -951,7 +982,8 @@ static int InvertXtermGreyscale(int x) { static int ByteToColor(int x) { uint8_t c; c = x / 256. * 24 + 232; - if (white) c = InvertXtermGreyscale(c); + if (white) + c = InvertXtermGreyscale(c); return c; } @@ -1095,7 +1127,8 @@ static bool HasPendingInput(void) { static bool ShouldDraw(void) { struct timespec now; static struct timespec next; - if (!isdragging) return true; + if (!isdragging) + return true; now = timespec_real(); if (timespec_cmp(now, next) > 0 && !HasPendingInput()) { next = timespec_add(now, timespec_frommicros(1. / 24 * 1e6)); @@ -1384,7 +1417,8 @@ static void Gui(void) { ╚────────────────────────────────────────────────────────────────────────────│*/ int main(int argc, char *argv[]) { - if (!NoDebug()) ShowCrashReports(); + if (!NoDebug()) + ShowCrashReports(); out = 1; speed = 1; tyn = right = 80; diff --git a/tool/viz/maxmind.c b/tool/viz/maxmind.c index e7e469b7a..823cf460a 100644 --- a/tool/viz/maxmind.c +++ b/tool/viz/maxmind.c @@ -123,7 +123,8 @@ int main(int argc, char *argv[]) { MMDB_open("/usr/local/share/maxmind/GeoLite2-ASN.mmdb", 0, asdb)); for (rc = 0, i = 1; i < argc; ++i) { if (PrintIpInfo(argv[i]) != -1) { - if (i + 1 < argc) printf("\n"); + if (i + 1 < argc) + printf("\n"); } else { fprintf(stderr, "NOT FOUND: %s\n", argv[i]); rc = 1; diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index 9ff4a2d3b..8c4eebf7c 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -343,7 +343,8 @@ static void PreventBufferbloat(void) { static bool HasPendingInput(void) { struct pollfd fds[1]; - if (IsWindows()) return true; /* XXX */ + if (IsWindows()) + return true; /* XXX */ fds[0].fd = 0; fds[0].events = POLLIN; fds[0].revents = 0; @@ -355,8 +356,10 @@ static int GetCurrentRange(void) { int i; if (ranges.i) { for (i = 0; i < ranges.i; ++i) { - if (offset < ranges.p[i].a) return MAX(0, i - 1); - if (offset < ranges.p[i].b) return i; + if (offset < ranges.p[i].a) + return MAX(0, i - 1); + if (offset < ranges.p[i].b) + return i; } return ranges.i - 1; } else { @@ -472,9 +475,11 @@ static void OnPrevEnd(void) { static void OnMouse(char *p) { int e, x, y; e = strtol(p, &p, 10); - if (*p == ';') ++p; + if (*p == ';') + ++p; x = min(txn, max(1, strtol(p, &p, 10))) - 1; - if (*p == ';') ++p; + if (*p == ';') + ++p; y = min(tyn, max(1, strtol(p, &p, 10))) - 1; e |= (*p == 'm') << 2; switch (e) { @@ -523,7 +528,8 @@ static void ReadKeyboard(void) { char buf[32], *p = buf; bzero(buf, sizeof(buf)); if (readansi(0, buf, sizeof(buf)) == -1) { - if (errno == EINTR) return; + if (errno == EINTR) + return; exit(errno); } switch (*p++) { @@ -698,8 +704,10 @@ static void LoadRanges(void) { range.b = 0; ranges.i = 0; for (;;) { - if ((n = read(fd, b, sizeof(b))) == -1) exit(1); - if (!n) break; + if ((n = read(fd, b, sizeof(b))) == -1) + exit(1); + if (!n) + break; for (i = 0; i < n; ++i) { switch (t) { case 0: @@ -807,7 +815,8 @@ static void Render(void) { for (i = 0, n = p - buffer; i < n; i += got) { got = 0; if ((rc = write(out, buffer + i, n - i)) == -1) { - if (errno == EINTR) continue; + if (errno == EINTR) + continue; exit(errno); } got = rc; @@ -828,7 +837,8 @@ static void Zoom(long have) { n = have >> zoom; i = n / txn; r = n % txn; - if (r) ++i; + if (r) + ++i; if (order == LINEAR) { for (; i < tyn; ++i) { canvas[txn * i] = '~'; @@ -877,7 +887,8 @@ static void MemZoom(void) { } if (ok && HasPendingInput()) { ReadKeyboard(); - if (!IsWindows()) continue; /* XXX */ + if (!IsWindows()) + continue; /* XXX */ } ok = true; if (pid) { @@ -953,7 +964,8 @@ static void GetOpts(int argc, char *argv[]) { } int main(int argc, char *argv[]) { - if (!NoDebug()) ShowCrashReports(); + if (!NoDebug()) + ShowCrashReports(); out = 1; GetOpts(argc, argv); Open(); diff --git a/tool/viz/printansi.c b/tool/viz/printansi.c index 733701d6b..dd9ebaf59 100644 --- a/tool/viz/printansi.c +++ b/tool/viz/printansi.c @@ -172,7 +172,8 @@ static void GetOpts(int *argc, char *argv[]) { } } if (optind == *argc) { - if (!g_flags.out) g_flags.out = "-"; + if (!g_flags.out) + g_flags.out = "-"; argv[(*argc)++] = "-"; } if (!g_flags.full && (!g_flags.width || !g_flags.width)) { @@ -269,7 +270,8 @@ struct Block { static void *Raster(long yn, long xn, unsigned char Y[yn][xn]) { long y, x, i, j, k, s, bi, bs; for (y = 0; y + 4 <= yn; y += 4) { - if (y) fputc('\n', stdout); + if (y) + fputc('\n', stdout); for (x = 0; x + 2 <= xn; x += 2) { bi = 0; bs = LONG_MAX; diff --git a/tool/viz/printimage.c b/tool/viz/printimage.c index fb2c5974a..8185fa120 100644 --- a/tool/viz/printimage.c +++ b/tool/viz/printimage.c @@ -228,7 +228,8 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn], unsigned char a[3], b[3]; didhalfy = false; for (y = y0; y < yn; y += dy) { - if (y) printf("\e[0m\n"); + if (y) + printf("\e[0m\n"); for (x = x0; x < xn; x += dx) { a[0] = RGB[0][y][x]; a[1] = RGB[1][y][x]; @@ -328,8 +329,10 @@ static void PrintImageSerious(long yn, long xn, unsigned char RGB[3][yn][xn], long y, x; struct TtyRgb bg = {0x12, 0x34, 0x56, 0}; struct TtyRgb fg = {0x12, 0x34, 0x56, 0}; - if (g_flags.unsharp) unsharp(3, yn, xn, RGB, yn, xn); - if (g_flags.dither) dither(yn, xn, RGB, yn, xn); + if (g_flags.unsharp) + unsharp(3, yn, xn, RGB, yn, xn); + if (g_flags.dither) + dither(yn, xn, RGB, yn, xn); if (yn && xn) { for (y = 0; y < tyn; ++y) { for (x = 0; x < txn; ++x) { @@ -396,8 +399,10 @@ void WithImageFile(const char *path, wyn = g_winsize.ws_row * 2; wxn = g_winsize.ws_col; if (g_flags.ignoreaspect) { - if (!dyn) dyn = wyn; - if (!dxn) dxn = wxn * (1 + !g_flags.half); + if (!dyn) + dyn = wyn; + if (!dxn) + dxn = wxn * (1 + !g_flags.half); } if (!dyn && !dxn) { if (sxn * wyn > syn * wxn) { @@ -439,7 +444,8 @@ int main(int argc, char *argv[]) { int i; ShowCrashReports(); GetOpts(&argc, argv); - if (optind == argc) PrintUsage(EXIT_SUCCESS, STDOUT_FILENO); + if (optind == argc) + PrintUsage(EXIT_SUCCESS, STDOUT_FILENO); stbi_set_unpremultiply_on_load(true); for (i = optind; i < argc; ++i) { WithImageFile(argv[i], ProcessImage); diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c index 7d9abbc43..a92ab375d 100644 --- a/tool/viz/printpeb.c +++ b/tool/viz/printpeb.c @@ -58,7 +58,8 @@ int NextBestThing(void) { posix_fadvise(fd, 0, 0, MADV_SEQUENTIAL); ssize_t wrote; while ((wrote = copyfd(fd, 1, -1)) != -1) { - if (wrote == 0) break; + if (wrote == 0) + break; } close(fd); return 0; @@ -139,11 +140,16 @@ void PrintSystemInfo(void) { } const char *ft2str(int ft) { - if (ft == kNtFileTypeUnknown) return "kNtFileTypeUnknown"; - if (ft == kNtFileTypeDisk) return "kNtFileTypeDisk"; - if (ft == kNtFileTypeChar) return "kNtFileTypeChar"; - if (ft == kNtFileTypePipe) return "kNtFileTypePipe"; - if (ft == kNtFileTypeRemote) return "kNtFileTypeRemote"; + if (ft == kNtFileTypeUnknown) + return "kNtFileTypeUnknown"; + if (ft == kNtFileTypeDisk) + return "kNtFileTypeDisk"; + if (ft == kNtFileTypeChar) + return "kNtFileTypeChar"; + if (ft == kNtFileTypePipe) + return "kNtFileTypePipe"; + if (ft == kNtFileTypeRemote) + return "kNtFileTypeRemote"; return "wut?"; } diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 19b2acd59..7d5c04127 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -529,8 +529,10 @@ static bool OpenSpeaker(void) { if (!once) { once = true; i = 0; - if (ffplay_) tryspeakerfns_[i++] = TryFfplay; - if (sox_) tryspeakerfns_[i++] = TrySox; + if (ffplay_) + tryspeakerfns_[i++] = TryFfplay; + if (sox_) + tryspeakerfns_[i++] = TrySox; } snprintf(fifopath_, sizeof(fifopath_), "%s%s.%d.%d.wav", __get_tmpdir(), firstnonnull(program_invocation_short_name, "unknown"), getpid(), @@ -589,7 +591,8 @@ static void DescribeAlgorithms(char *p) { break; case kTtyQuantAnsi: p = stpcpy(p, " aixterm ansi"); - if (istango_) p = stpcpy(p, " tango"); + if (istango_) + p = stpcpy(p, " tango"); break; default: break; @@ -609,7 +612,8 @@ static void DescribeAlgorithms(char *p) { } static char *StartRender(char *vt) { - if (!ttymode_) vt += sprintf(vt, "\r\n\r\n"); + if (!ttymode_) + vt += sprintf(vt, "\r\n\r\n"); if (fullclear_) { vt += sprintf(vt, "\e[0m\e[H\e[J"); fullclear_ = false; @@ -640,8 +644,10 @@ static bool HasAdjustments(void) { } static char *DescribeAdjustments(char *p) { - if (emboss_) p = stpcpy(p, " emboss"); - if (sobel_) p = stpcpy(p, " sobel"); + if (emboss_) + p = stpcpy(p, " emboss"); + if (sobel_) + p = stpcpy(p, " sobel"); switch (sharp_) { case kSharpSharp: p = stpcpy(p, " sharp"); @@ -662,21 +668,36 @@ static char *DescribeAdjustments(char *p) { default: break; } - if (IsNonZeroFloat(hue_)) p += sprintf(p, " hue%+.2f", hue_); - if (IsNonZeroFloat(sat_)) p += sprintf(p, " sat%+.2f", sat_); - if (IsNonZeroFloat(lit_)) p += sprintf(p, " lit%+.2f", lit_); - if (pf1_) p = stpcpy(p, " PF1"); - if (pf2_) p = stpcpy(p, " PF2"); - if (pf3_) p = stpcpy(p, " PF3"); - if (pf4_) p = stpcpy(p, " PF4"); - if (pf5_) p = stpcpy(p, " PF5"); - if (pf6_) p = stpcpy(p, " PF6"); - if (pf7_) p = stpcpy(p, " PF7"); - if (pf8_) p = stpcpy(p, " PF8"); - if (pf9_) p = stpcpy(p, " PF9"); - if (pf10_) p = stpcpy(p, " PF10"); - if (pf11_) p = stpcpy(p, " PF11"); - if (pf12_) p = stpcpy(p, " PF12"); + if (IsNonZeroFloat(hue_)) + p += sprintf(p, " hue%+.2f", hue_); + if (IsNonZeroFloat(sat_)) + p += sprintf(p, " sat%+.2f", sat_); + if (IsNonZeroFloat(lit_)) + p += sprintf(p, " lit%+.2f", lit_); + if (pf1_) + p = stpcpy(p, " PF1"); + if (pf2_) + p = stpcpy(p, " PF2"); + if (pf3_) + p = stpcpy(p, " PF3"); + if (pf4_) + p = stpcpy(p, " PF4"); + if (pf5_) + p = stpcpy(p, " PF5"); + if (pf6_) + p = stpcpy(p, " PF6"); + if (pf7_) + p = stpcpy(p, " PF7"); + if (pf8_) + p = stpcpy(p, " PF8"); + if (pf9_) + p = stpcpy(p, " PF9"); + if (pf10_) + p = stpcpy(p, " PF10"); + if (pf11_) + p = stpcpy(p, " PF11"); + if (pf12_) + p = stpcpy(p, " PF12"); *p++ = ' '; *p++ = '\0'; return p; @@ -782,8 +803,10 @@ static void TranscodeVideo(plm_frame_t *pf) { TIMEIT(t1, { pary_ = 2; - if (pf1_) pary_ = 1.; - if (pf2_) pary_ = (266 / 64.) * (900 / 1600.); + if (pf1_) + pary_ = 1.; + if (pf2_) + pary_ = (266 / 64.) * (900 / 1600.); pary_ *= plm_get_pixel_aspect_ratio(plm_); YCbCr2RgbScale(g2_->yn, g2_->xn, g2_->b, pf->y.height, pf->y.width, (void *)pf->y.data, pf->cr.height, pf->cr.width, @@ -805,8 +828,10 @@ static void TranscodeVideo(plm_frame_t *pf) { default: break; } - if (sobel_) sobel(g2_); - if (emboss_) emboss(g2_); + if (sobel_) + sobel(g2_); + if (emboss_) + emboss(g2_); switch (sharp_) { case kSharpSharp: sharpen(3, g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn); @@ -932,7 +957,8 @@ static void WriteVideo(void) { } static void RefreshDisplay(void) { - if (f1_ && f1_->n) f1_->i = 0; + if (f1_ && f1_->n) + f1_->i = 0; DimensionDisplay(); resized_ = false; historyclear_ = true; @@ -1287,8 +1313,10 @@ static void PerformBestEffortIo(void) { DEBUGF("poll() toto=%d [grace=%,ldns]", toto, timespec_tonanos(GetGraceTime())); if (toto) { - if (fds[0].revents & (POLLIN | POLLERR)) ReadKeyboard(); - if (fds[1].revents & (POLLOUT | POLLERR)) WriteVideo(); + if (fds[0].revents & (POLLIN | POLLERR)) + ReadKeyboard(); + if (fds[1].revents & (POLLOUT | POLLERR)) + WriteVideo(); } } else if (errno == EINTR) { DEBUGF("poll() → EINTR"); @@ -1300,7 +1328,8 @@ static void PerformBestEffortIo(void) { static void RestoreTty(void) { DrainVideo(); - if (ttymode_) ttysend(outfd_, "\r\n\e[J"); + if (ttymode_) + ttysend(outfd_, "\r\n\e[J"); ttymode_ = false; ttyraw(-1); } @@ -1352,7 +1381,8 @@ static void PrintVideo(void) { static bool AskUserYesOrNoQuestion(const char *prompt) { char c; - if (yes_ || !ttymode_) return true; + if (yes_ || !ttymode_) + return true; ttysend(outfd_, "\r\e[K"); ttysend(outfd_, prompt); ttysend(outfd_, " [yn] "); @@ -1411,8 +1441,10 @@ static void GetOpts(int argc, char *argv[]) { } static void OnExit(void) { - if (playpid_) kill(playpid_, SIGTERM), sched_yield(); - if (plm_) plm_destroy(plm_), plm_ = NULL; + if (playpid_) + kill(playpid_, SIGTERM), sched_yield(); + if (plm_) + plm_destroy(plm_), plm_ = NULL; YCbCrFree(&ycbcr_); RestoreTty(); ttyidentclear(&ti_); @@ -1561,8 +1593,10 @@ int main(int argc, char *argv[]) { ShowCrashReports(); fullclear_ = true; GetOpts(argc, argv); - if (!tuned_) PickDefaults(); - if (optind == argc) PrintUsage(EX_USAGE, STDERR_FILENO); + if (!tuned_) + PickDefaults(); + if (optind == argc) + PrintUsage(EX_USAGE, STDERR_FILENO); patharg_ = argv[optind]; s = commandvenv("SOX", "sox"); sox_ = s ? strdup(s) : 0; @@ -1584,7 +1618,8 @@ int main(int argc, char *argv[]) { xsigaction(SIGWINCH, OnResize, 0, 0, NULL); xsigaction(SIGCHLD, OnSigChld, 0, 0, NULL); xsigaction(SIGPIPE, OnSigPipe, 0, 0, NULL); - if (ttyraw(kTtyLfToCrLf) != -1) ttymode_ = true; + if (ttyraw(kTtyLfToCrLf) != -1) + ttymode_ = true; __cxa_atexit((void *)OnExit, NULL, NULL); __log_file = fopen(logpath_, "a"); if (ischardev(infd_) && ischardev(outfd_)) { @@ -1593,10 +1628,12 @@ int main(int argc, char *argv[]) { infd_ = -1; } /* CHECK_NE(-1, fcntl(outfd_, F_SETFL, O_NONBLOCK)); */ - if (CanPlayAudio()) MakeLatencyLittleLessBad(); + if (CanPlayAudio()) + MakeLatencyLittleLessBad(); TryToOpenFrameBuffer(); RenounceSpecialPrivileges(); - if (t2 > t1) longjmp(jb_, 1); + if (t2 > t1) + longjmp(jb_, 1); OpenVideo(); DimensionDisplay(); starttime_ = timespec_real(); diff --git a/tool/viz/rlimit.c b/tool/viz/rlimit.c index 0cedfe648..3d3b84eb5 100644 --- a/tool/viz/rlimit.c +++ b/tool/viz/rlimit.c @@ -31,7 +31,8 @@ static void SetLimit(int resource, uint64_t soft, uint64_t hard) { struct rlimit old; struct rlimit lim = {soft, hard}; - if (resource == 127) return; + if (resource == 127) + return; if (setrlimit(resource, &lim) == -1) { if (!getrlimit(resource, &old)) { lim.rlim_max = MIN(hard, old.rlim_max); diff --git a/tool/viz/setitimer_accuracy.c b/tool/viz/setitimer_accuracy.c index be88a7a2a..227413514 100644 --- a/tool/viz/setitimer_accuracy.c +++ b/tool/viz/setitimer_accuracy.c @@ -57,5 +57,6 @@ int main(int argc, char *argv[]) { expect = timeval_add(start, interval); signal(SIGALRM, OnTick); setitimer(ITIMER_REAL, &(struct itimerval){interval, interval}, 0); - for (;;) pause(); + for (;;) + pause(); } diff --git a/tool/viz/tailf.c b/tool/viz/tailf.c index 91a4ef46f..054feed29 100644 --- a/tool/viz/tailf.c +++ b/tool/viz/tailf.c @@ -63,28 +63,37 @@ int main(int argc, char *argv[]) { ssize_t n; size_t i, j; bool chopped; - if (argc < 2) return 1; - if ((fd = open(argv[1], O_RDONLY)) == -1) return 2; - if (fstat(fd, &st) == -1) return 3; + if (argc < 2) + return 1; + if ((fd = open(argv[1], O_RDONLY)) == -1) + return 2; + if (fstat(fd, &st) == -1) + return 3; n = st.st_size - MIN(st.st_size, sizeof(buf)); - if ((n = pread(fd, buf, sizeof(buf), n)) == -1) return 4; + if ((n = pread(fd, buf, sizeof(buf), n)) == -1) + return 4; for (p = buf + n, i = 0; i < 10; ++i) { p = firstnonnull(memrchr(buf, '\n', p - buf), buf); } chopped = false; - if (buf + n - p) ++p; + if (buf + n - p) + ++p; i = st.st_size - (buf + n - p); atexit(OnExit); HideCursor(); xsigaction(SIGINT, OnInt, 0, 0, 0); xsigaction(SIGTERM, OnInt, 0, 0, 0); while (!exited) { - if (fstat(fd, &st) == -1) return 5; - if (i > st.st_size) i = 0; + if (fstat(fd, &st) == -1) + return 5; + if (i > st.st_size) + i = 0; for (; i < st.st_size; i += n) { - if ((n = pread(fd, buf, sizeof(buf), i)) == -1) return 6; + if ((n = pread(fd, buf, sizeof(buf), i)) == -1) + return 6; j = n; - while (j && (buf[j - 1] == '\n' || buf[j - 1] == '\r')) --j; + while (j && (buf[j - 1] == '\n' || buf[j - 1] == '\r')) + --j; if (j) { if (chopped) { WriteString("\r\n"); diff --git a/tool/viz/virtualquery.c b/tool/viz/virtualquery.c index f17f9eb38..7168c7202 100644 --- a/tool/viz/virtualquery.c +++ b/tool/viz/virtualquery.c @@ -66,7 +66,8 @@ int main(int argc, char *argv[]) { "RegionSize", "State", "Type", "AllocationProtect", "Protect"); for (p = 0;; p = (char *)mi.BaseAddress + mi.RegionSize) { bzero(&mi, sizeof(mi)); - if (!VirtualQuery(p, &mi, sizeof(mi))) break; + if (!VirtualQuery(p, &mi, sizeof(mi))) + break; sizefmt(b[0], mi.RegionSize, 1024); printf("%.12lx %.12lx %10s %16s %16s %32s %32s\n", mi.AllocationBase, mi.BaseAddress, b[0], DescribeNtMemState(b[1], mi.State),