From 0d748ad58e1063dd1f8560f18a0c75293b9415b7 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Fri, 1 Sep 2023 20:49:13 -0700 Subject: [PATCH] Fix warnings This change fixes Cosmopolitan so it has fewer opinions about compiler warnings. The whole repository had to be cleaned up to be buildable in -Werror -Wall mode. This lets us benefit from things like strict const checking. Some actual bugs might have been caught too. --- dsp/core/c121.h | 2 +- dsp/core/c121s.h | 2 +- dsp/core/sad16x8n.c | 3 +- dsp/mpeg/idct.c | 2 +- dsp/mpeg/mpeg1.c | 12 +- dsp/scale/cdecimate2xuint8x8.c | 4 +- dsp/scale/gyarados.c | 7 +- dsp/tty/rgb2ansi.c | 4 +- dsp/tty/ttyraster.c | 5 +- dsp/tty/write.c | 2 +- examples/cosh.c | 6 +- examples/crashreport.c | 1 + examples/crashreport2.c | 1 - examples/datauri.c | 3 +- examples/defer-statements.c | 4 +- examples/forkexec.c | 1 - examples/forkexecwait.c | 2 - examples/gettimeofday.c | 2 +- examples/greenbean.c | 3 +- examples/hangman.c | 5 +- examples/hellolua.c | 2 +- examples/img.c | 6 +- examples/kilo.c | 10 +- examples/nanosleep_test.c | 2 +- examples/nc.c | 2 +- examples/nesemu1.cc | 9 +- examples/panels.c | 2 +- examples/script.c | 4 +- examples/unbourne.c | 4 +- examples/wall.c | 1 - libc/calls/__sig2.c | 3 +- libc/calls/clock_gettime-mono.c | 1 - libc/calls/closefrom.c | 1 + libc/calls/copy_file_range.c | 2 +- libc/calls/execl.c | 4 +- libc/calls/execle.c | 4 +- libc/calls/execlp.c | 4 +- libc/calls/execve-sysv.c | 8 +- libc/calls/execve.c | 3 +- libc/calls/fadvise.c | 2 +- libc/calls/fcntl-nt.c | 10 +- libc/calls/fexecve.c | 11 +- libc/calls/fstatat-sysv.c | 1 - libc/calls/fstatfs-nt.c | 1 - libc/calls/getloadavg-nt.c | 1 - libc/calls/gettimeofday.c | 1 - libc/calls/groups.internal.h | 2 +- libc/calls/ioctl.c | 8 +- libc/calls/isatty.c | 1 - libc/calls/mkfifo.c | 2 +- libc/calls/mkntcmdline.c | 1 - libc/calls/mkntenvblock.c | 13 +- libc/calls/mount.c | 2 +- libc/calls/mremap-sysv.greg.c | 2 +- libc/calls/now.c | 1 - libc/calls/onntconsoleevent.c | 3 +- libc/calls/openpty.c | 4 +- libc/calls/pledge-linux.c | 18 +-- libc/calls/pwrite.c | 2 +- libc/calls/raise.c | 2 +- libc/calls/read-nt.c | 2 - libc/calls/readlinkat-nt.c | 2 +- libc/calls/readv-serial.c | 2 +- libc/calls/reservefd.c | 1 - libc/calls/sigenter-xnu.c | 2 +- libc/calls/sigprocmask.c | 3 +- libc/calls/sigsuspend.c | 3 +- libc/calls/sigtimedwait.c | 3 +- libc/calls/splice.c | 2 +- libc/calls/struct/filter.internal.h | 2 +- libc/calls/struct/iovec.internal.h | 2 +- libc/calls/struct/termios.internal.h | 2 +- libc/calls/struct/timespec.h | 2 +- libc/calls/struct/timeval.h | 2 +- libc/calls/struct/winsize.internal.h | 2 +- libc/calls/tcsetattr-nt.c | 1 - libc/calls/ttyname_r.c | 1 - libc/calls/uname.c | 1 - libc/calls/unveil.c | 4 +- libc/calls/utimensat-xnu.c | 1 - libc/calls/wait4-nt.c | 4 +- libc/calls/wincrash.c | 2 +- libc/calls/winstdin1.c | 1 - libc/calls/write.c | 4 +- libc/dns/getaddrinfo.c | 1 - libc/dns/getnameinfo.c | 2 +- libc/elf/elf.h | 7 +- libc/elf/findelfsectionbyname.c | 2 +- libc/elf/getelfsectionaddress.c | 2 +- libc/elf/getelfsectionname.c | 4 +- libc/elf/getelfstring.c | 10 +- libc/elf/getelfstringtable.c | 2 +- libc/elf/tinyelf.internal.h | 9 +- libc/fmt/fmt.h | 2 +- libc/fmt/leb128.h | 2 +- libc/fmt/magnumstrs.internal.h | 8 +- libc/fmt/strtol.c | 6 +- libc/fmt/strtol.internal.h | 4 +- libc/fmt/strtoul.c | 10 +- libc/fmt/unuleb64.c | 2 +- libc/fmt/wcstol.c | 6 +- libc/fmt/wcstoul.c | 10 +- libc/integral/c.inc | 104 ++---------- libc/intrin/asan.c | 13 +- libc/intrin/countbits.c | 5 +- libc/intrin/cp.c | 4 +- libc/intrin/createfile.c | 15 +- libc/intrin/describeflags.c | 6 +- libc/intrin/describeflags.internal.h | 6 +- libc/intrin/describeframe.c | 1 - libc/intrin/describemagnums.c | 5 +- libc/intrin/describepollfds.c | 3 +- libc/intrin/describesicode.c | 4 +- libc/intrin/describesockoptname.c | 4 +- libc/intrin/describetermios.c | 4 +- libc/intrin/describewinsize.c | 7 +- libc/intrin/ffs.c | 3 +- libc/intrin/g_fds.c | 4 +- libc/intrin/kprintf.greg.c | 22 ++- libc/intrin/memchr.c | 4 +- libc/intrin/memmove.c | 2 +- libc/intrin/memrchr.c | 2 +- libc/intrin/mman.greg.c | 4 +- libc/intrin/printmemoryintervals.c | 2 +- libc/intrin/pthread_key_delete.c | 1 - libc/intrin/pthread_mutex_lock.c | 2 +- libc/intrin/pthread_mutex_trylock.c | 2 +- libc/intrin/pthread_mutex_unlock.c | 2 +- libc/intrin/pthread_setspecific.c | 2 +- libc/intrin/sigcountset.c | 2 +- libc/intrin/stracef.greg.c | 2 +- libc/intrin/strchr.c | 3 +- libc/intrin/strchrnul.c | 3 +- libc/intrin/strcmp.c | 2 +- libc/intrin/strerror.c | 2 +- libc/intrin/strerror_wr.greg.c | 7 +- libc/intrin/strsignal.c | 2 +- libc/intrin/strsignal_r.c | 6 +- libc/intrin/unsetenv.c | 3 +- libc/intrin/virtualprotect.c | 1 - libc/intrin/winerr.greg.c | 2 +- libc/log/addr2linepath.c | 2 +- libc/log/attachdebugger.c | 24 +-- libc/log/backtrace2.c | 7 +- libc/log/backtrace3.c | 2 +- libc/log/checkfail.c | 1 - libc/log/gdbexec.c | 8 +- libc/log/getcallername.c | 1 - libc/log/libfatal.internal.h | 3 +- libc/log/log.h | 1 - libc/log/memsummary.c | 22 +-- libc/log/oncrash_amd64.c | 3 +- libc/log/oncrash_arm64.c | 11 +- libc/log/printwindowsmemory.c | 1 - libc/log/vflogf.c | 2 - libc/log/watch.c | 1 - libc/mem/critbit0_emplace.c | 2 +- libc/mem/gc.c | 1 - libc/nt/createfile.h | 4 +- libc/nt/memory.h | 4 +- libc/nt/nt/file.h | 2 +- libc/nt/struct/objectattributes.h | 2 +- libc/nt/synchronization.h | 2 +- libc/runtime/clone.c | 4 +- libc/runtime/cocmd.c | 11 +- libc/runtime/cosmo2.c | 11 +- libc/runtime/efimain.greg.c | 7 +- libc/runtime/enable_tls.c | 4 +- libc/runtime/fork-nt.c | 13 +- libc/runtime/fork.c | 1 + libc/runtime/ftracer.c | 7 +- libc/runtime/getdosenviron.c | 5 +- libc/runtime/getinterpreterexecutablename.c | 2 - libc/runtime/getlogin.c | 2 +- libc/runtime/getsymboltable.c | 5 +- libc/runtime/interceptflag.greg.c | 2 +- libc/runtime/internal.h | 1 - libc/runtime/mmap.c | 6 +- libc/runtime/munmap.c | 8 +- libc/runtime/printargs.c | 13 +- libc/runtime/set_tls.c | 3 +- libc/runtime/sysconf.c | 1 - libc/runtime/winmain.greg.c | 2 +- libc/runtime/zipos-get.c | 3 +- libc/runtime/zipos-open.c | 2 +- libc/sock/accept-nt.c | 2 +- libc/sock/inet_ntop.c | 2 +- libc/sock/inet_pton.c | 2 +- libc/sock/kntwsadata.c | 2 +- libc/sock/nointernet.c | 1 - libc/sock/pselect.c | 4 +- libc/sock/recv.c | 2 +- libc/sock/send.c | 4 +- libc/sock/sendfile.c | 1 - libc/sock/sendto.c | 6 +- libc/sock/setsockopt-nt.c | 4 +- libc/sock/sockdebug.c | 1 - libc/sock/socketpair-nt.c | 2 +- libc/sock/syslog.c | 3 +- libc/sock/wsablock.c | 2 +- libc/stdio/ctermid.c | 2 +- libc/stdio/dirstream.c | 8 +- libc/stdio/dprintf.h | 2 +- libc/stdio/fmemopen.c | 1 - libc/stdio/fmt.c | 8 +- libc/stdio/fseek_unlocked.c | 1 - libc/stdio/ftell.c | 1 - libc/stdio/fwrite_unlocked.c | 2 +- libc/stdio/iconv.c | 6 +- libc/stdio/popen.c | 9 +- libc/stdio/posix_spawn.internal.h | 2 +- libc/stdio/posix_spawn_file_actions.c | 5 +- libc/stdio/puts.c | 22 +-- .../getsicodename.c => stdio/puts_unlocked.c} | 26 ++- libc/stdio/rngset.c | 2 +- libc/stdio/stdio.h | 1 + libc/stdio/system.c | 2 +- libc/stdio/vcscanf.c | 1 - libc/stdio/vdprintf.c | 2 +- libc/str/bcmp.c | 9 +- libc/str/c16rtomb.c | 2 +- libc/str/dosdatetimetounix.c | 2 +- libc/str/getzipcdircomment.c | 2 +- libc/str/getzipeocd.c | 9 +- libc/str/isutf8.c | 2 +- libc/str/iswlower.c | 1 - libc/str/iswupper.c | 1 - libc/str/lz4cpy.c | 3 +- libc/str/lz4len.c | 5 +- libc/str/mbrtowc.c | 2 +- libc/str/mbsrtowcs.c | 6 +- libc/str/mbtowc.c | 6 +- libc/str/memmem.c | 7 +- libc/str/memrchr16.c | 4 +- libc/str/rawmemchr.c | 10 +- libc/str/setlocale.c | 6 +- libc/str/str.h | 64 ++++---- libc/str/strcasecmp.c | 2 +- libc/str/strcasestr.c | 7 +- libc/str/strstr.c | 7 +- libc/str/thompike.h | 2 +- libc/str/tprecode8to16.c | 2 +- libc/str/wcschr.c | 2 +- libc/str/wcschrnul.c | 4 +- libc/str/wmemrchr.c | 4 +- libc/testlib/benchrunner.c | 1 - libc/testlib/comborunner.c | 5 +- libc/testlib/ezbench.h | 3 + libc/testlib/fixturerunner.c | 2 +- libc/testlib/quota.c | 1 - libc/testlib/showerror.c | 1 - libc/testlib/testlib.h | 9 +- libc/testlib/testmain.c | 2 - libc/testlib/testrunner.c | 3 +- libc/thread/makecontext.c | 1 - libc/thread/mktls.c | 2 +- libc/thread/pthread_atfork.c | 3 +- libc/thread/pthread_cancel.c | 1 - libc/thread/pthread_create.c | 3 - libc/thread/pthread_ungarbage.c | 1 - libc/thread/sem_open.c | 8 +- libc/thread/sem_timedwait.c | 1 - libc/thread/thread.h | 11 +- libc/thread/{tls2.h => tls2.internal.h} | 2 +- libc/thread/wait0.c | 2 +- libc/thread/wait0.internal.h | 3 +- libc/tinymath/acos.c | 2 +- libc/tinymath/asin.c | 2 +- libc/tinymath/ceil.c | 2 +- libc/tinymath/feval.internal.h | 3 + libc/tinymath/floor.c | 2 +- libc/tinymath/fma.c | 10 +- libc/vga/tty-graph.inc | 2 +- libc/vga/tty.greg.c | 6 +- libc/x/utf16to32.c | 2 - libc/x/utf16to8.c | 2 +- libc/x/utf8to32.c | 1 - libc/x/xasprintf.h | 2 +- libc/x/xbarf.c | 2 +- libc/x/xbasename.c | 7 +- libc/x/xdirname.c | 7 +- libc/x/xhomedir.c | 1 - libc/x/xslurp.c | 2 +- libc/x/xstrmul.c | 2 +- libc/zip.internal.h | 2 +- net/finger/describesyn.c | 2 +- net/finger/fingersyn.c | 2 +- net/http/decodelatin1.c | 2 +- net/http/encodelatin1.c | 2 +- net/http/escapeurl.c | 2 +- net/http/foldheader.c | 2 +- net/http/http.h | 2 +- net/http/indentlines.c | 2 +- net/http/isnocompressext.c | 2 +- net/http/parsehttpdatetime.c | 4 +- net/http/parseurl.c | 6 +- net/http/tokenbucket.c | 4 +- net/https/formatx509name.c | 2 +- net/https/https.h | 2 +- net/https/initializekey.c | 4 +- net/https/initializerng.c | 2 +- net/https/sslcache.c | 2 +- net/turfwar/blackholed.c | 14 +- net/turfwar/turfwar.c | 4 +- test/dsp/core/alaw_test.c | 3 +- test/dsp/scale/magikarp_test.c | 1 - test/dsp/tty/windex_test.c | 131 --------------- test/libc/calls/access_test.c | 1 - test/libc/calls/clock_gettime_test.c | 2 +- test/libc/calls/commandv_test.c | 1 - test/libc/calls/execve_test.c | 6 +- test/libc/calls/ioctl_test.c | 1 - test/libc/calls/lock2_test.c | 3 - test/libc/calls/mkdir_test.c | 2 +- test/libc/calls/pledge_test.c | 7 +- test/libc/calls/poll_test.c | 1 + test/libc/calls/raise_race_test.c | 2 +- test/libc/calls/readlinkat_test.c | 3 +- test/libc/calls/reservefd_test.c | 16 -- test/libc/calls/sched_getaffinity_test.c | 4 +- test/libc/calls/setrlimit_test.c | 8 +- test/libc/calls/sigprocmask_test.c | 2 - test/libc/calls/timespec_test.c | 1 - test/libc/calls/tkill_test.c | 2 +- test/libc/dns/parsehoststxt_test.c | 2 +- test/libc/dns/parseresolvconf_test.c | 2 +- test/libc/dns/resolvehoststxt_test.c | 4 +- test/libc/fmt/formathex64_test.c | 2 +- test/libc/intrin/kprintf_test.c | 4 +- test/libc/intrin/memmove_test.c | 13 +- test/libc/intrin/memset_test.c | 5 +- test/libc/intrin/pthread_atfork_test.c | 1 - test/libc/intrin/pthread_mutex_lock_test.c | 8 - test/libc/intrin/rand64_test.c | 6 +- test/libc/intrin/strchr_test.c | 8 +- test/libc/intrin/strcmp_test.c | 4 +- test/libc/mem/malloc_test.c | 7 +- test/libc/mem/sortedints_test.c | 3 + test/libc/nexgen32e/gclongjmp_test.c | 2 - test/libc/nexgen32e/memset_test.c | 4 +- test/libc/runtime/daemon_test.c | 3 +- test/libc/runtime/fork_test.c | 1 - test/libc/runtime/mmap_test.c | 10 +- test/libc/runtime/mprotect_test.c | 17 +- test/libc/sock/nonblock_test.c | 4 - test/libc/sock/recvfrom_test.c | 2 - test/libc/sock/sendfile_test.c | 4 +- test/libc/sock/sendrecvmsg_test.c | 4 +- test/libc/sock/socket_test.c | 7 +- test/libc/sock/unix_test.c | 4 +- test/libc/stdio/fgetln_test.c | 1 - test/libc/stdio/getdelim_test.c | 5 +- test/libc/stdio/getentropy_test.c | 2 +- test/libc/stdio/getrandom_test.c | 8 +- test/libc/stdio/mt19937_test.c | 62 ------- test/libc/stdio/posix_spawn_test.c | 8 +- test/libc/stdio/sprintf_s_test.c | 2 - test/libc/stdio/vappendf_test.c | 1 - test/libc/str/memcasecmp_test.c | 6 - test/libc/str/memcpy_test.c | 24 --- test/libc/str/memmem_test.c | 4 +- test/libc/str/strcasestr_test.c | 3 +- test/libc/str/strstr_test.c | 3 +- test/libc/str/wcwidth_test.c | 3 +- test/libc/thread/pthread_cancel_test.c | 4 +- test/libc/thread/pthread_create_test.c | 3 +- test/libc/thread/pthread_detach_test.c | 1 - test/libc/thread/sem_timedwait_test.c | 18 +-- test/libc/tinymath/sincos_test.c | 6 +- test/net/http/isacceptablehost_test.c | 2 - test/net/http/parseurl_test.c | 2 - test/net/https/mbedtls_test.c | 36 ++--- test/tool/build/lib/javadown_test.c | 6 +- test/tool/plinko/plinko_test.c | 1 - third_party/bzip2/bzip2.mk | 1 + third_party/chibicc/as.c | 34 ++-- third_party/chibicc/asm.c | 2 +- third_party/chibicc/chibicc.c | 2 +- third_party/chibicc/chibicc.h | 6 +- third_party/chibicc/codegen.c | 9 +- third_party/chibicc/dox1.c | 1 - third_party/chibicc/dox2.c | 3 +- third_party/chibicc/parse.c | 1 - third_party/compiler_rt/divtc3.c | 3 + third_party/compiler_rt/multc3.c | 3 + third_party/ctags/flex.c | 1 + third_party/ctags/jscript.c | 2 + third_party/ctags/sql.c | 1 + third_party/dlmalloc/init.inc | 2 +- third_party/double-conversion/wrapper.cc | 4 +- third_party/gdtoa/gdtoa_fltrnds.inc | 3 +- third_party/gdtoa/misc.c | 1 - third_party/gdtoa/strtord.c | 3 +- third_party/gdtoa/strtordd.c | 3 +- third_party/gdtoa/strtorf.c | 3 +- third_party/gdtoa/strtorx.c | 3 +- third_party/ggml/ggml.c | 12 +- third_party/ggml/llama.cc | 2 +- third_party/ggml/main.cc | 3 +- third_party/libcxx/__config | 5 +- third_party/linenoise/linenoise.c | 53 +++--- third_party/lua/cosmo.h | 2 +- third_party/lua/lrepl.c | 6 +- third_party/lua/lua.main.c | 3 - third_party/lua/luaencodejsondata.c | 2 +- third_party/lua/luaencodeluadata.c | 7 +- third_party/lua/luaencodeurl.c | 29 ++-- third_party/lua/luapushheader.c | 2 +- third_party/lua/lunix.c | 41 +++-- third_party/make/getopt.c | 4 +- third_party/make/job.c | 26 +-- third_party/make/main.c | 3 + third_party/make/read.c | 4 +- third_party/make/remake.c | 1 + third_party/mbedtls/aesni.c | 1 - third_party/mbedtls/base64.c | 4 +- third_party/mbedtls/bigmul.c | 11 +- third_party/mbedtls/bignum.c | 6 +- third_party/mbedtls/bignum_internal.h | 8 +- third_party/mbedtls/bigshift.c | 4 +- third_party/mbedtls/ecdh_everest.c | 3 +- third_party/mbedtls/ecp.c | 6 +- third_party/mbedtls/ecp256.c | 2 +- third_party/mbedtls/ecp384.c | 10 +- third_party/mbedtls/ecpshl.c | 24 +-- third_party/mbedtls/everest.c | 2 +- third_party/mbedtls/gcm.c | 3 +- third_party/mbedtls/karatsuba.c | 13 +- third_party/mbedtls/san.c | 7 +- third_party/mbedtls/secp256r1.c | 7 +- third_party/mbedtls/secp384r1.c | 1 + third_party/mbedtls/sha1.c | 2 +- third_party/mbedtls/shiftright-avx.c | 4 +- third_party/mbedtls/ssl_msg.c | 2 - third_party/mbedtls/ssl_tls.c | 2 +- third_party/mbedtls/test/lib.c | 4 +- third_party/mbedtls/test/secp384r1_test.c | 8 - third_party/mbedtls/test/test_suite_aes.cbc.c | 2 + third_party/mbedtls/test/test_suite_aes.cfb.c | 2 + third_party/mbedtls/test/test_suite_aes.ecb.c | 2 + third_party/mbedtls/test/test_suite_aes.ofb.c | 2 + .../mbedtls/test/test_suite_aes.rest.c | 2 + third_party/mbedtls/test/test_suite_aes.xts.c | 2 + third_party/musl/glob.c | 8 +- third_party/musl/rand48.c | 4 +- third_party/musl/tempnam.c | 4 +- third_party/nsync/futex.c | 9 +- third_party/nsync/futex.internal.h | 2 +- third_party/nsync/mu_semaphore_futex.c | 4 +- third_party/nsync/mu_semaphore_gcd.c | 1 + third_party/python/Include/datetime.h | 1 + .../python/Modules/_decimal/docstrings.h | 3 + third_party/python/Modules/_hashmbedtls.c | 10 +- third_party/python/Modules/_testcapimodule.c | 3 + .../python/Modules/cjkcodecs/cjkcodecs.h | 3 + third_party/python/Modules/main.c | 2 + third_party/python/Modules/socketmodule.c | 3 +- third_party/python/Modules/timemodule.c | 1 - third_party/python/Modules/tlsmodule.c | 5 +- .../python/Modules/unicodedata_getcode.c | 2 +- third_party/python/Objects/descrobject.c | 5 +- third_party/python/Objects/object.c | 1 + third_party/python/Objects/structseq.c | 3 +- third_party/python/Python/ceval.c | 6 + third_party/python/Python/cosmomodule.c | 9 +- third_party/python/Python/fatality.c | 1 - third_party/python/Python/import.c | 5 +- third_party/python/Python/initimport.c | 1 - third_party/python/Python/pylifecycle.c | 7 +- third_party/python/Python/random.c | 5 +- third_party/python/Python/sysmodule.c | 35 ---- third_party/python/launch.c | 2 +- third_party/python/pycomp.c | 3 +- third_party/python/pyobj.c | 7 +- third_party/python/runpythonmodule.c | 11 +- third_party/quickjs/bigint.c | 1 + third_party/quickjs/map.c | 1 + third_party/quickjs/quickjs.c | 10 +- third_party/quickjs/str.c | 8 +- third_party/radpajama/main-redpajama-chat.cc | 9 +- third_party/sqlite3/sqlite3session.c | 1 + third_party/stb/stb_image_write_png.c | 13 +- third_party/tidy/language.c | 2 +- third_party/tidy/parser.c | 1 + third_party/tidy/tmbstr.c | 2 +- third_party/unzip/fileio.c | 2 - third_party/unzip/unix.c | 1 + third_party/unzip/unzip.c | 2 +- third_party/unzip/unzip.mk | 1 + third_party/xed/x86ild.greg.c | 3 +- third_party/zip/fileio.c | 7 +- third_party/zip/zip.mk | 1 + third_party/zip/zipup.c | 6 +- third_party/zlib/zutil.c | 2 + tool/args/args.c | 2 +- tool/build/apelink.c | 10 +- tool/build/ar.c | 2 +- tool/build/assimilate.c | 8 +- tool/build/bigmul.c | 4 +- tool/build/chmod.c | 2 +- tool/build/compile.c | 15 +- tool/build/dso/sandbox.c | 2 +- tool/build/elf2pe.c | 4 +- tool/build/fastdiff.c | 3 +- tool/build/fixupobj.c | 14 +- tool/build/gzip.c | 2 +- tool/build/lib/asmdown.c | 4 +- tool/build/lib/buffer.c | 3 +- tool/build/lib/buffer.h | 2 +- tool/build/lib/demangle.c | 4 +- tool/build/lib/eztls.c | 6 +- tool/build/lib/getargs.c | 2 +- tool/build/lib/interner.c | 2 +- tool/build/lib/javadown.c | 6 +- tool/build/lib/panel.c | 1 - tool/build/lz4toasm.c | 6 +- tool/build/march-native.c | 2 +- tool/build/mkdeps.c | 7 +- tool/build/mv.c | 2 +- tool/build/objbincopy.c | 3 +- tool/build/package.c | 14 +- tool/build/pledge.c | 2 - tool/build/rollup.c | 2 +- tool/build/runit.c | 8 +- tool/build/runitd.c | 14 +- tool/build/unbundle.c | 2 +- tool/build/zipcopy.c | 3 +- tool/build/zipobj.c | 3 +- tool/decode/ar.c | 2 +- tool/decode/elf.c | 7 +- tool/decode/lib/flagger.c | 6 +- tool/decode/macho.c | 6 +- tool/decode/pe2.c | 20 ++- tool/decode/zip.c | 4 +- tool/lambda/bru2bin.c | 6 +- tool/lambda/lam2bin.c | 6 +- tool/lambda/lib/debug.c | 3 +- tool/net/fetch.inc | 20 ++- tool/net/lfuncs.c | 49 +++--- tool/net/lsqlite3.c | 18 +-- tool/net/redbean.c | 153 ++++++++---------- tool/net/wb.c | 8 +- tool/plinko/lib/bind.c | 2 +- tool/plinko/lib/cons.c | 5 +- tool/plinko/lib/dispatchycombine.c | 2 +- tool/plinko/lib/enclose.c | 2 - tool/plinko/lib/gc.c | 4 +- tool/plinko/lib/isdelegate.c | 1 - tool/plinko/lib/isycombinator.c | 1 - tool/plinko/lib/plan.c | 6 +- tool/plinko/lib/plinko.c | 22 +-- tool/plinko/lib/prettyprint.c | 2 +- tool/plinko/lib/printf.c | 4 +- tool/plinko/lib/read.c | 9 +- tool/plinko/lib/trace.c | 9 +- tool/plinko/lib/trace.h | 1 - tool/plinko/lib/tree.c | 8 +- tool/viz/deathstar.c | 1 - tool/viz/derasterize.c | 9 +- tool/viz/fontspace.c | 6 +- tool/viz/getglyph.c | 1 - tool/viz/lib/bilinearscale.c | 4 +- tool/viz/lib/dither.c | 5 +- tool/viz/lib/formatmatrix-double.c | 5 +- tool/viz/lib/ycbcr2rgb3.c | 6 +- tool/viz/life.c | 4 +- tool/viz/memzoom.c | 1 - tool/viz/printansi.c | 2 +- tool/viz/printimage.c | 10 +- tool/viz/printpeb.c | 2 +- tool/viz/printvideo.c | 10 +- 571 files changed, 1306 insertions(+), 1888 deletions(-) rename libc/{log/getsicodename.c => stdio/puts_unlocked.c} (75%) rename libc/thread/{tls2.h => tls2.internal.h} (95%) delete mode 100644 test/dsp/tty/windex_test.c diff --git a/dsp/core/c121.h b/dsp/core/c121.h index c03f9e038..d7b09314b 100644 --- a/dsp/core/c121.h +++ b/dsp/core/c121.h @@ -5,7 +5,7 @@ COSMOPOLITAN_C_START_ __funline unsigned char C121(unsigned char al, unsigned char bl, unsigned char cl) { - unsigned short ax, bx; + unsigned short ax; ax = al; ax += bl; ax += bl; diff --git a/dsp/core/c121s.h b/dsp/core/c121s.h index 0af3cbc7a..46e01c682 100644 --- a/dsp/core/c121s.h +++ b/dsp/core/c121s.h @@ -3,7 +3,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) __funline signed char C121S(signed char al, signed char bl, signed char cl) { - short ax, bx; + short ax; ax = al; ax += bl; ax += bl; diff --git a/dsp/core/sad16x8n.c b/dsp/core/sad16x8n.c index b01b73b04..e141d249b 100644 --- a/dsp/core/sad16x8n.c +++ b/dsp/core/sad16x8n.c @@ -31,13 +31,14 @@ * @param y needs to be 16-byte aligned */ void sad16x8n(size_t n, short x[n][8], const short y[n][8]) { - size_t i, j; + size_t i; for (i = 0; i < n; ++i) { #ifdef __x86_64__ *(__m128i *)x[i] = _mm_adds_epi16(*(__m128i *)x[i], *(__m128i *)y[i]); #elif defined(__aarch64__) *(int16x4_t *)x[i] = vqadd_s16(*(int16x4_t *)x[i], *(int16x4_t *)y[i]); #else + size_t j; for (j = 0; j < 8; ++j) { x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX); } diff --git a/dsp/mpeg/idct.c b/dsp/mpeg/idct.c index f8c3858d0..7bb420c46 100644 --- a/dsp/mpeg/idct.c +++ b/dsp/mpeg/idct.c @@ -41,7 +41,7 @@ asm(".include \"libc/disclaimer.inc\""); * @note discovered by Nasir Ahmed */ void plm_video_idct(int block[8][8]) { - int i, j, t1, t2, m0; + int i, t1, t2, m0; int b1, b3, b4, b6, b7; int y3, y4, y5, y6, y7; int x0, x1, x2, x3, x4; diff --git a/dsp/mpeg/mpeg1.c b/dsp/mpeg/mpeg1.c index 19692f2c6..1822c6432 100644 --- a/dsp/mpeg/mpeg1.c +++ b/dsp/mpeg/mpeg1.c @@ -1105,12 +1105,12 @@ plm_video_t *plm_video_create_with_buffer(plm_buffer_t *buffer, static textstartup void plm_video_init(void) { PLM_VIDEO_MACROBLOCK_TYPE[0] = NULL; - PLM_VIDEO_MACROBLOCK_TYPE[1] = PLM_VIDEO_MACROBLOCK_TYPE_INTRA; - PLM_VIDEO_MACROBLOCK_TYPE[2] = PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE, - PLM_VIDEO_MACROBLOCK_TYPE[3] = PLM_VIDEO_MACROBLOCK_TYPE_B; - PLM_VIDEO_DCT_SIZE[0] = PLM_VIDEO_DCT_SIZE_LUMINANCE; - PLM_VIDEO_DCT_SIZE[1] = PLM_VIDEO_DCT_SIZE_CHROMINANCE; - PLM_VIDEO_DCT_SIZE[2] = PLM_VIDEO_DCT_SIZE_CHROMINANCE; + PLM_VIDEO_MACROBLOCK_TYPE[1] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_INTRA; + PLM_VIDEO_MACROBLOCK_TYPE[2] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE; + PLM_VIDEO_MACROBLOCK_TYPE[3] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_B; + PLM_VIDEO_DCT_SIZE[0] = (void *)PLM_VIDEO_DCT_SIZE_LUMINANCE; + PLM_VIDEO_DCT_SIZE[1] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE; + PLM_VIDEO_DCT_SIZE[2] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE; } const void *const plm_video_init_ctor[] initarray = {plm_video_init}; diff --git a/dsp/scale/cdecimate2xuint8x8.c b/dsp/scale/cdecimate2xuint8x8.c index a6bcc4bf4..6851b3d10 100644 --- a/dsp/scale/cdecimate2xuint8x8.c +++ b/dsp/scale/cdecimate2xuint8x8.c @@ -55,10 +55,10 @@ void *cDecimate2xUint8x8(unsigned long n, unsigned char A[n], K[4], K[5], K[4], K[5], K[4], K[5], K[4], K[5]}; signed char kMadd4[16] = {K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7]}; - unsigned char in1[16], in2[16], in3[16], in4[32]; unsigned char bv0[16], bv1[16], bv2[16], bv3[16]; + unsigned char in1[16], in2[16], in3[16]; short wv0[8], wv1[8], wv2[8], wv3[8]; - unsigned long i, j, v, w, o; + unsigned long i, j, w; if (n >= STRIDE) { i = 0; w = (n + RATIO / 2) / RATIO; diff --git a/dsp/scale/gyarados.c b/dsp/scale/gyarados.c index 5bd815d11..e227484d9 100644 --- a/dsp/scale/gyarados.c +++ b/dsp/scale/gyarados.c @@ -82,7 +82,6 @@ static bool IsNormalized(int n, double A[n]) { } void FreeSamplingSolution(struct SamplingSolution *ss) { - long i; if (ss) { free(ss->indices); free(ss->weights); @@ -93,7 +92,7 @@ void FreeSamplingSolution(struct SamplingSolution *ss) { struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar, double off, double par) { double *fweights; - double sum, hw, w, x, f; + double sum, hw, x, f; short *weights, *indices; struct SamplingSolution *res; long j, i, k, n, min, max, s, N[6]; @@ -151,8 +150,8 @@ static void GyaradosImpl(long dyw, long dxw, int dst[dyw][dxw], long syw, const short fyi[dyn][yfn], const short fyw[dyn][yfn], const short fxi[dxn][xfn], const short fxw[dxn][xfn], bool sharpen) { - long i, j; - int eax, dy, dx, sy, sx; + long i; + int eax, dy, dx, sx; for (sx = 0; sx < sxn; ++sx) { for (dy = 0; dy < dyn; ++dy) { for (eax = i = 0; i < yfn; ++i) { diff --git a/dsp/tty/rgb2ansi.c b/dsp/tty/rgb2ansi.c index 51b321eab..3f3e37bd2 100644 --- a/dsp/tty/rgb2ansi.c +++ b/dsp/tty/rgb2ansi.c @@ -98,8 +98,8 @@ static int uncube(int x) { } static textstartup void rgb2ansi_init(void) { - uint8_t c, y; - uint32_t i, j; + uint8_t c; + uint32_t i; memcpy(g_ansi2rgb_, &kCgaPalette, sizeof(kCgaPalette)); for (i = 16; i < 232; ++i) { g_ansi2rgb_[i].r = kXtermCube[((i - 020) / 044) % 06]; diff --git a/dsp/tty/ttyraster.c b/dsp/tty/ttyraster.c index 7466efc63..ada628d85 100644 --- a/dsp/tty/ttyraster.c +++ b/dsp/tty/ttyraster.c @@ -609,7 +609,7 @@ static struct Pick PickBlockUnicodeAnsi(struct TtyRgb tl, struct TtyRgb tr, struct TtyRgb tr2 = GetQuant(tr); struct TtyRgb bl2 = GetQuant(bl); struct TtyRgb br2 = GetQuant(br); - unsigned i, p1, p2; + unsigned p1, p2; uint16_t picks1[96] forcealign(32); uint16_t picks2[32] forcealign(32); memset(picks1, 0x79, sizeof(picks1)); @@ -646,7 +646,7 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr, struct TtyRgb tr2 = GetQuant(tr); struct TtyRgb bl2 = GetQuant(bl); struct TtyRgb br2 = GetQuant(br); - unsigned i, p1, p2; + unsigned p1, p2; uint16_t picks1[32] forcealign(32); uint16_t picks2[32] forcealign(32); memset(picks1, 0x79, sizeof(picks1)); @@ -660,7 +660,6 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr, static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr, struct TtyRgb bl, struct TtyRgb br) { - unsigned i; uint16_t picks[32] forcealign(32); memset(picks, 0x79, sizeof(picks)); PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br); diff --git a/dsp/tty/write.c b/dsp/tty/write.c index 26e31c122..e07a5cf8d 100644 --- a/dsp/tty/write.c +++ b/dsp/tty/write.c @@ -38,8 +38,8 @@ * @return 0 on success, or -1 w/ errno */ ssize_t ttywrite(int fd, const void *data, size_t size) { - char *p; ssize_t rc; + const char *p; size_t wrote, n; p = data; n = size; diff --git a/examples/cosh.c b/examples/cosh.c index e079977b6..b88c599fb 100644 --- a/examples/cosh.c +++ b/examples/cosh.c @@ -93,10 +93,8 @@ static void CompleteFilename(const char *p, const char *q, const char *b, } 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; + for (b = p, q = (p += strlen(p)); p > b; --p) { if (!isalnum(p[-1]) && (p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' && p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) { @@ -143,8 +141,8 @@ int main(int argc, char *argv[]) { char *prog, path[PATH_MAX]; sigset_t chldmask, savemask; int stdoutflags, stderrflags; + int n, rc, ws, child, killcount; const char *stdoutpath, *stderrpath; - int n, rc, ws, pid, child, killcount; struct sigaction sa, saveint, savequit; char *p, *line, **args, *arg, *start, *state, prompt[1024]; linenoiseSetFreeHintsCallback(free); diff --git a/examples/crashreport.c b/examples/crashreport.c index 788832098..6c3d8a6ba 100644 --- a/examples/crashreport.c +++ b/examples/crashreport.c @@ -36,6 +36,7 @@ dontubsan int main(int argc, char *argv[]) { volatile double a = 0; volatile double b = 23; volatile double c = exp(b) / a; + (void)c; volatile int64_t x; return 1 / (x = 0); diff --git a/examples/crashreport2.c b/examples/crashreport2.c index 78a8c266a..95f51ddec 100644 --- a/examples/crashreport2.c +++ b/examples/crashreport2.c @@ -43,7 +43,6 @@ */ int main(int argc, char *argv[]) { - volatile int64_t x; ShowCrashReports(); printf("please press ctrl+\\ and see what happens...\n"); sigsuspend(0); diff --git a/examples/datauri.c b/examples/datauri.c index fc3aeb997..6b4706de3 100644 --- a/examples/datauri.c +++ b/examples/datauri.c @@ -35,8 +35,7 @@ void PrintUsage(int rc, FILE *f) { void PrintUri(const char *path) { size_t n; - void *img, *src, *mime; - int opt, i; + void *img; if (!(img = gc(xslurp(path, &n)))) exit(2); fputs("data:", stdout); fputs(FindContentType(path, -1), stdout); diff --git a/examples/defer-statements.c b/examples/defer-statements.c index cdb9be3ab..e58dbce51 100644 --- a/examples/defer-statements.c +++ b/examples/defer-statements.c @@ -7,15 +7,15 @@ │ • http://creativecommons.org/publicdomain/zero/1.0/ │ ╚─────────────────────────────────────────────────────────────────*/ #endif -#include "libc/mem/mem.h" #include "libc/mem/gc.h" +#include "libc/mem/mem.h" #include "libc/stdio/stdio.h" /** * Cosmopolitan C is just as awesome as Go! * Example contributed by @Keithcat1 (#266) */ -main() { +int main() { _defer(printf, "Done!\n"); for (long i = 0; i < 100000; i++) { printf("%i ", i); diff --git a/examples/forkexec.c b/examples/forkexec.c index 418e16485..4f34aca2c 100644 --- a/examples/forkexec.c +++ b/examples/forkexec.c @@ -11,7 +11,6 @@ #include "libc/stdio/stdio.h" int main(int argc, char *argv[]) { - int pid; if (argc < 3) { fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr); return 1; diff --git a/examples/forkexecwait.c b/examples/forkexecwait.c index eca2b20cd..152a3f469 100644 --- a/examples/forkexecwait.c +++ b/examples/forkexecwait.c @@ -11,8 +11,6 @@ #include "libc/stdio/stdio.h" int main(int argc, char *argv[]) { - int pid; - volatile void *p; if (argc < 3) { fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr); return 1; diff --git a/examples/gettimeofday.c b/examples/gettimeofday.c index 2e5623e0b..2dd8f1e03 100644 --- a/examples/gettimeofday.c +++ b/examples/gettimeofday.c @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) { struct tm tm; struct timeval tv; rc = gettimeofday(&tv, 0); - assert(!rc); + unassert(!rc); t = tv.tv_sec; gmtime_r(&t, &tm); FormatHttpDateTime(p, &tm); diff --git a/examples/greenbean.c b/examples/greenbean.c index fd3c44abd..2c3cfeaf7 100644 --- a/examples/greenbean.c +++ b/examples/greenbean.c @@ -148,14 +148,13 @@ void *Worker(void *id) { while (!closingtime) { struct tm tm; int64_t unixts; - struct Url url; ssize_t got, sent; struct timespec ts; struct HttpMessage msg; uint32_t clientaddrsize; struct sockaddr_in clientaddr; char inbuf[1500], outbuf[512], *p, *q; - int clientip, client, inmsglen, outmsglen; + int client, inmsglen, outmsglen; // this slows the server down a lot but is needed on non-Linux to // react to keyboard ctrl-c diff --git a/examples/hangman.c b/examples/hangman.c index 83f20bd96..0aa257ad9 100644 --- a/examples/hangman.c +++ b/examples/hangman.c @@ -38,8 +38,8 @@ */ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" -#include "libc/stdio/rand.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/time/time.h" @@ -178,8 +178,7 @@ void youwon() printf("you win, the word is %s\n",realword); } -main(argc,argv) - char **argv; +int main(int argc,char **argv) { if(argc==1) dictfile=DICT; else dictfile=argv[1]; diff --git a/examples/hellolua.c b/examples/hellolua.c index a0fbedddf..0dae319ac 100644 --- a/examples/hellolua.c +++ b/examples/hellolua.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { luaL_openlibs(L); lua_pushcfunction(L, NativeAdd); lua_setglobal(L, "NativeAdd"); - luaL_dofile(L, "/zip/examples/hellolua.lua"); + (void)luaL_dofile(L, "/zip/examples/hellolua.lua"); lua_close(L); return 0; } diff --git a/examples/img.c b/examples/img.c index 1b0fe596d..13c7e1033 100644 --- a/examples/img.c +++ b/examples/img.c @@ -44,14 +44,14 @@ void PrintUsage(int rc, FILE *f) { void PrintImg(const char *path) { size_t n; - int opt, i, yn, xn, cn, w, h; - void *img, *pix, *src, *mime; + 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 (linktag) { printf("", path); } - src = path; + src = (void *)path; if (datauri) { src = xasprintf("data:%s;base64,%s", FindContentType(path, -1), _gc(EncodeBase64(img, n, &n))); diff --git a/examples/kilo.c b/examples/kilo.c index eeed5cb3c..0aca8475b 100644 --- a/examples/kilo.c +++ b/examples/kilo.c @@ -413,9 +413,9 @@ void editorUpdateSyntax(erow *row) { int i, prev_sep, in_string, in_comment; char *p; const char *const *keywords = E.syntax->keywords; - char *scs = E.syntax->singleline_comment_start; - char *mcs = E.syntax->multiline_comment_start; - char *mce = E.syntax->multiline_comment_end; + const char *scs = E.syntax->singleline_comment_start; + const char *mcs = E.syntax->multiline_comment_start; + const char *mce = E.syntax->multiline_comment_end; /* Point to the first non-space char. */ p = row->render; @@ -575,7 +575,7 @@ int editorSyntaxToColor(int hl) { * setting it in the global state E.syntax. */ void editorSelectSyntaxHighlight(char *filename) { for (unsigned j = 0; j < HLDB_ENTRIES; j++) { - struct editorSyntax *s = HLDB + j; + const struct editorSyntax *s = HLDB + j; unsigned i = 0; while (s->filematch[i]) { char *p; @@ -898,7 +898,7 @@ struct abuf { }; static void abAppend(struct abuf *ab, const char *s, int len) { - CONCAT(&ab->p, &ab->i, &ab->n, s, len); + CONCAT(&ab->p, &ab->i, &ab->n, (void *)s, len); } /* This function writes the whole screen using VT100 escape characters diff --git a/examples/nanosleep_test.c b/examples/nanosleep_test.c index dbeea1c20..d6d8e70c5 100644 --- a/examples/nanosleep_test.c +++ b/examples/nanosleep_test.c @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { long i, ns; - struct timespec x, y, w; + struct timespec x, y; timespec_sleep(timespec_fromnanos(0)); // warmup printf("\nrelative sleep\n"); diff --git a/examples/nc.c b/examples/nc.c index c90c2aa1b..f484013bb 100644 --- a/examples/nc.c +++ b/examples/nc.c @@ -45,10 +45,10 @@ int main(int argc, char *argv[]) { ssize_t rc; size_t i, got; + int opt, sock; char buf[1500]; bool halfclose = true; const char *host, *port; - int opt, err, toto, sock; struct addrinfo *ai = NULL; struct linger linger = {true, 1}; struct pollfd fds[2] = {{-1, POLLIN}, {-1, POLLIN}}; diff --git a/examples/nesemu1.cc b/examples/nesemu1.cc index e004850f3..2bf6a4245 100644 --- a/examples/nesemu1.cc +++ b/examples/nesemu1.cc @@ -164,7 +164,6 @@ static struct TtyRgb* ttyrgb_; static unsigned char *R, *G, *B; static struct ZipGames zipgames_; static struct Action arrow_, button_; -static struct SamplingSolution* asx_; static struct SamplingSolution* ssy_; static struct SamplingSolution* ssx_; static unsigned char pixels_[3][DYN][DXN]; @@ -585,7 +584,6 @@ void Raster(void) { f->p = stpcpy(f->p, "\e[0m\e[H"); f->p = stpcpy(f->p, status_.text); } - CHECK_LT(f->p - f->mem, vtsize_); PollAndSynchronize(); } @@ -599,7 +597,6 @@ void FlushScanline(unsigned py) { } static void PutPixel(unsigned px, unsigned py, unsigned pixel, int offset) { - unsigned rgb; static unsigned prev; pixels_[0][py][px] = palette_[offset][prev % 64][pixel][2]; pixels_[1][py][px] = palette_[offset][prev % 64][pixel][1]; @@ -1811,8 +1808,8 @@ void GetOpts(int argc, char* argv[]) { size_t FindZipGames(void) { char* name; + size_t i, cf; struct Zipos* zipos; - size_t i, cf, namesize; if ((zipos = __zipos_get())) { for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir); i < ZIP_CDIR_RECORDS(zipos->cdir); @@ -1834,14 +1831,14 @@ int SelectGameFromZip(void) { int i, rc; char *line, *uri; fputs("\nCOSMOPOLITAN NESEMU1\n\n", stdout); - for (i = 0; i < zipgames_.i; ++i) { + for (i = 0; i < (int)zipgames_.i; ++i) { printf(" [%d] %s\n", i, zipgames_.p[i]); } fputs("\nPlease choose a game (or CTRL-C to quit) [default 0]: ", stdout); fflush(stdout); rc = 0; if ((line = GetLine())) { - i = MAX(0, MIN(zipgames_.i - 1, atoi(line))); + i = MAX(0, MIN((int)zipgames_.i - 1, atoi(line))); uri = zipgames_.p[i]; rc = PlayGame(uri, NULL); free(uri); diff --git a/examples/panels.c b/examples/panels.c index 8630e86a8..8f30fb945 100644 --- a/examples/panels.c +++ b/examples/panels.c @@ -122,7 +122,7 @@ void Clear(void) { } void Layout(void) { - long i, j; + long i; i = txn >> 1; pan.left.top = 0; pan.left.left = 0; diff --git a/examples/script.c b/examples/script.c index c8d1d8b85..269bd3628 100644 --- a/examples/script.c +++ b/examples/script.c @@ -113,9 +113,9 @@ main(int argc, char *argv[]) static char obuf[BUFSIZ]; static char ibuf[BUFSIZ]; fd_set rfd; + int fm_fd; int aflg, Fflg, kflg, pflg, ch, k, n; int flushtime, readstdin; - int fm_fd, fm_log; aflg = Fflg = kflg = pflg = 0; usesleep = 1; @@ -125,6 +125,8 @@ main(int argc, char *argv[]) warning. (not needed w/clang) */ showexit = 0; + (void)fm_fd; + while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1) switch(ch) { case 'a': diff --git a/examples/unbourne.c b/examples/unbourne.c index 721935af2..6bef9907b 100644 --- a/examples/unbourne.c +++ b/examples/unbourne.c @@ -1026,7 +1026,6 @@ struct t_op { │ cosmopolitan § the unbourne shell » bss ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ -static int inter; static char **argptr; /* argument list for builtin commands */ static char **gargv; static char **t_wp; @@ -5747,7 +5746,7 @@ static void CompleteCommand(const char *p, const char *q, const char *b, } closedir(d); } - free(path); + free((void *)path); } } } @@ -5784,7 +5783,6 @@ static void CompleteFilename(const char *p, const char *q, const char *b, static void ShellCompletion(const char *p, linenoiseCompletions *c) { bool slashed; const char *q, *b; - struct tblentry **pp, *cmdp; for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) { if (p[-1] == '/' && p[-1] == '\\') slashed = true; if (!isalnum(p[-1]) && diff --git a/examples/wall.c b/examples/wall.c index e9e6ce094..f4da6315b 100644 --- a/examples/wall.c +++ b/examples/wall.c @@ -75,7 +75,6 @@ char *GetHost(void) { } char *GetTime(void) { - int64_t t; struct tm tm; struct timespec ts; clock_gettime(0, &ts); diff --git a/libc/calls/__sig2.c b/libc/calls/__sig2.c index a7873c2f6..fcf679fb9 100644 --- a/libc/calls/__sig2.c +++ b/libc/calls/__sig2.c @@ -183,7 +183,7 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code, if (__sig_is_fatal(sig)) { intptr_t hStderr; const char *signame; - char *end, sigbuf[15], output[16]; + char *end, sigbuf[21], output[22]; signame = strsignal_r(sig, sigbuf); STRACE("terminating due to uncaught %s", signame); hStderr = GetStdHandle(kNtStdErrorHandle); @@ -274,7 +274,6 @@ textwindows int __sig_add(int tid, int sig, int si_code) { * @threadsafe */ textwindows bool __sig_check(int sigops) { - unsigned rva; bool delivered; struct Signal *sig; delivered = false; diff --git a/libc/calls/clock_gettime-mono.c b/libc/calls/clock_gettime-mono.c index 308a4f503..b90116387 100644 --- a/libc/calls/clock_gettime-mono.c +++ b/libc/calls/clock_gettime-mono.c @@ -37,7 +37,6 @@ static void sys_clock_gettime_mono_init(void) { int sys_clock_gettime_mono(struct timespec *time) { uint64_t nanos; uint64_t cycles; - struct timespec res; if (X86_HAVE(INVTSC)) { cosmo_once(&g_mono.once, sys_clock_gettime_mono_init); cycles = rdtsc() - g_mono.base_tick; diff --git a/libc/calls/closefrom.c b/libc/calls/closefrom.c index e854ef55e..b4bb8f5c4 100644 --- a/libc/calls/closefrom.c +++ b/libc/calls/closefrom.c @@ -43,6 +43,7 @@ */ int closefrom(int first) { int rc, err; + (void)err; if (first < 0) { // consistent with openbsd // freebsd allows this but it's dangerous diff --git a/libc/calls/copy_file_range.c b/libc/calls/copy_file_range.c index b7983b080..72eb91606 100644 --- a/libc/calls/copy_file_range.c +++ b/libc/calls/copy_file_range.c @@ -39,8 +39,8 @@ static struct CopyFileRange { } g_copy_file_range; static bool HasCopyFileRange(void) { + int e; bool ok; - int e, rc; e = errno; BLOCK_CANCELLATIONS; if (IsLinux()) { diff --git a/libc/calls/execl.c b/libc/calls/execl.c index fc7e63216..b634eae2a 100644 --- a/libc/calls/execl.c +++ b/libc/calls/execl.c @@ -43,9 +43,9 @@ int execl(const char *exe, const char *arg, ... /*, NULL*/) { va_end(va); argv = alloca((i + 2) * sizeof(char *)); va_start(vb, arg); - argv[0] = arg; + argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, const char *))) break; + if (!(argv[i] = va_arg(vb, char *))) break; } va_end(vb); return execv(exe, argv); diff --git a/libc/calls/execle.c b/libc/calls/execle.c index fddd3021e..eb48bc8d6 100644 --- a/libc/calls/execle.c +++ b/libc/calls/execle.c @@ -45,9 +45,9 @@ int execle(const char *exe, const char *arg, va_end(va); argv = alloca((i + 2) * sizeof(char *)); va_start(vb, arg); - argv[0] = arg; + argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, const char *))) break; + if (!(argv[i] = va_arg(vb, char *))) break; } va_end(vb); return execve(exe, argv, envp); diff --git a/libc/calls/execlp.c b/libc/calls/execlp.c index 66f5f6e59..ca17489e3 100644 --- a/libc/calls/execlp.c +++ b/libc/calls/execlp.c @@ -49,9 +49,9 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) { va_end(va); argv = alloca((i + 2) * sizeof(char *)); va_start(vb, arg); - argv[0] = arg; + argv[0] = (char *)arg; for (i = 1;; ++i) { - if (!(argv[i] = va_arg(vb, const char *))) break; + if (!(argv[i] = va_arg(vb, char *))) break; } va_end(vb); diff --git a/libc/calls/execve-sysv.c b/libc/calls/execve-sysv.c index 32e9fb60f..b3dbfde59 100644 --- a/libc/calls/execve-sysv.c +++ b/libc/calls/execve-sysv.c @@ -89,15 +89,15 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) { ".ape-" APE_VERSION_STR, buf))) || CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."), ".ape-" APE_VERSION_STR, buf))))) { - shargs[0] = ape; - shargs[1] = "-"; - shargs[2] = prog; + shargs[0] = (char *)ape; + shargs[1] = (char *)"-"; + shargs[2] = (char *)prog; memcpy(shargs + 3, argv, (i + 1) * sizeof(char *)); errno = e; rc = __sys_execve(shargs[0], shargs, envp); } else if (CanExecute(prog)) { shargs[0] = _PATH_BSHELL; - shargs[1] = prog; + shargs[1] = (char *)prog; memcpy(shargs + 2, argv + 1, i * sizeof(char *)); errno = e; rc = __sys_execve(shargs[0], shargs, envp); diff --git a/libc/calls/execve.c b/libc/calls/execve.c index 0635ec93c..46f3c2fdd 100644 --- a/libc/calls/execve.c +++ b/libc/calls/execve.c @@ -56,9 +56,8 @@ * @vforksafe */ int execve(const char *prog, char *const argv[], char *const envp[]) { - struct ZiposUri uri; int rc; - size_t i; + struct ZiposUri uri; if (!prog || !argv || !envp || (IsAsan() && (!__asan_is_valid_str(prog) || // !__asan_is_valid_strlist(argv) || // diff --git a/libc/calls/fadvise.c b/libc/calls/fadvise.c index 2a5b13ddb..bd7442374 100644 --- a/libc/calls/fadvise.c +++ b/libc/calls/fadvise.c @@ -43,7 +43,7 @@ int sys_fadvise_netbsd(int, int, int64_t, int64_t, int) asm("sys_fadvise"); * @raise ENOSYS on XNU and OpenBSD */ int fadvise(int fd, uint64_t offset, uint64_t len, int advice) { - int rc, e = errno; + int rc; if (IsLinux()) { rc = sys_fadvise(fd, offset, len, advice); } else if (IsFreebsd() || IsNetbsd()) { diff --git a/libc/calls/fcntl-nt.c b/libc/calls/fcntl-nt.c index a0df32741..42c48815d 100644 --- a/libc/calls/fcntl-nt.c +++ b/libc/calls/fcntl-nt.c @@ -124,11 +124,10 @@ textwindows void sys_fcntl_nt_lock_cleanup(int fd) { static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, uintptr_t arg) { - int e; + uint32_t flags; struct flock *l; - uint32_t flags, err; + int64_t pos, off, len, end; struct FileLock *fl, *ft, **flp; - int64_t pos, off, len, end, size; l = (struct flock *)arg; len = l->l_len; @@ -171,7 +170,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, for (flp = &g_locks.list, fl = *flp; fl;) { if (fl->fd == fd) { if (EqualsFileLock(fl, off, len)) { - if (fl->exc == l->l_type == F_WRLCK) { + if (fl->exc == (l->l_type == F_WRLCK)) { // we already have this lock return 0; } else { @@ -205,7 +204,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd, l->l_whence = SEEK_SET; l->l_start = fl->off; l->l_len = fl->len; - l->l_type == fl->exc ? F_WRLCK : F_RDLCK; + l->l_type = fl->exc ? F_WRLCK : F_RDLCK; l->l_pid = getpid(); return 0; } @@ -360,7 +359,6 @@ static textwindows int sys_fcntl_nt_setfl(int fd, unsigned *flags, textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) { int rc; - uint32_t flags; if (__isfdkind(fd, kFdFile) || // __isfdkind(fd, kFdSocket) || // __isfdkind(fd, kFdConsole)) { diff --git a/libc/calls/fexecve.c b/libc/calls/fexecve.c index 9b26dfed2..ee11c5172 100644 --- a/libc/calls/fexecve.c +++ b/libc/calls/fexecve.c @@ -45,7 +45,6 @@ static bool IsAPEFd(const int fd) { char buf[8]; - bool res; return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf); } @@ -115,7 +114,7 @@ static bool ape_to_elf(void *ape, const size_t apesize) { * This does an inplace conversion of APE to ELF when detected!!!! */ static int fd_to_mem_fd(const int infd, char *path) { - if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) { + if ((!IsLinux() && !IsFreebsd()) || !_weaken(mmap) || !_weaken(munmap)) { return enosys(); } @@ -143,9 +142,9 @@ static int fd_to_mem_fd(const int infd, char *path) { bool success = readRc != -1; if (success && (st.st_size > 8) && IsAPEMagic(space)) { int flags = fcntl(fd, F_GETFD); - if (success = (flags != -1) && - (fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) && - ape_to_elf(space, st.st_size)) { + if ((success = (flags != -1) && + (fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) && + ape_to_elf(space, st.st_size))) { const int newfd = fcntl(fd, F_DUPFD, 9001); if (newfd != -1) { close(fd); @@ -232,7 +231,7 @@ int fexecve(int fd, char *const argv[], char *const envp[]) { } size_t numenvs; for (numenvs = 0; envp[numenvs];) ++numenvs; - const size_t desenvs = min(500, max(numenvs + 1, 2)); + // const size_t desenvs = min(500, max(numenvs + 1, 2)); static _Thread_local char *envs[500]; memcpy(envs, envp, numenvs * sizeof(char *)); envs[numenvs] = path; diff --git a/libc/calls/fstatat-sysv.c b/libc/calls/fstatat-sysv.c index 0e6476a81..b2e636608 100644 --- a/libc/calls/fstatat-sysv.c +++ b/libc/calls/fstatat-sysv.c @@ -28,7 +28,6 @@ */ int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st, int32_t flags) { - int rc; void *p; union metastat ms; if (IsAsan() && !__asan_is_valid_str(path)) return efault(); diff --git a/libc/calls/fstatfs-nt.c b/libc/calls/fstatfs-nt.c index 62e86b9f4..ba57d2b57 100644 --- a/libc/calls/fstatfs-nt.c +++ b/libc/calls/fstatfs-nt.c @@ -37,7 +37,6 @@ textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) { uint64_t w; NtStatus st; - uint32_t type; uint32_t h, i, j; struct NtIoStatusBlock io; struct NtFileFsFullSizeInformation fs; diff --git a/libc/calls/getloadavg-nt.c b/libc/calls/getloadavg-nt.c index 65fda675a..6e90db64b 100644 --- a/libc/calls/getloadavg-nt.c +++ b/libc/calls/getloadavg-nt.c @@ -57,7 +57,6 @@ textwindows int sys_getloadavg_nt(double *a, int n) { } static textstartup void sys_getloadavg_nt_init(void) { - double a[3]; if (IsWindows()) { load = 1; cpus = __get_cpu_count() / 2; diff --git a/libc/calls/gettimeofday.c b/libc/calls/gettimeofday.c index 11c401bdd..8943f77fe 100644 --- a/libc/calls/gettimeofday.c +++ b/libc/calls/gettimeofday.c @@ -55,7 +55,6 @@ static gettimeofday_f *__gettimeofday = __gettimeofday_init; */ int gettimeofday(struct timeval *tv, struct timezone *tz) { int rc; - axdx_t ad; if (IsAsan() && ((tv && !__asan_is_valid(tv, sizeof(*tv))) || (tz && !__asan_is_valid(tz, sizeof(*tz))))) { rc = efault(); diff --git a/libc/calls/groups.internal.h b/libc/calls/groups.internal.h index fb91680bc..616b47277 100644 --- a/libc/calls/groups.internal.h +++ b/libc/calls/groups.internal.h @@ -4,7 +4,7 @@ COSMOPOLITAN_C_START_ int sys_getgroups(int size, uint32_t list[]); -int sys_setgroups(size_t size, uint32_t list[]); +int sys_setgroups(size_t size, const uint32_t list[]); const char *DescribeGidList(char[128], int, int, const uint32_t list[]); #define DescribeGidList(rc, length, gidlist) \ diff --git a/libc/calls/ioctl.c b/libc/calls/ioctl.c index 12f35b71d..47ee0aa27 100644 --- a/libc/calls/ioctl.c +++ b/libc/calls/ioctl.c @@ -72,7 +72,6 @@ static struct HostAdapterInfoNode { static int ioctl_default(int fd, unsigned long request, void *arg) { int rc; - va_list va; int64_t handle; if (!IsWindows()) { return sys_ioctl(fd, request, arg); @@ -94,7 +93,6 @@ static int ioctl_default(int fd, unsigned long request, void *arg) { static int ioctl_fionread(int fd, uint32_t *arg) { int rc; - va_list va; int64_t handle; uint32_t avail; if (!IsWindows()) { @@ -323,7 +321,6 @@ static textwindows int createHostInfo( struct NtIpAdapterPrefix *ap; struct HostAdapterInfoNode *node = NULL; char baseName[IFNAMSIZ]; - char name[IFNAMSIZ]; int count, i; /* __hostInfo must be empty */ unassert(__hostInfo == NULL); @@ -416,7 +413,6 @@ err: static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) { struct ifreq *ptr; - struct NtIpAdapterAddresses *aa; struct HostAdapterInfoNode *node; if (__hostInfo) { freeHostInfo(); @@ -480,12 +476,12 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) { * BSD ABIs mainly differ by having sockaddr::sa_len * XNU uses a 32-bit length in a struct that's packed! */ - int i, rc, fam; + int rc, fam; + size_t bufMax; char *b, *p, *e; char ifcBsd[16]; struct ifreq *req; uint32_t bufLen, ip; - size_t numReq, bufMax; if (IsLinux()) { return sys_ioctl(fd, SIOCGIFCONF, ifc); } diff --git a/libc/calls/isatty.c b/libc/calls/isatty.c index 92553fa36..d8f698b4b 100644 --- a/libc/calls/isatty.c +++ b/libc/calls/isatty.c @@ -37,7 +37,6 @@ * @raise EPERM if pledge() was used without tty */ bool32 isatty(int fd) { - int e; bool32 res; struct winsize ws; if (__isfdkind(fd, kFdZip)) { diff --git a/libc/calls/mkfifo.c b/libc/calls/mkfifo.c index 0ce58491b..e2cc3396d 100644 --- a/libc/calls/mkfifo.c +++ b/libc/calls/mkfifo.c @@ -38,7 +38,7 @@ */ int mkfifo(const char *pathname, unsigned mode) { // TODO(jart): Windows? - int e, rc; + int rc; if (IsAsan() && !__asan_is_valid_str(pathname)) { rc = efault(); } else if (IsLinux()) { diff --git a/libc/calls/mkntcmdline.c b/libc/calls/mkntcmdline.c index fb8b72ba6..5081c4835 100644 --- a/libc/calls/mkntcmdline.c +++ b/libc/calls/mkntcmdline.c @@ -71,7 +71,6 @@ textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], char *const argv[]) { wint_t x, y; int slashes, n; bool needsquote; - char16_t cbuf[2]; char *ansiargv[2]; size_t i, j, k, s; if (!argv[0]) { diff --git a/libc/calls/mkntenvblock.c b/libc/calls/mkntenvblock.c index 669ff827a..7a69acc5f 100644 --- a/libc/calls/mkntenvblock.c +++ b/libc/calls/mkntenvblock.c @@ -36,9 +36,9 @@ static inline int IsAlpha(int c) { return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); } -static inline char *StrChr(char *s, int c) { +static inline char *StrChr(const char *s, int c) { for (;; ++s) { - if ((*s & 255) == (c & 255)) return s; + if ((*s & 255) == (c & 255)) return (char *)s; if (!*s) return 0; } } @@ -52,7 +52,6 @@ static textwindows inline int CompareStrings(const char *l, const char *r) { static textwindows void FixPath(char *path) { char *p; - size_t i; // skip over variable name while (*path++) { @@ -71,7 +70,7 @@ static textwindows void FixPath(char *path) { // turn \c\... into c:\... p = path; - if ((p[0] == '/' | p[0] == '\\') && IsAlpha(p[1]) && + if ((p[0] == '/' || p[0] == '\\') && IsAlpha(p[1]) && (p[2] == '/' || p[2] == '\\')) { p[0] = p[1]; p[1] = ':'; @@ -92,7 +91,7 @@ static textwindows void FixPath(char *path) { } } -static textwindows void InsertString(char **a, size_t i, char *s, +static textwindows void InsertString(char **a, size_t i, const char *s, char buf[ARG_MAX], size_t *bufi, bool *have_systemroot) { char *v; @@ -119,7 +118,7 @@ static textwindows void InsertString(char **a, size_t i, char *s, for (j = i; j > 0 && CompareStrings(s, a[j - 1]) < 0; --j) { a[j] = a[j - 1]; } - a[j] = s; + a[j] = (char *)s; } /** @@ -136,8 +135,6 @@ static textwindows void InsertString(char **a, size_t i, char *s, textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[], const char *extravar, char buf[ARG_MAX]) { bool v; - char *t; - axdx_t rc; uint64_t w; char **vars; wint_t x, y; diff --git a/libc/calls/mount.c b/libc/calls/mount.c index 36bb2560f..0fcdc0fb5 100644 --- a/libc/calls/mount.c +++ b/libc/calls/mount.c @@ -25,7 +25,7 @@ int32_t sys_mount_linux(const char *source, const char *target, const char *filesystemtype, uint64_t mountflags, const void *data) asm("sys_mount"); int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags, - void *data) asm("sys_mount"); + const void *data) asm("sys_mount"); /** * Mounts file system. diff --git a/libc/calls/mremap-sysv.greg.c b/libc/calls/mremap-sysv.greg.c index 3a5ad39f3..2b403a708 100644 --- a/libc/calls/mremap-sysv.greg.c +++ b/libc/calls/mremap-sysv.greg.c @@ -37,7 +37,7 @@ void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) { #ifdef __x86_64__ bool cf; - uintptr_t res, rdi, rsi, rdx; + uintptr_t res, rdx; register uintptr_t r8 asm("r8"); register uintptr_t r10 asm("r10"); if (IsLinux()) { diff --git a/libc/calls/now.c b/libc/calls/now.c index d079d46ee..a0fba41dc 100644 --- a/libc/calls/now.c +++ b/libc/calls/now.c @@ -102,7 +102,6 @@ static long double nowl_vdso(void) { long double nowl_setup(void) { bool isfast; - uint64_t ticks; __gettime = __clock_gettime_get(&isfast); if (isfast) { nowl = nowl_vdso; diff --git a/libc/calls/onntconsoleevent.c b/libc/calls/onntconsoleevent.c index e6ef7b650..3d6cb2518 100644 --- a/libc/calls/onntconsoleevent.c +++ b/libc/calls/onntconsoleevent.c @@ -26,13 +26,12 @@ #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sig.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" #ifdef __x86_64__ textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) { struct CosmoTib tib; - struct StackFrame *fr; // win32 spawns a thread on its own just to deliver sigint // TODO(jart): make signal code lockless so we can delete! diff --git a/libc/calls/openpty.c b/libc/calls/openpty.c index c4801ff45..494fd68ee 100644 --- a/libc/calls/openpty.c +++ b/libc/calls/openpty.c @@ -48,7 +48,7 @@ struct IoctlPtmGet { static int openpty_impl(int *mfd, int *sfd, char *name, const struct termios *tio, // const struct winsize *wsz) { - int m, s, p; + int m, s; struct IoctlPtmGet t; RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY))); if (!IsOpenbsd()) { @@ -66,7 +66,7 @@ static int openpty_impl(int *mfd, int *sfd, char *name, *sfd = s; if (name) strcpy(name, t.sname); if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio)); - if (wsz) npassert(!tcgetwinsize(s, wsz)); + if (wsz) npassert(!tcsetwinsize(s, wsz)); return 0; OnError: if (m != -1) sys_close(m); diff --git a/libc/calls/pledge-linux.c b/libc/calls/pledge-linux.c index eaa98abcf..f098877a7 100644 --- a/libc/calls/pledge-linux.c +++ b/libc/calls/pledge-linux.c @@ -1079,11 +1079,11 @@ static privileged int GetTid(void) { } static privileged void Log(const char *s, ...) { - int res; va_list va; va_start(va, s); do { #ifdef __x86_64__ + int res; asm volatile("syscall" : "=a"(res) : "0"(__NR_linux_write), "D"(2), "S"(s), "d"(StrLen(s)) @@ -1156,10 +1156,10 @@ static privileged int SigProcMask(int how, int64_t set, int64_t *old) { } static privileged void KillThisProcess(void) { - int res; SigAction(Sigabrt, &(struct sigaction){0}, 0); SigProcMask(Sig_Setmask, -1, 0); #ifdef __x86_64__ + int res; asm volatile("syscall" : "=a"(res) : "0"(__NR_linux_kill), "D"(GetPid()), "S"(Sigabrt) @@ -1196,10 +1196,10 @@ static privileged void KillThisProcess(void) { } static privileged void KillThisThread(void) { - int res; SigAction(Sigabrt, &(struct sigaction){0}, 0); SigProcMask(Sig_Setmask, -1, 0); #ifdef __x86_64__ + int res; asm volatile("syscall" : "=a"(res) : "0"(__NR_linux_tkill), "D"(GetTid()), "S"(Sigabrt) @@ -1233,7 +1233,7 @@ static privileged const char *GetSyscallName(uint16_t n) { return "unknown"; } -static privileged int HasSyscall(struct Pledges *p, uint16_t n) { +static privileged int HasSyscall(const struct Pledges *p, uint16_t n) { int i; for (i = 0; i < p->len; ++i) { if (p->syscalls[i] == n) { @@ -1249,11 +1249,11 @@ static privileged int HasSyscall(struct Pledges *p, uint16_t n) { static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) { bool found; char ord[17]; - int i, ok, mode = si->si_errno; + int i, mode = si->si_errno; ucontext_t *ctx = vctx; ctx->uc_mcontext.MCONTEXT_SYSCALL_RESULT_REGISTER = -Eperm; FixCpy(ord, si->si_syscall, 12); - for (found = i = 0; i < ARRAYLEN(kPledge); ++i) { + for (found = false, i = 0; i < ARRAYLEN(kPledge); ++i) { if (HasSyscall(kPledge + i, si->si_syscall)) { Log("error: protected syscall ", GetSyscallName(si->si_syscall), " (ord=", ord, "); pledge promise '", kPledge[i].name, "' to allow\n", @@ -1289,8 +1289,8 @@ static privileged void MonitorSigSys(void) { } } -static privileged void AppendFilter(struct Filter *f, struct sock_filter *p, - size_t n) { +static privileged void AppendFilter(struct Filter *f, + const struct sock_filter *p, size_t n) { if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible; MemCpy(f->p + f->n, p, n * sizeof(*f->p)); f->n += n; @@ -2290,8 +2290,8 @@ static privileged void AppendPledge(struct Filter *f, // * @vforksafe */ privileged int sys_pledge_linux(unsigned long ipromises, int mode) { + int i, rc = -1; struct Filter f; - int i, e, rc = -1; struct sock_filter sf[1] = {BPF_STMT(BPF_RET | BPF_K, 0)}; CheckLargeStackAllocation(&f, sizeof(f)); f.n = 0; diff --git a/libc/calls/pwrite.c b/libc/calls/pwrite.c index db94c6dfe..b9e5005cd 100644 --- a/libc/calls/pwrite.c +++ b/libc/calls/pwrite.c @@ -67,7 +67,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) { } else if (__isfdkind(fd, kFdSocket)) { rc = espipe(); } else if (__isfdkind(fd, kFdFile)) { - rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, offset); + rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, offset); } else { return ebadf(); } diff --git a/libc/calls/raise.c b/libc/calls/raise.c index 1c41b8a24..bdf6b5bda 100644 --- a/libc/calls/raise.c +++ b/libc/calls/raise.c @@ -53,7 +53,7 @@ static dontubsan void RaiseSigFpe(void) { * @asyncsignalsafe */ int raise(int sig) { - int rc, tid, event; + int rc; STRACE("raise(%G) → ...", sig); if (sig == SIGTRAP) { DebugBreak(); diff --git a/libc/calls/read-nt.c b/libc/calls/read-nt.c index 005368490..ed6e25660 100644 --- a/libc/calls/read-nt.c +++ b/libc/calls/read-nt.c @@ -66,7 +66,6 @@ static textwindows ssize_t sys_read_nt_impl(struct Fd *fd, void *data, int filetype; int64_t handle; uint32_t remain; - uint32_t conmode; char *targetdata; uint32_t targetsize; bool is_console_input; @@ -205,7 +204,6 @@ StartOver: textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov, size_t iovlen, int64_t opt_offset) { ssize_t rc; - uint32_t size; size_t i, total; if (opt_offset < -1) return einval(); if (_check_interrupts(kSigOpRestartable)) return -1; diff --git a/libc/calls/readlinkat-nt.c b/libc/calls/readlinkat-nt.c index 47631d067..a97aecd56 100644 --- a/libc/calls/readlinkat-nt.c +++ b/libc/calls/readlinkat-nt.c @@ -45,7 +45,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf, if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1; mem = 16384; memory = alloca(mem); - CheckLargeStackAllocation(memory, mem); + CheckLargeStackAllocation((char *)memory, mem); rdb = (struct NtReparseDataBuffer *)memory; if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting, kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics, diff --git a/libc/calls/readv-serial.c b/libc/calls/readv-serial.c index 00857c6ba..b1f91ca78 100644 --- a/libc/calls/readv-serial.c +++ b/libc/calls/readv-serial.c @@ -26,7 +26,7 @@ static bool IsDataAvailable(struct Fd *fd) { return inb(fd->handle + UART_LSR) & UART_TTYDA; } -static int GetFirstIov(struct iovec *iov, int iovlen) { +static int GetFirstIov(const struct iovec *iov, int iovlen) { int i; for (i = 0; i < iovlen; ++i) { if (iov[i].iov_len) { diff --git a/libc/calls/reservefd.c b/libc/calls/reservefd.c index 1bde9a6be..43770bfb5 100644 --- a/libc/calls/reservefd.c +++ b/libc/calls/reservefd.c @@ -39,7 +39,6 @@ static volatile size_t mapsize; * @asyncsignalsafe */ int __ensurefds_unlocked(int fd) { - bool relocate; if (fd < g_fds.n) return fd; g_fds.n = fd + 1; g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE, diff --git a/libc/calls/sigenter-xnu.c b/libc/calls/sigenter-xnu.c index 1e62bd95a..b70fc4112 100644 --- a/libc/calls/sigenter-xnu.c +++ b/libc/calls/sigenter-xnu.c @@ -488,7 +488,6 @@ static privileged void linuxssefpustate2xnu( privileged void __sigenter_xnu(void *fn, int infostyle, int sig, struct siginfo_xnu *xnuinfo, struct __darwin_ucontext *xnuctx) { - intptr_t ax; int rva, flags; struct Goodies { ucontext_t uc; @@ -571,6 +570,7 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig, } #ifdef __x86_64__ + intptr_t ax; asm volatile("syscall" : "=a"(ax) : "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle) diff --git a/libc/calls/sigprocmask.c b/libc/calls/sigprocmask.c index 389ab619d..787e22dd1 100644 --- a/libc/calls/sigprocmask.c +++ b/libc/calls/sigprocmask.c @@ -50,9 +50,8 @@ * @vforksafe */ int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) { - int res, rc, arg1; + int rc; sigset_t old = {0}; - const sigset_t *arg2; if (IsAsan() && ((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) || (opt_out_oldset && diff --git a/libc/calls/sigsuspend.c b/libc/calls/sigsuspend.c index e5b1abd9e..5f3d07e3b 100644 --- a/libc/calls/sigsuspend.c +++ b/libc/calls/sigsuspend.c @@ -47,7 +47,8 @@ */ int sigsuspend(const sigset_t *ignore) { int rc; - sigset_t save, *arg, mask = {0}; + const sigset_t *arg; + sigset_t save, mask = {0}; STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore)); BEGIN_CANCELLATION_POINT; diff --git a/libc/calls/sigtimedwait.c b/libc/calls/sigtimedwait.c index 4ce46fa95..15afb34d6 100644 --- a/libc/calls/sigtimedwait.c +++ b/libc/calls/sigtimedwait.c @@ -47,10 +47,11 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) { int rc; - char strsig[15]; + char strsig[21]; struct timespec ts; union siginfo_meta si = {0}; BEGIN_CANCELLATION_POINT; + (void)strsig; if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) || (info && !__asan_is_valid(info, sizeof(*info))) || diff --git a/libc/calls/splice.c b/libc/calls/splice.c index 2c161153a..2cfd85a4c 100644 --- a/libc/calls/splice.c +++ b/libc/calls/splice.c @@ -36,8 +36,8 @@ static struct Splice { } g_splice; static bool HasSplice(void) { + int e; bool ok; - int e, rc; e = errno; if (IsLinux()) { // Our testing indicates splice() doesn't work as documneted on diff --git a/libc/calls/struct/filter.internal.h b/libc/calls/struct/filter.internal.h index 7ec704563..b44fec07b 100644 --- a/libc/calls/struct/filter.internal.h +++ b/libc/calls/struct/filter.internal.h @@ -15,7 +15,7 @@ struct sock_filter { struct sock_fprog { unsigned short len; - struct sock_filter *filter; + const struct sock_filter *filter; }; #define BPF_RVAL(code) ((code)&0x18) diff --git a/libc/calls/struct/iovec.internal.h b/libc/calls/struct/iovec.internal.h index 4bb8a2f1f..e2b65790a 100644 --- a/libc/calls/struct/iovec.internal.h +++ b/libc/calls/struct/iovec.internal.h @@ -21,7 +21,7 @@ ssize_t sys_writev_metal(struct Fd *, const struct iovec *, int); ssize_t sys_writev_nt(int, const struct iovec *, int); ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int); ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t); -ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *, +ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, const void *, uint32_t); const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int); diff --git a/libc/calls/struct/termios.internal.h b/libc/calls/struct/termios.internal.h index 244418323..a8e4e4f91 100644 --- a/libc/calls/struct/termios.internal.h +++ b/libc/calls/struct/termios.internal.h @@ -5,7 +5,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -const char *DescribeTermios(char[1024], ssize_t, struct termios *); +const char *DescribeTermios(char[1024], ssize_t, const struct termios *); #define DescribeTermios(rc, tio) DescribeTermios(alloca(1024), rc, tio) diff --git a/libc/calls/struct/timespec.h b/libc/calls/struct/timespec.h index f1f40789e..739cfadad 100644 --- a/libc/calls/struct/timespec.h +++ b/libc/calls/struct/timespec.h @@ -45,7 +45,7 @@ static inline bool timespec_iszero(struct timespec __ts) { return !(__ts.tv_sec | __ts.tv_nsec); } static inline bool timespec_isvalid(struct timespec __ts) { - return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull; + return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull; } #endif /* _COSMO_SOURCE */ diff --git a/libc/calls/struct/timeval.h b/libc/calls/struct/timeval.h index 2d59bf883..4adaa8207 100644 --- a/libc/calls/struct/timeval.h +++ b/libc/calls/struct/timeval.h @@ -42,7 +42,7 @@ static inline bool timeval_iszero(struct timeval __tv) { return !(__tv.tv_sec | __tv.tv_usec); } static inline bool timeval_isvalid(struct timeval __tv) { - return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull; + return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull; } #endif /* _COSMO_SOURCE */ diff --git a/libc/calls/struct/winsize.internal.h b/libc/calls/struct/winsize.internal.h index 928701b12..7647be2b4 100644 --- a/libc/calls/struct/winsize.internal.h +++ b/libc/calls/struct/winsize.internal.h @@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_ int tcgetwinsize_nt(int, struct winsize *); -const char *DescribeWinsize(char[64], int, struct winsize *); +const char *DescribeWinsize(char[64], int, const struct winsize *); #define DescribeWinsize(rc, ws) DescribeWinsize(alloca(64), rc, ws) COSMOPOLITAN_C_END_ diff --git a/libc/calls/tcsetattr-nt.c b/libc/calls/tcsetattr-nt.c index 7ffef7dc6..6681fd690 100644 --- a/libc/calls/tcsetattr-nt.c +++ b/libc/calls/tcsetattr-nt.c @@ -164,7 +164,6 @@ textwindows void __echo_terminal_input(struct Fd *fd, char *p, size_t n) { textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) { bool32 ok; - int infd; int64_t hInput, hOutput; uint32_t inmode, outmode; if (__isfdkind(fd, kFdConsole)) { diff --git a/libc/calls/ttyname_r.c b/libc/calls/ttyname_r.c index 4823cb81f..dcc93a164 100644 --- a/libc/calls/ttyname_r.c +++ b/libc/calls/ttyname_r.c @@ -37,7 +37,6 @@ static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) { uint32_t mode; - const char *s; if (GetConsoleMode(g_fds.p[fd].handle, &mode)) { if (strlcpy(buf, (mode & kNtEnableVirtualTerminalInput) ? "CONIN$" : "CONOUT$", diff --git a/libc/calls/uname.c b/libc/calls/uname.c index 253abff12..56a3e3745 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -66,7 +66,6 @@ static void GetBsdStr(int c0, int c1, char *s) { // Gets NT name ignoring errors with guaranteed NUL-terminator. static textwindows void GetNtName(char *name, int kind) { - uint32_t n = SYS_NMLN; char16_t name16[256]; uint32_t size = ARRAYLEN(name16); if (GetComputerNameEx(kind, name16, &size)) { diff --git a/libc/calls/unveil.c b/libc/calls/unveil.c index 89d99dcd0..eabba9efc 100644 --- a/libc/calls/unveil.c +++ b/libc/calls/unveil.c @@ -211,8 +211,8 @@ static int unveil_init(void) { static char *JoinPaths(char *buf, size_t size, const char *path, const char *other) { size_t pathlen, otherlen; - if (!other) return path; - if (!path) return 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/calls/utimensat-xnu.c b/libc/calls/utimensat-xnu.c index d6c801adf..fb571c7f2 100644 --- a/libc/calls/utimensat-xnu.c +++ b/libc/calls/utimensat-xnu.c @@ -28,7 +28,6 @@ int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2], int flags) { - int i; struct stat st; struct timeval now, tv[2]; if (flags) return einval(); diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index d6c52a128..432744be9 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -81,11 +81,11 @@ static textwindows void AddProcessStats(int64_t h, struct rusage *ru) { static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { + int pids[64]; int64_t handle; - int rc, pids[64]; + uint32_t i, count; int64_t handles[64]; uint32_t dwExitCode; - uint32_t i, j, count; if (*pid != -1 && *pid != 0) { if (*pid < 0) { // XXX: this is sloppy diff --git a/libc/calls/wincrash.c b/libc/calls/wincrash.c index 6242f7b5b..f76303c79 100644 --- a/libc/calls/wincrash.c +++ b/libc/calls/wincrash.c @@ -32,7 +32,7 @@ #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sig.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" #ifdef __x86_64__ diff --git a/libc/calls/winstdin1.c b/libc/calls/winstdin1.c index 4bf156e2e..9b91c442d 100644 --- a/libc/calls/winstdin1.c +++ b/libc/calls/winstdin1.c @@ -101,7 +101,6 @@ Finish: // this makes it possible for our read() implementation to periodically // poll for signals while performing a blocking overlapped io operation dontasan dontubsan dontinstrument textwindows void WinMainStdin(void) { - uint32_t mode; char16_t pipename[64]; int64_t hStdin, hWriter, hReader, hThread, hSemaphore; if (!SupportsWindows()) return; diff --git a/libc/calls/write.c b/libc/calls/write.c index 504cc52cb..e32aaa62e 100644 --- a/libc/calls/write.c +++ b/libc/calls/write.c @@ -79,9 +79,9 @@ ssize_t write(int fd, const void *buf, size_t size) { } else if (fd >= g_fds.n) { rc = ebadf(); } else if (IsMetal()) { - rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){buf, size}, 1); + rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){(void *)buf, size}, 1); } else if (IsWindows()) { - rc = sys_writev_nt(fd, &(struct iovec){buf, size}, 1); + rc = sys_writev_nt(fd, &(struct iovec){(void *)buf, size}, 1); } else { rc = enosys(); } diff --git a/libc/dns/getaddrinfo.c b/libc/dns/getaddrinfo.c index c6c56c72e..a799ca4bf 100644 --- a/libc/dns/getaddrinfo.c +++ b/libc/dns/getaddrinfo.c @@ -47,7 +47,6 @@ int getaddrinfo(const char *name, const char *service, const struct addrinfo *hints, struct addrinfo **res) { int rc, port; const char *canon; - size_t protolen; struct addrinfo *ai; char proto[32]; port = 0; diff --git a/libc/dns/getnameinfo.c b/libc/dns/getnameinfo.c index c6c15ba36..a610eeea4 100644 --- a/libc/dns/getnameinfo.c +++ b/libc/dns/getnameinfo.c @@ -58,7 +58,7 @@ int getnameinfo(const struct sockaddr *addr, uint32_t addrlen, char *name, int flags) { char *p, rdomain[1 + sizeof "255.255.255.255.in-addr.arpa"]; char info[NI_MAXHOST + 1]; - int rc, port; + int port; uint8_t *ip; unsigned int valid_flags; diff --git a/libc/elf/elf.h b/libc/elf/elf.h index d6a580cb9..294240683 100644 --- a/libc/elf/elf.h +++ b/libc/elf/elf.h @@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_ /*───────────────────────────────────────────────────────────────────────────│─╗ │ cosmopolitan § executable linkable format ─╬─│┼ ╚────────────────────────────────────────────────────────────────────────────│*/ +/* clang-format off */ bool IsElfSymbolContent(const Elf64_Sym *); bool IsElf64Binary(const Elf64_Ehdr *, size_t); @@ -18,11 +19,11 @@ Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *); Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *); Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half); -Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *, size_t, char *, const char *); -const char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word); +Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *); +char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word); void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *); void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *); -const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *); +char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *); char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t); COSMOPOLITAN_C_END_ diff --git a/libc/elf/findelfsectionbyname.c b/libc/elf/findelfsectionbyname.c index 5d5a6878a..9e69f2633 100644 --- a/libc/elf/findelfsectionbyname.c +++ b/libc/elf/findelfsectionbyname.c @@ -28,7 +28,7 @@ * @param mapsize is the number of bytes past `elf` we can access * @return pointer to section header within image, or null */ -Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *elf, size_t mapsize, +Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *elf, size_t mapsize, char *shdrstrtab, const char *name) { long i; Elf64_Shdr *shdr; diff --git a/libc/elf/getelfsectionaddress.c b/libc/elf/getelfsectionaddress.c index 8c5f4168e..daa8157ff 100644 --- a/libc/elf/getelfsectionaddress.c +++ b/libc/elf/getelfsectionaddress.c @@ -39,7 +39,7 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated const Elf64_Shdr *shdr) { // foreign Elf64_Off last; if (!shdr) return 0; - if (!shdr->sh_size) return elf; + 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; diff --git a/libc/elf/getelfsectionname.c b/libc/elf/getelfsectionname.c index 3b968281a..f1792a036 100644 --- a/libc/elf/getelfsectionname.c +++ b/libc/elf/getelfsectionname.c @@ -18,8 +18,8 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/elf/elf.h" -const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize, - Elf64_Shdr *shdr) { +char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize, + const Elf64_Shdr *shdr) { if (!shdr) return 0; return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize), shdr->sh_name); diff --git a/libc/elf/getelfstring.c b/libc/elf/getelfstring.c index 2afa97f69..8cad3b48b 100644 --- a/libc/elf/getelfstring.c +++ b/libc/elf/getelfstring.c @@ -39,10 +39,10 @@ * 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or * 4. an arithmetic overflow occurred */ -const char *GetElfString(const Elf64_Ehdr *elf, // validated - size_t mapsize, // validated - const char *strtab, // validated - Elf64_Word i) { // foreign +char *GetElfString(const Elf64_Ehdr *elf, // validated + size_t mapsize, // validated + const char *strtab, // validated + Elf64_Word i) { // foreign const char *e; if (!i) return ""; e = (const char *)elf; @@ -50,5 +50,5 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated if (i >= mapsize) return 0; if (strtab + i >= e + mapsize) return 0; if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0; - return (const char *)strtab + i; + return (char *)strtab + i; } diff --git a/libc/elf/getelfstringtable.c b/libc/elf/getelfstringtable.c index 623434ec8..85c569ced 100644 --- a/libc/elf/getelfstringtable.c +++ b/libc/elf/getelfstringtable.c @@ -41,7 +41,7 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, // const char *section_name) { int i; char *name; - Elf64_Shdr *shdr; + const Elf64_Shdr *shdr; for (i = 0; i < elf->e_shnum; ++i) { if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) && shdr->sh_type == SHT_STRTAB && diff --git a/libc/elf/tinyelf.internal.h b/libc/elf/tinyelf.internal.h index bbe4b1084..23e9dc52e 100644 --- a/libc/elf/tinyelf.internal.h +++ b/libc/elf/tinyelf.internal.h @@ -22,7 +22,7 @@ COSMOPOLITAN_C_START_ ((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \ (unsigned)(e)->e_shentsize * (i))) -static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) { +static inline char *GetStrtab(const Elf64_Ehdr *e, size_t *n) { int i; char *name; Elf64_Shdr *shdr; @@ -39,7 +39,7 @@ static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) { return 0; } -static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) { +static inline Elf64_Sym *GetSymtab(const Elf64_Ehdr *e, Elf64_Xword *n) { int i; Elf64_Shdr *shdr; for (i = e->e_shnum; i-- > 0;) { @@ -52,9 +52,10 @@ static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) { return 0; } -static inline void GetImageRange(Elf64_Ehdr *elf, intptr_t *x, intptr_t *y) { +static inline void GetImageRange(const Elf64_Ehdr *elf, intptr_t *x, + intptr_t *y) { unsigned i; - Elf64_Phdr *phdr; + const Elf64_Phdr *phdr; intptr_t start, end, pstart, pend; start = INTPTR_MAX; end = 0; diff --git a/libc/fmt/fmt.h b/libc/fmt/fmt.h index b794b78de..f7a65f4ed 100644 --- a/libc/fmt/fmt.h +++ b/libc/fmt/fmt.h @@ -17,7 +17,7 @@ int snprintf(char *, size_t, const char *, ...) printfesque(3) dontthrow nocallback; int vsnprintf(char *, size_t, const char *, va_list) dontthrow nocallback; -int sprintf(char *, const char *, ...) printfesque(2) dontthrow nocallback; +int sprintf(char *, const char *, ...) dontthrow nocallback; int vsprintf(char *, const char *, va_list) dontthrow nocallback; int sscanf(const char *, const char *, ...) scanfesque(2); diff --git a/libc/fmt/leb128.h b/libc/fmt/leb128.h index e7a0175e7..a8681b8a9 100644 --- a/libc/fmt/leb128.h +++ b/libc/fmt/leb128.h @@ -14,7 +14,7 @@ char *sleb64(char *, int64_t); char *zleb64(char[hasatleast 10], int64_t); char *uleb64(char[hasatleast 10], uint64_t); int unzleb64(const char *, size_t, int64_t *); -int unuleb64(char *, size_t, uint64_t *); +int unuleb64(const char *, size_t, uint64_t *); COSMOPOLITAN_C_END_ #endif /* _COSMO_SOURCE */ diff --git a/libc/fmt/magnumstrs.internal.h b/libc/fmt/magnumstrs.internal.h index b8338a1de..77833499c 100644 --- a/libc/fmt/magnumstrs.internal.h +++ b/libc/fmt/magnumstrs.internal.h @@ -28,9 +28,9 @@ extern const struct MagnumStr kSockOptnames[]; extern const struct MagnumStr kTcpOptnames[]; extern const struct MagnumStr kPollNames[]; -char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int); +const char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int); -__funline char *GetMagnumStr(const struct MagnumStr *ms, int x) { +__funline const char *GetMagnumStr(const struct MagnumStr *ms, int x) { int i; for (i = 0; ms[i].x != MAGNUM_TERMINATOR; ++i) { if (x == MAGNUM_NUMBER(ms, i)) { @@ -44,7 +44,7 @@ __funline char *GetMagnumStr(const struct MagnumStr *ms, int x) { * Converts errno value to descriptive sentence. * @return non-null rodata string or null if not found */ -__funline char *_strerdoc(int x) { +__funline const char *_strerdoc(int x) { if (x) { return GetMagnumStr(kErrnoDocs, x); } else { @@ -56,7 +56,7 @@ __funline char *_strerdoc(int x) { * Converts errno value to symbolic name. * @return non-null rodata string or null if not found */ -__funline char *_strerrno(int x) { +__funline const char *_strerrno(int x) { if (x) { return GetMagnumStr(kErrnoNames, x); } else { diff --git a/libc/fmt/strtol.c b/libc/fmt/strtol.c index 807b35188..3cd2c40d9 100644 --- a/libc/fmt/strtol.c +++ b/libc/fmt/strtol.c @@ -53,7 +53,7 @@ long strtol(const char *s, char **endptr, int base) { char t = 0; long x = 0; int d, c = *s; - CONSUME_SPACES(s, c); + CONSUME_SPACES(char, s, c); GET_SIGN(s, c, d); GET_RADIX(s, c, base); if ((c = kBase36[c & 255]) && --c < base) { @@ -67,7 +67,9 @@ long strtol(const char *s, char **endptr, int base) { } while ((c = kBase36[*++s & 255]) && --c < base); } } - if (t && endptr) *endptr = s; + if (t && endptr) { + *endptr = (char *)s; + } return x; } diff --git a/libc/fmt/strtol.internal.h b/libc/fmt/strtol.internal.h index 3be9d6cce..04580c636 100644 --- a/libc/fmt/strtol.internal.h +++ b/libc/fmt/strtol.internal.h @@ -2,8 +2,8 @@ #define COSMOPOLITAN_LIBC_FMT_STRTOL_H_ #include "libc/errno.h" -#define CONSUME_SPACES(s, c) \ - if (endptr) *endptr = s; \ +#define CONSUME_SPACES(t, s, c) \ + if (endptr) *endptr = (t *)(s); \ while (c == ' ' || c == '\t') c = *++s #define GET_SIGN(s, c, d) \ diff --git a/libc/fmt/strtoul.c b/libc/fmt/strtoul.c index d04e69a13..af0aaf26e 100644 --- a/libc/fmt/strtoul.c +++ b/libc/fmt/strtoul.c @@ -42,20 +42,24 @@ unsigned long strtoul(const char *s, char **endptr, int base) { char t = 0; int d, c = *s; unsigned long x = 0; - CONSUME_SPACES(s, c); + CONSUME_SPACES(char, s, c); GET_SIGN(s, c, d); GET_RADIX(s, c, base); if ((c = kBase36[c & 255]) && --c < base) { t |= 1; do { if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) { - if (endptr) *endptr = s + 1; + if (endptr) { + *endptr = (char *)(s + 1); + } errno = ERANGE; return ULONG_MAX; } } while ((c = kBase36[*++s & 255]) && --c < base); } - if (t && endptr) *endptr = s; + if (t && endptr) { + *endptr = (char *)s; + } return d > 0 ? x : -x; } diff --git a/libc/fmt/unuleb64.c b/libc/fmt/unuleb64.c index 80c83a771..cf82a3e98 100644 --- a/libc/fmt/unuleb64.c +++ b/libc/fmt/unuleb64.c @@ -26,7 +26,7 @@ * @param x receives number number * @return bytes decoded or -1 on error */ -int unuleb64(char *p, size_t n, uint64_t *x) { +int unuleb64(const char *p, size_t n, uint64_t *x) { int k; size_t i; uint64_t t; diff --git a/libc/fmt/wcstol.c b/libc/fmt/wcstol.c index 3658ddb67..7e2571c88 100644 --- a/libc/fmt/wcstol.c +++ b/libc/fmt/wcstol.c @@ -41,7 +41,7 @@ long wcstol(const wchar_t *s, wchar_t **endptr, int base) { char t = 0; long x = 0; int d, c = *s; - CONSUME_SPACES(s, c); + CONSUME_SPACES(wchar_t, s, c); GET_SIGN(s, c, d); GET_RADIX(s, c, base); if ((c = kBase36[c & 255]) && --c < base) { @@ -55,7 +55,9 @@ long wcstol(const wchar_t *s, wchar_t **endptr, int base) { } while ((c = kBase36[*++s & 255]) && --c < base); } } - if (t && endptr) *endptr = s; + if (t && endptr) { + *endptr = (wchar_t *)s; + } return x; } diff --git a/libc/fmt/wcstoul.c b/libc/fmt/wcstoul.c index 7aeb4dbff..6c3865ccb 100644 --- a/libc/fmt/wcstoul.c +++ b/libc/fmt/wcstoul.c @@ -41,20 +41,24 @@ unsigned long wcstoul(const wchar_t *s, wchar_t **endptr, int base) { char t = 0; int d, c = *s; unsigned long x = 0; - CONSUME_SPACES(s, c); + CONSUME_SPACES(wchar_t, s, c); GET_SIGN(s, c, d); GET_RADIX(s, c, base); if ((c = kBase36[c & 255]) && --c < base) { t |= 1; do { if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) { - if (endptr) *endptr = s + 1; + if (endptr) { + *endptr = (wchar_t *)(s + 1); + } errno = ERANGE; return ULONG_MAX; } } while ((c = kBase36[*++s & 255]) && --c < base); } - if (t && endptr) *endptr = s; + if (t && endptr) { + *endptr = (wchar_t *)s; + } return d > 0 ? x : -x; } diff --git a/libc/integral/c.inc b/libc/integral/c.inc index b8e6bdbfd..d0daf0bf9 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -651,101 +651,13 @@ void abort(void) wontreturn; #define initarray _Section(".init_array") #endif -#ifndef __STRICT_ANSI__ -#if defined(__GNUC__) || defined(__llvm__) -#pragma GCC diagnostic ignored \ - "-Wundef" /* complaints about __ASSEMBLER__/__LINKER__ */ -#pragma GCC diagnostic ignored "-Wsign-compare" /* lint needs to change */ -#pragma GCC diagnostic ignored "-Wtype-limits" /* makes macros unsafe */ -#pragma GCC diagnostic ignored "-Woverflow" /* also breaks macros */ -#pragma GCC diagnostic ignored "-Wformat" /* forces only gnu pf */ -#pragma GCC diagnostic ignored "-Wunused-parameter" /* extreme prejudice */ -#pragma GCC diagnostic ignored "-Wunused-function" /* contradicts dce! */ -#pragma GCC diagnostic ignored "-Wunused-const-variable" /* let me dce */ -#pragma GCC diagnostic ignored "-Wunused-variable" /* belongs in tidy */ -#pragma GCC diagnostic ignored "-Wformat-extra-args" /* is also broken */ -#pragma GCC diagnostic ignored "-Wparentheses" /* annoying tidy */ -#pragma GCC diagnostic ignored "-Wdangling-else" /* come on tidy */ -#pragma GCC diagnostic ignored "-Wformat-security" /* come on tidy */ -#pragma GCC diagnostic ignored "-Wunused-value" /* breaks macros */ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /* libcxx */ +#pragma GCC diagnostic ignored "-Wformat" /* todo: patch gcc */ +#pragma GCC diagnostic ignored "-Wformat-extra-args" /* todo: patch gcc */ +#pragma GCC diagnostic ignored "-Wunused-function" /* contradicts dce */ +#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */ #ifndef __cplusplus -#pragma GCC diagnostic ignored "-Wimplicit-int" -#pragma GCC diagnostic ignored "-Wc++-compat" -#endif /* C++ */ -#endif /* GCC || LLVM */ -#if defined(__GNUC__) && !defined(__llvm__) -/* why we need authorization to name a variable `yn' */ -#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch" -#pragma GCC diagnostic ignored "-Wfree-nonheap-object" /* broken #54202 */ -#ifndef __cplusplus -#if __GNUC__ >= 6 -#pragma GCC diagnostic ignored /* wut */ "-Wdiscarded-qualifiers" -#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-variable" -#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-parameter" -#endif /* GCC6+ */ -#if __GNUC__ >= 8 -#pragma GCC diagnostic ignored "-Wstringop-truncation" -#pragma GCC diagnostic ignored "-Wstringop-overflow" /* breaks strndup */ -#endif /* GCC8+ */ -#if __GNUC__ + 0 >= 9 -#pragma GCC diagnostic ignored /* "always true" breaks dce */ "-Waddress" -#if __GNUC__ >= 11 -#pragma GCC diagnostic ignored /* annoying */ "-Wattributes" -#pragma GCC diagnostic ignored /* orwellian */ "-Wold-style-definition" -#pragma GCC diagnostic ignored /* what? */ "-Wformat-overflow" -#endif /* GCC11+ */ -#endif /* GCC9+ */ -#endif /* !C++ */ -#endif /* GCC && !LLVM */ -#ifdef __llvm__ -#pragma clang diagnostic ignored \ - "-Wincompatible-pointer-types-discards-qualifiers" -#pragma clang diagnostic ignored "-Wbuiltin-requires-header" -#pragma clang diagnostic ignored "-Wparentheses-equality" /*-save-temps*/ -#pragma clang diagnostic ignored "-Wunused-value" /*({-save-temps})*/ -#pragma clang diagnostic ignored "-Wstring-plus-int" /* special ed */ -#pragma clang diagnostic ignored "-Wunused-value" /* extreme prejudice */ -#pragma clang diagnostic ignored "-Wbuiltin-requires-header" -#pragma clang diagnostic ignored \ - "-Wincompatible-pointer-types-discards-qualifiers" -#endif /* !GCC && LLVM */ -#endif /* ANSI */ - -#ifndef __W__ -#ifndef __STRICT_ANSI__ -#if defined(__GNUC__) || defined(__llvm__) -#pragma GCC diagnostic error "-Wpointer-arith" -#pragma GCC diagnostic error "-Wnonnull" -#pragma GCC diagnostic error "-Wunused-result" -#pragma GCC diagnostic error "-Wstrict-aliasing" -#ifndef __cplusplus -#pragma GCC diagnostic error "-Wimplicit-function-declaration" -#if __GNUC__ >= 6 -#pragma GCC diagnostic error "-Wincompatible-pointer-types" -#if __GNUC__ >= 8 -#pragma GCC diagnostic error "-Wmultistatement-macros" -#pragma GCC diagnostic error "-Wpacked-not-aligned" -#pragma GCC diagnostic error "-Wcast-align=strict" -#pragma GCC diagnostic error "-Wif-not-aligned" -#endif /* GCC 8+ */ -#endif /* GCC 6+ */ -#endif /* __cplusplus */ -#endif /* GCC || LLVM */ -#if defined(__GNUC__) && !defined(__llvm__) -#pragma GCC diagnostic error "-Wwrite-strings" -#pragma GCC diagnostic error "-Wtrampolines" -#if __GNUC__ >= 6 -#pragma GCC diagnostic error "-Wnonnull-compare" -#elif __GNUC__ >= 9 -#pragma GCC diagnostic error /* e.g. fabs not abs */ "-Wabsolute-value" -#endif /* GCC 6+ */ -#endif /* GCC && !LLVM */ -#ifdef __llvm__ -#pragma clang diagnostic error "-Wassume" -#endif /* !GCC && LLVM */ -#endif /* ANSI */ -#endif /* -w */ +#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bulls */ +#endif #ifndef __STRICT_ANSI__ #ifdef __x86_64__ @@ -829,9 +741,13 @@ void abort(void) wontreturn; #define __strong_reference(sym, alias) __weak_reference(sym, alias) #endif +#if defined(__GNUC__) || defined(__llvm__) #define __funline \ extern __inline \ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +#else +#define __funline static inline +#endif #define MACHINE_CODE_ANALYSIS_BEGIN_ #define MACHINE_CODE_ANALYSIS_END_ diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index dc1d22d83..7e0aa53ae 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -129,13 +129,13 @@ struct AsanExtra { }; struct AsanSourceLocation { - const char *filename; + char *filename; int line; int column; }; struct AsanAccessInfo { - const char *addr; + char *addr; const uintptr_t first_bad_addr; size_t size; bool iswrite; @@ -143,7 +143,7 @@ struct AsanAccessInfo { }; struct AsanGlobal { - const char *addr; + char *addr; size_t size; size_t size_with_redzone; const void *name; @@ -517,7 +517,6 @@ struct AsanFault __asan_check(const void *p, long n) { */ struct AsanFault __asan_check_str(const char *p) { uint64_t w; - struct AsanFault f; signed char c, k, *s; s = SHADOW(p); if (OverlapsShadowSpace(p, 1)) { @@ -1059,7 +1058,8 @@ static struct AsanExtra *__asan_get_extra(const void *p, size_t *c) { long x, n; struct AsanExtra *e; f = (intptr_t)p >> 16; - if (!kisdangerous(p) && (n = _weaken(dlmalloc_usable_size)(p)) > sizeof(*e) && + if (!kisdangerous(p) && + (n = _weaken(dlmalloc_usable_size)((void *)p)) > sizeof(*e) && !ckd_add(&x, (intptr_t)p, n) && x <= 0x800000000000 && (LIKELY(f == (int)((x - 1) >> 16)) || !kisdangerous((void *)(x - 1))) && (LIKELY(f == (int)((x = x - sizeof(*e)) >> 16)) || @@ -1227,7 +1227,6 @@ void *__asan_memalign(size_t align, size_t size) { } void *__asan_calloc(size_t n, size_t m) { - char *p; struct AsanTrace bt; __asan_trace(&bt, RBP); if (ckd_mul(&n, n, m)) n = -1; @@ -1498,7 +1497,7 @@ void __asan_init(int argc, char **argv, char **envp, intptr_t *auxv) { __asan_shadow_existing_mappings(); __asan_map_shadow((uintptr_t)__executable_start, _end - __executable_start); __asan_map_shadow(0, 4096); - __asan_poison(0, getauxval(AT_PAGESZ), kAsanNullPage); + __asan_poison((void *)__veil("r", 0L), getauxval(AT_PAGESZ), kAsanNullPage); if (!IsWindows()) { sys_mprotect((void *)0x7fff8000, 0x10000, PROT_READ); } diff --git a/libc/intrin/countbits.c b/libc/intrin/countbits.c index 5e5906e99..f6c0f3c4f 100644 --- a/libc/intrin/countbits.c +++ b/libc/intrin/countbits.c @@ -29,18 +29,17 @@ * @note 30gbps on Nehalem (Intel 2008+) otherwise 3gbps */ size_t _countbits(const void *a, size_t n) { - int i; size_t t; unsigned b; uint64_t x; - long Ai, Bi, Ci, Di; - long Ao, Bo, Co, Do; const char *p, *e; t = 0; p = a; e = p + n; if (!IsTiny()) { #ifdef __x86_64__ + long Ai, Bi, Ci, Di; + long Ao, Bo, Co, Do; if (X86_HAVE(POPCNT)) { while (p + sizeof(long) * 4 <= e) { __builtin_memcpy(&Ai, p + 000, sizeof(long)); diff --git a/libc/intrin/cp.c b/libc/intrin/cp.c index 623aae909..9e11a916f 100644 --- a/libc/intrin/cp.c +++ b/libc/intrin/cp.c @@ -28,7 +28,7 @@ int begin_cancellation_point(void) { int state = 0; struct CosmoTib *tib; struct PosixThread *pt; - if (__enable_tls) { + if (__tls_enabled) { tib = __get_tls(); if ((pt = (struct PosixThread *)tib->tib_pthread)) { state = pt->flags & PT_INCANCEL; @@ -41,7 +41,7 @@ int begin_cancellation_point(void) { void end_cancellation_point(int state) { struct CosmoTib *tib; struct PosixThread *pt; - if (__enable_tls) { + if (__tls_enabled) { tib = __get_tls(); if ((pt = (struct PosixThread *)tib->tib_pthread)) { pt->flags &= ~PT_INCANCEL; diff --git a/libc/intrin/createfile.c b/libc/intrin/createfile.c index d2fa41201..944584801 100644 --- a/libc/intrin/createfile.c +++ b/libc/intrin/createfile.c @@ -38,13 +38,14 @@ __msabi extern typeof(Sleep) *const __imp_Sleep; * @return handle, or -1 on failure w/ `errno` set appropriately * @note this wrapper takes care of ABI, STRACE(), and __winerr() */ -textwindows int64_t CreateFile(const char16_t *lpFileName, // - uint32_t dwDesiredAccess, // - uint32_t dwShareMode, // - struct NtSecurityAttributes *opt_lpSecurity, // - int dwCreationDisposition, // - uint32_t dwFlagsAndAttributes, // - int64_t opt_hTemplateFile) { +textwindows int64_t +CreateFile(const char16_t *lpFileName, // + uint32_t dwDesiredAccess, // + uint32_t dwShareMode, // + const struct NtSecurityAttributes *opt_lpSecurity, // + int dwCreationDisposition, // + uint32_t dwFlagsAndAttributes, // + int64_t opt_hTemplateFile) { int64_t hHandle; uint32_t micros = 1; TryAgain: diff --git a/libc/intrin/describeflags.c b/libc/intrin/describeflags.c index 84bf670c3..2c1d22dad 100644 --- a/libc/intrin/describeflags.c +++ b/libc/intrin/describeflags.c @@ -19,12 +19,12 @@ #include "libc/intrin/describeflags.internal.h" // TODO(jart): Fork this function into ASAN and non-ASAN versions. -const char *DescribeFlags(char *p, size_t n, struct DescribeFlags *d, size_t m, - const char *prefix, unsigned x) { +const char *DescribeFlags(char *p, size_t n, const struct DescribeFlags *d, + size_t m, const char *prefix, unsigned x) { bool t; char b[21]; size_t i, j, k; - for (t = i = j = 0; j < m; ++j) { + for (t = false, i = j = 0; j < m; ++j) { if (d[j].flag && d[j].flag != -1 && (x & d[j].flag) == d[j].flag) { x &= ~d[j].flag; if (t) { diff --git a/libc/intrin/describeflags.internal.h b/libc/intrin/describeflags.internal.h index cd585e122..78a40448c 100644 --- a/libc/intrin/describeflags.internal.h +++ b/libc/intrin/describeflags.internal.h @@ -9,7 +9,7 @@ struct thatispacked DescribeFlags { const char *name; }; -const char *DescribeFlags(char *, size_t, struct DescribeFlags *, size_t, +const char *DescribeFlags(char *, size_t, const struct DescribeFlags *, size_t, const char *, unsigned); const char *DescribeArchPrctlCode(char[12], int); @@ -54,7 +54,7 @@ const char *DescribeRemapFlags(char[48], int); const char *DescribeRlimitName(char[20], int); const char *DescribeSchedPolicy(char[48], int); const char *DescribeSeccompOperation(int); -const char *DescribeSiCode(char[17], int, int); +const char *DescribeSiCode(char[20], int, int); const char *DescribeSleepFlags(char[16], int); const char *DescribeSockLevel(char[12], int); const char *DescribeSockOptname(char[32], int, int); @@ -105,7 +105,7 @@ const char *DescribeWhichPrio(char[12], int); #define DescribeRemapFlags(x) DescribeRemapFlags(alloca(48), x) #define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl) #define DescribeSchedPolicy(x) DescribeSchedPolicy(alloca(48), x) -#define DescribeSiCode(x, y) DescribeSiCode(alloca(17), x, y) +#define DescribeSiCode(x, y) DescribeSiCode(alloca(20), x, y) #define DescribeSleepFlags(x) DescribeSleepFlags(alloca(16), x) #define DescribeSockLevel(x) DescribeSockLevel(alloca(12), x) #define DescribeSockOptname(x, y) DescribeSockOptname(alloca(32), x, y) diff --git a/libc/intrin/describeframe.c b/libc/intrin/describeframe.c index a651a825f..486b73c21 100644 --- a/libc/intrin/describeframe.c +++ b/libc/intrin/describeframe.c @@ -61,7 +61,6 @@ static const char *GetFrameName(int x) { } const char *(DescribeFrame)(char buf[32], int x) { - char *p; if (IsShadowFrame(x)) { ksnprintf(buf, 32, "%s %s %.8x", GetFrameName(x), GetFrameName(FRAME(UNSHADOW(ADDR_32_TO_48(x)))), diff --git a/libc/intrin/describemagnums.c b/libc/intrin/describemagnums.c index 18e18565e..b8a877457 100644 --- a/libc/intrin/describemagnums.c +++ b/libc/intrin/describemagnums.c @@ -20,8 +20,9 @@ #include "libc/fmt/magnumstrs.internal.h" #include "libc/str/str.h" -char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, int x) { - char *s; +const char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, + int x) { + const char *s; if (x == 127) return "CLOCK_INVALID"; if ((s = GetMagnumStr(m, x))) { stpcpy(stpcpy(b, p), s); diff --git a/libc/intrin/describepollfds.c b/libc/intrin/describepollfds.c index 15a14eaeb..0390120f6 100644 --- a/libc/intrin/describepollfds.c +++ b/libc/intrin/describepollfds.c @@ -32,8 +32,7 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds, size_t nfds) { char b64[64]; - const char *d; - int i, j, o = 0; + int i, o = 0; if (!fds) return "NULL"; if ((!IsAsan() && kisdangerous(fds)) || diff --git a/libc/intrin/describesicode.c b/libc/intrin/describesicode.c index d7df1ec8e..be6c4bd6b 100644 --- a/libc/intrin/describesicode.c +++ b/libc/intrin/describesicode.c @@ -30,7 +30,7 @@ static bool IsSiUser(int si_code) { } } -static void NameIt(char p[17], const char *s, int si_code) { +static void NameIt(char p[20], const char *s, int si_code) { p = stpcpy(p, s); FormatInt32(p, si_code); } @@ -38,7 +38,7 @@ static void NameIt(char p[17], const char *s, int si_code) { /** * Returns symbolic name for siginfo::si_code value. */ -const char *(DescribeSiCode)(char b[17], int sig, int si_code) { +const char *(DescribeSiCode)(char b[20], int sig, int si_code) { NameIt(b, "SI_", si_code); if (si_code == SI_QUEUE) { strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */ diff --git a/libc/intrin/describesockoptname.c b/libc/intrin/describesockoptname.c index 8215fb0c3..1a4c4810f 100644 --- a/libc/intrin/describesockoptname.c +++ b/libc/intrin/describesockoptname.c @@ -26,8 +26,8 @@ * Describes setsockopt() optname arguments. */ const char *(DescribeSockOptname)(char buf[32], int l, int x) { - int i; - char *s, *p; + char *p; + const char *s; const struct MagnumStr *ms; p = buf; if (x) { diff --git a/libc/intrin/describetermios.c b/libc/intrin/describetermios.c index 358ad32ff..921f09ed2 100644 --- a/libc/intrin/describetermios.c +++ b/libc/intrin/describetermios.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/struct/termios.h" +#include "libc/calls/struct/termios.internal.h" #include "libc/dce.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/describeflags.internal.h" @@ -28,7 +29,8 @@ #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *(DescribeTermios)(char buf[N], ssize_t rc, struct termios *tio) { +const char *(DescribeTermios)(char buf[N], ssize_t rc, + const struct termios *tio) { int o = 0; char b128[128]; diff --git a/libc/intrin/describewinsize.c b/libc/intrin/describewinsize.c index 29a711ba4..835f5ae77 100644 --- a/libc/intrin/describewinsize.c +++ b/libc/intrin/describewinsize.c @@ -29,11 +29,8 @@ #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *(DescribeWinsize)(char buf[N], int rc, struct winsize *ws) { - char b64[64]; - const char *d; - int i, j, o = 0; - +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 ((!IsAsan() && kisdangerous(ws)) || diff --git a/libc/intrin/ffs.c b/libc/intrin/ffs.c index 257adb0ab..86e617e52 100644 --- a/libc/intrin/ffs.c +++ b/libc/intrin/ffs.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/nexgen32e/ffs.h" /** * Finds lowest set bit in word. @@ -27,7 +28,7 @@ int ffs(int x) { /** * Finds lowest set bit in word. */ -long ffsl(long x) { +int ffsl(long x) { return __builtin_ffsl(x); } diff --git a/libc/intrin/g_fds.c b/libc/intrin/g_fds.c index 29455658a..9bb557520 100644 --- a/libc/intrin/g_fds.c +++ b/libc/intrin/g_fds.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/internal.h" #include "libc/calls/state.internal.h" +#include "libc/calls/struct/fd.internal.h" #include "libc/calls/ttydefaults.h" #include "libc/intrin/atomic.h" #include "libc/intrin/extend.internal.h" @@ -26,12 +26,10 @@ #include "libc/intrin/nomultics.internal.h" #include "libc/intrin/pushpop.internal.h" #include "libc/intrin/weaken.h" -#include "libc/macros.internal.h" #include "libc/nt/runtime.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" -#include "libc/str/str.h" #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/o.h" #include "libc/thread/thread.h" diff --git a/libc/intrin/kprintf.greg.c b/libc/intrin/kprintf.greg.c index 653580b14..b95e4535e 100644 --- a/libc/intrin/kprintf.greg.c +++ b/libc/intrin/kprintf.greg.c @@ -74,7 +74,7 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" #include "libc/vga/vga.internal.h" #define KGETINT(x, va, t, s) \ @@ -134,14 +134,13 @@ __msabi extern typeof(WriteFile) *const __imp_WriteFile; long __klog_handle; extern struct SymbolTable *__symtab; -privileged static inline char *kadvance(char *p, char *e, long n) { +__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; return (char *)t; } -privileged static char *kemitquote(char *p, char *e, signed char t, - unsigned c) { +__funline char *kemitquote(char *p, char *e, signed char t, unsigned c) { if (t) { if (p < e) { *p = t < 0 ? 'u' : 'L'; @@ -155,27 +154,27 @@ privileged static char *kemitquote(char *p, char *e, signed char t, return p; } -privileged static inline bool kiskernelpointer(const void *p) { +__funline bool kiskernelpointer(const void *p) { return 0x7f0000000000 <= (intptr_t)p && (intptr_t)p < 0x800000000000; } -privileged static inline bool kistextpointer(const void *p) { +__funline bool kistextpointer(const void *p) { return __executable_start <= (const unsigned char *)p && (const unsigned char *)p < _etext; } -privileged static inline bool kisimagepointer(const void *p) { +__funline bool kisimagepointer(const void *p) { return __executable_start <= (const unsigned char *)p && (const unsigned char *)p < _end; } -privileged static inline bool kischarmisaligned(const char *p, signed char t) { +__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); return false; } -privileged static inline bool kismemtrackhosed(void) { +__funline bool kismemtrackhosed(void) { return !((_weaken(_mmi)->i <= _weaken(_mmi)->n) && (_weaken(_mmi)->p == _weaken(_mmi)->s || _weaken(_mmi)->p == (struct MemoryInterval *)kMemtrackStart)); @@ -319,7 +318,7 @@ privileged long kloghandle(void) { hand = STDERR_FILENO; } else if (IsWindows()) { uint32_t e, n; - const char16_t path[512]; + char16_t path[512]; e = __imp_GetLastError(); n = __imp_GetEnvironmentVariableW(u"KPRINTF_LOG", path, 512); if (!n && __imp_GetLastError() == kNtErrorEnvvarNotFound) { @@ -389,7 +388,6 @@ privileged void klog(const char *b, size_t n) { #ifdef __x86_64__ int e; long h; - bool cf; size_t i; uint16_t dx; uint32_t wrote; @@ -442,7 +440,7 @@ privileged void klog(const char *b, size_t n) { privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va) { - int si, y; + int si; wint_t t, u; const char *abet; signed char type; diff --git a/libc/intrin/memchr.c b/libc/intrin/memchr.c index 690680de3..b4a79aac2 100644 --- a/libc/intrin/memchr.c +++ b/libc/intrin/memchr.c @@ -40,10 +40,8 @@ dontasan static inline const unsigned char *memchr_sse(const unsigned char *s, unsigned char c, size_t n) { size_t i; - unsigned k; unsigned m; - xmm_t v, *p; - xmm_t t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; + xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; for (; n >= 16; n -= 16, s += 16) { v = *(const xmm_t *)s; m = __builtin_ia32_pmovmskb128(v == t); diff --git a/libc/intrin/memmove.c b/libc/intrin/memmove.c index 98c3ae77c..94199b109 100644 --- a/libc/intrin/memmove.c +++ b/libc/intrin/memmove.c @@ -91,7 +91,7 @@ void *memmove(void *dst, const void *src, size_t n) { size_t i; const char *s; uint64_t a, b; - xmm_t v, w, x, y, V, W, X, Y, wut; + xmm_t v, w, x, y, V, W, X, Y; d = dst; s = src; diff --git a/libc/intrin/memrchr.c b/libc/intrin/memrchr.c index 79f07ebdc..63fccbae6 100644 --- a/libc/intrin/memrchr.c +++ b/libc/intrin/memrchr.c @@ -40,7 +40,7 @@ dontasan static inline const unsigned char *memrchr_sse(const unsigned char *s, unsigned char c, size_t n) { size_t i; - unsigned k, m; + unsigned m; xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; for (i = n; i >= 16;) { v = *(const xmm_t *)(s + (i -= 16)); diff --git a/libc/intrin/mman.greg.c b/libc/intrin/mman.greg.c index 1c8523538..1319b5d4f 100644 --- a/libc/intrin/mman.greg.c +++ b/libc/intrin/mman.greg.c @@ -210,7 +210,7 @@ dontasan void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) { */ static dontasan textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) { - uint64_t i, j, *m, p, pe; + uint64_t i; 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. */ @@ -261,8 +261,8 @@ dontasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t, */ dontasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b, uint64_t top) { + uint64_t i, f, v, m; struct Elf64_Phdr *p; - uint64_t i, f, v, m, *e; extern char ape_phdrs[] __attribute__((__weak__)); extern char ape_phdrs_end[] __attribute__((__weak__)); __setup_mman(mm, pml4t, top); diff --git a/libc/intrin/printmemoryintervals.c b/libc/intrin/printmemoryintervals.c index 281a82fb3..74dc9e7e3 100644 --- a/libc/intrin/printmemoryintervals.c +++ b/libc/intrin/printmemoryintervals.c @@ -32,8 +32,8 @@ static bool IsNoteworthyHole(unsigned i, const struct MemoryIntervals *mm) { } void PrintMemoryIntervals(int fd, const struct MemoryIntervals *mm) { - char *p, mappingbuf[8], framebuf[64], sb[16]; long i, w, frames, maptally = 0; + char mappingbuf[8], framebuf[64], sb[16]; for (w = i = 0; i < mm->i; ++i) { w = MAX(w, LengthInt64Thousands(mm->p[i].y + 1 - mm->p[i].x)); } diff --git a/libc/intrin/pthread_key_delete.c b/libc/intrin/pthread_key_delete.c index fce775dd1..4a2fbb4a5 100644 --- a/libc/intrin/pthread_key_delete.c +++ b/libc/intrin/pthread_key_delete.c @@ -34,7 +34,6 @@ * @return 0 on success, or errno on error */ int pthread_key_delete(pthread_key_t k) { - uint64_t mask; unassert(0 <= k && k < PTHREAD_KEYS_MAX); unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire)); atomic_store_explicit(_pthread_key_dtor + k, 0, memory_order_release); diff --git a/libc/intrin/pthread_mutex_lock.c b/libc/intrin/pthread_mutex_lock.c index b1c7e146e..4d6b6432b 100644 --- a/libc/intrin/pthread_mutex_lock.c +++ b/libc/intrin/pthread_mutex_lock.c @@ -65,7 +65,7 @@ * @vforksafe */ int pthread_mutex_lock(pthread_mutex_t *mutex) { - int c, d, t; + int t; if (__vforked) return 0; diff --git a/libc/intrin/pthread_mutex_trylock.c b/libc/intrin/pthread_mutex_trylock.c index e6c6c0660..585735426 100644 --- a/libc/intrin/pthread_mutex_trylock.c +++ b/libc/intrin/pthread_mutex_trylock.c @@ -35,7 +35,7 @@ * @raise ENOTRECOVERABLE if `mutex` is corrupted */ errno_t pthread_mutex_trylock(pthread_mutex_t *mutex) { - int c, d, t; + int t; if (__tls_enabled && // mutex->_type == PTHREAD_MUTEX_NORMAL && // diff --git a/libc/intrin/pthread_mutex_unlock.c b/libc/intrin/pthread_mutex_unlock.c index 9a3b870a1..643eec8ed 100644 --- a/libc/intrin/pthread_mutex_unlock.c +++ b/libc/intrin/pthread_mutex_unlock.c @@ -37,7 +37,7 @@ * @vforksafe */ int pthread_mutex_unlock(pthread_mutex_t *mutex) { - int c, t; + int t; if (__vforked) return 0; diff --git a/libc/intrin/pthread_setspecific.c b/libc/intrin/pthread_setspecific.c index 92ee5088b..dbd847bc3 100644 --- a/libc/intrin/pthread_setspecific.c +++ b/libc/intrin/pthread_setspecific.c @@ -37,6 +37,6 @@ int pthread_setspecific(pthread_key_t k, const void *val) { // ──Quoth POSIX.1-2017 unassert(0 <= k && k < PTHREAD_KEYS_MAX); unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire)); - __get_tls()->tib_keys[k] = val; + __get_tls()->tib_keys[k] = (void *)val; return 0; } diff --git a/libc/intrin/sigcountset.c b/libc/intrin/sigcountset.c index c1eabf01c..1abebe4ad 100644 --- a/libc/intrin/sigcountset.c +++ b/libc/intrin/sigcountset.c @@ -28,7 +28,7 @@ * @asyncsignalsafe */ int sigcountset(const sigset_t *set) { - int r, i, x, y; + int x, y; switch (_NSIG) { case 32: x = (uint32_t)set->__bits[0]; diff --git a/libc/intrin/stracef.greg.c b/libc/intrin/stracef.greg.c index 344f5a072..874bd9ce1 100644 --- a/libc/intrin/stracef.greg.c +++ b/libc/intrin/stracef.greg.c @@ -20,7 +20,7 @@ #include "libc/intrin/strace.internal.h" #include "libc/runtime/runtime.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" privileged void __stracef(const char *fmt, ...) { va_list v; diff --git a/libc/intrin/strchr.c b/libc/intrin/strchr.c index 23a5af58a..0aa822808 100644 --- a/libc/intrin/strchr.c +++ b/libc/intrin/strchr.c @@ -35,7 +35,8 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); dontasan static inline const char *strchr_sse(const char *s, unsigned char c) { unsigned k; unsigned m; - xmm_t v, *p; + const xmm_t *p; + xmm_t v; xmm_t z = {0}; xmm_t n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; k = (uintptr_t)s & 15; diff --git a/libc/intrin/strchrnul.c b/libc/intrin/strchrnul.c index 28d4662e4..5ab232bda 100644 --- a/libc/intrin/strchrnul.c +++ b/libc/intrin/strchrnul.c @@ -36,7 +36,8 @@ dontasan static inline const char *strchrnul_sse(const char *s, unsigned char c) { unsigned k; unsigned m; - xmm_t v, *p; + const xmm_t *p; + xmm_t v; xmm_t z = {0}; xmm_t n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; k = (uintptr_t)s & 15; diff --git a/libc/intrin/strcmp.c b/libc/intrin/strcmp.c index 484ed0a8e..8e085acdd 100644 --- a/libc/intrin/strcmp.c +++ b/libc/intrin/strcmp.c @@ -32,7 +32,7 @@ dontasan int strcmp(const char *a, const char *b) { int c; size_t i = 0; - uint64_t v, w, d; + uint64_t v, w; if (a == b) return 0; if (IsAsan()) __asan_verify_str(a); if (IsAsan()) __asan_verify_str(b); diff --git a/libc/intrin/strerror.c b/libc/intrin/strerror.c index bdcec8121..a09660205 100644 --- a/libc/intrin/strerror.c +++ b/libc/intrin/strerror.c @@ -28,7 +28,7 @@ */ char *strerror(int err) { if (IsTiny()) { - return firstnonnull(_strerrno(err), "EUNKNOWN"); + return (char *)firstnonnull(_strerrno(err), "EUNKNOWN"); } else { _Alignas(1) static char buf[512]; strerror_r(err, buf, sizeof(buf)); diff --git a/libc/intrin/strerror_wr.greg.c b/libc/intrin/strerror_wr.greg.c index b2a27da71..38a98a9a2 100644 --- a/libc/intrin/strerror_wr.greg.c +++ b/libc/intrin/strerror_wr.greg.c @@ -42,17 +42,16 @@ dontasan dontubsan privileged int strerror_wr(int err, uint32_t winerr, char *buf, size_t size) { /* kprintf() weakly depends on this function */ int c, n; - bool wanting; char16_t winmsg[256]; const char *sym, *msg; - wanting = false; + /* wanting = false; */ if (!(sym = _strerrno(err))) { sym = "EUNKNOWN"; - wanting = true; + /* wanting = true; */ } if (!(msg = _strerdoc(err))) { msg = "No error information"; - wanting = true; + /* wanting = true; */ } if (IsTiny()) { if (!sym) sym = "EUNKNOWN"; diff --git a/libc/intrin/strsignal.c b/libc/intrin/strsignal.c index 5afe95e13..ab70a1c5a 100644 --- a/libc/intrin/strsignal.c +++ b/libc/intrin/strsignal.c @@ -18,7 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/str/str.h" -static char g_strsignal[15]; +static char g_strsignal[21]; /** * Returns string describing signal code. diff --git a/libc/intrin/strsignal_r.c b/libc/intrin/strsignal_r.c index 09b57ed70..579598472 100644 --- a/libc/intrin/strsignal_r.c +++ b/libc/intrin/strsignal_r.c @@ -36,15 +36,13 @@ * @asyncsignalsafe * @threadsafe */ -privileged dontdiscard char *strsignal_r(int sig, char buf[15]) { - int i; - char *p; +privileged dontdiscard char *strsignal_r(int sig, char buf[21]) { const char *s; if (!sig) { return "0"; } if ((s = GetMagnumStr(kSignalNames, sig))) { - return s; + return (char *)s; } if (SIGRTMIN <= sig && sig <= SIGRTMAX) { sig -= SIGRTMIN; diff --git a/libc/intrin/unsetenv.c b/libc/intrin/unsetenv.c index fec521936..893d8c577 100644 --- a/libc/intrin/unsetenv.c +++ b/libc/intrin/unsetenv.c @@ -29,8 +29,9 @@ * @raise EINVAL if `s` is an empty string or has a `'='` character */ int unsetenv(const char *s) { - char **p, *t; + char **p; struct Env e; + const char *t; if (!s || !*s) return einval(); for (t = s; *t; ++t) { if (*t == '=') return einval(); diff --git a/libc/intrin/virtualprotect.c b/libc/intrin/virtualprotect.c index 5a16b535d..498a4940f 100644 --- a/libc/intrin/virtualprotect.c +++ b/libc/intrin/virtualprotect.c @@ -32,7 +32,6 @@ textwindows bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect, uint32_t *lpflOldProtect) { bool32 bOk; - char oldbuf[64]; bOk = __imp_VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect); if (!bOk) __winerr(); NTTRACE("VirtualProtect(%p, %'zu, %s, [%s]) → %hhhd% m", lpAddress, dwSize, diff --git a/libc/intrin/winerr.greg.c b/libc/intrin/winerr.greg.c index 28ac57665..af00e7c76 100644 --- a/libc/intrin/winerr.greg.c +++ b/libc/intrin/winerr.greg.c @@ -24,7 +24,7 @@ #include "libc/nt/runtime.h" #include "libc/sock/internal.h" #include "libc/sysv/errfuns.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" /** * Return path for failed Win32 API calls. diff --git a/libc/log/addr2linepath.c b/libc/log/addr2linepath.c index 3ece573b2..b97cb736b 100644 --- a/libc/log/addr2linepath.c +++ b/libc/log/addr2linepath.c @@ -22,7 +22,7 @@ #include "libc/str/str.h" static const char *TryMonoRepoPath(const char *var, const char *path) { - const char buf[PATH_MAX]; + char buf[PATH_MAX]; if (getenv(var)) return 0; if (!isexecutable(path)) return 0; if (*path != '/') { diff --git a/libc/log/attachdebugger.c b/libc/log/attachdebugger.c index 231990f0f..9068766de 100644 --- a/libc/log/attachdebugger.c +++ b/libc/log/attachdebugger.c @@ -94,18 +94,18 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) { sys_dup2(ttyfd, 1, 0); __sys_execve(gdb, (char *const[]){ - "gdb", "--tui", - "-p", pidstr, - se, elf, - "-ex", "set osabi GNU/Linux", - "-ex", "set complaints 0", - "-ex", "set confirm off", - "-ex", layout, - "-ex", "layout reg", - "-ex", "set var g_gdbsync = 1", - "-q", rewind, - breakcmd, "-ex", - "c", NULL, + "gdb", "--tui", + "-p", pidstr, + (char *)se, (char *)elf, + "-ex", "set osabi GNU/Linux", + "-ex", "set complaints 0", + "-ex", "set confirm off", + "-ex", (char *)layout, + "-ex", "layout reg", + "-ex", "set var g_gdbsync = 1", + "-q", (char *)rewind, + breakcmd, "-ex", + "c", NULL, }, environ); abort(); diff --git a/libc/log/backtrace2.c b/libc/log/backtrace2.c index 55ddb8fb9..4afb9b889 100644 --- a/libc/log/backtrace2.c +++ b/libc/log/backtrace2.c @@ -49,12 +49,15 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { ssize_t got; intptr_t addr; size_t i, j, gi; + char *p1, *p2, *p3; int ws, pid, pipefds[2]; struct Garbages *garbage; const struct StackFrame *frame; - char *debugbin, *p1, *p2, *p3, *addr2line; + const char *debugbin, *addr2line; char buf[kBacktraceBufSize], *argv[kBacktraceMaxFrames]; + (void)gi; + // DWARF is a weak standard. Platforms that use LLVM or old GNU // usually can't be counted upon to print backtraces correctly. if (!IsLinux() && !IsWindows()) { @@ -95,7 +98,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) { argv[i++] = "addr2line"; argv[i++] = "-a"; /* filter out w/ shell script wrapper for old versions */ argv[i++] = "-pCife"; - argv[i++] = debugbin; + argv[i++] = (char *)debugbin; garbage = __tls_enabled ? __get_tls()->tib_garbages : 0; gi = garbage ? garbage->i : 0; for (frame = bp; frame && i < kBacktraceMaxFrames - 1; frame = frame->next) { diff --git a/libc/log/backtrace3.c b/libc/log/backtrace3.c index a95921f32..d9f8af4a3 100644 --- a/libc/log/backtrace3.c +++ b/libc/log/backtrace3.c @@ -47,12 +47,12 @@ */ dontinstrument dontasan int PrintBacktraceUsingSymbols( int fd, const struct StackFrame *bp, struct SymbolTable *st) { - bool ok; size_t gi; intptr_t addr; int i, symbol, addend; struct Garbages *garbage; const struct StackFrame *frame; + (void)gi; if (!bp) bp = __builtin_frame_address(0); garbage = __tls_enabled ? __get_tls()->tib_garbages : 0; gi = garbage ? garbage->i : 0; diff --git a/libc/log/checkfail.c b/libc/log/checkfail.c index e4112eabe..e7b030dcc 100644 --- a/libc/log/checkfail.c +++ b/libc/log/checkfail.c @@ -46,7 +46,6 @@ relegated void __check_fail(const char *suffix, // int line, // const char *fmt, // ...) { - char *p; size_t i; va_list va; char hostname[32]; diff --git a/libc/log/gdbexec.c b/libc/log/gdbexec.c index a7d25dc19..00ba480a8 100644 --- a/libc/log/gdbexec.c +++ b/libc/log/gdbexec.c @@ -29,8 +29,8 @@ * Attaches GDB temporarily, to do something like print a variable. */ relegated int(gdbexec)(const char *cmd) { + int pid; struct StackFrame *bp; - int pid, ttyin, ttyout; const char *se, *elf, *gdb; char pidstr[11], breakcmd[40]; if (!(gdb = GetGdbPath())) return -1; @@ -50,8 +50,8 @@ relegated int(gdbexec)(const char *cmd) { "--nh", "-p", pidstr, - se, - elf, + (char *)se, + (char *)elf, "-ex", "set osabi GNU/Linux", "-ex", @@ -64,7 +64,7 @@ relegated int(gdbexec)(const char *cmd) { "-ex", breakcmd, "-ex", - cmd, + (char *)cmd, "-ex", "quit", NULL, diff --git a/libc/log/getcallername.c b/libc/log/getcallername.c index 2aeadcfd8..77f663a83 100644 --- a/libc/log/getcallername.c +++ b/libc/log/getcallername.c @@ -24,7 +24,6 @@ * Returns name of function that called caller function. */ const char *GetCallerName(const struct StackFrame *bp) { - struct SymbolTable *st; if (!bp && (bp = __builtin_frame_address(0))) bp = bp->next; if (bp) return GetSymbolByAddr(bp->addr); return 0; diff --git a/libc/log/libfatal.internal.h b/libc/log/libfatal.internal.h index 05f9db636..a47266dda 100644 --- a/libc/log/libfatal.internal.h +++ b/libc/log/libfatal.internal.h @@ -45,7 +45,7 @@ __funline void *__repmovsb(void *di, const void *si, size_t cx) { return di; #else volatile char *volatile d = di; - volatile char *volatile s = si; + volatile const char *volatile s = si; while (cx--) *d++ = *s++; return (void *)d; #endif @@ -131,7 +131,6 @@ __funline char16_t *__strstr16(const char16_t *haystack, } __funline const char *__strchr(const char *s, unsigned char c) { - char *r; for (;; ++s) { if ((*s & 255) == c) return s; if (!*s) return 0; diff --git a/libc/log/log.h b/libc/log/log.h index 3e0645f66..06d079d82 100644 --- a/libc/log/log.h +++ b/libc/log/log.h @@ -45,7 +45,6 @@ const char *GetAddr2linePath(void); const char *GetGdbPath(void); bool32 IsDebuggerPresent(bool); bool IsRunningUnderMake(void); -const char *GetSiCodeName(int, int); char *GetSymbolByAddr(int64_t); void PrintGarbage(void); void PrintGarbageNumeric(FILE *); diff --git a/libc/log/memsummary.c b/libc/log/memsummary.c index 7aa3b8c56..c0f6518fa 100644 --- a/libc/log/memsummary.c +++ b/libc/log/memsummary.c @@ -17,21 +17,21 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/stdio/dprintf.h" #include "libc/log/log.h" #include "libc/mem/mem.h" +#include "libc/stdio/dprintf.h" void _memsummary(int fd) { struct mallinfo mi; mi = mallinfo(); - (dprintf)(fd, - "arena\t\t%,-12zu\t# space allocated from system\n" - "ordblks\t\t%,-12zu\t# number of free chunks\n" - "hblkhd\t\t%,-12zu\t# space in mmapped regions\n" - "usmblks\t\t%,-12zu\t# maximum total allocated space\n" - "uordblks\t%,-12zu\t# total allocated space\n" - "fordblks\t%,-12zu\t# total free space\n" - "keepcost\t%,-12zu\t# releasable (via malloc_trim) space\n\n", - mi.arena, mi.ordblks, mi.hblkhd, mi.usmblks, mi.uordblks, - mi.fordblks, mi.keepcost); + dprintf(fd, + "arena\t\t%,-12zu\t# space allocated from system\n" + "ordblks\t\t%,-12zu\t# number of free chunks\n" + "hblkhd\t\t%,-12zu\t# space in mmapped regions\n" + "usmblks\t\t%,-12zu\t# maximum total allocated space\n" + "uordblks\t%,-12zu\t# total allocated space\n" + "fordblks\t%,-12zu\t# total free space\n" + "keepcost\t%,-12zu\t# releasable (via malloc_trim) space\n\n", + mi.arena, mi.ordblks, mi.hblkhd, mi.usmblks, mi.uordblks, mi.fordblks, + mi.keepcost); } diff --git a/libc/log/oncrash_amd64.c b/libc/log/oncrash_amd64.c index 97a72adc1..aea9e313b 100644 --- a/libc/log/oncrash_amd64.c +++ b/libc/log/oncrash_amd64.c @@ -29,6 +29,7 @@ #include "libc/fmt/itoa.h" #include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kmalloc.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/strace.internal.h" @@ -232,7 +233,7 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si, (ctx->uc_mcontext.rsp >= GetStaticStackAddr(0) && ctx->uc_mcontext.rsp <= GetStaticStackAddr(0) + getauxval(AT_PAGESZ))) ? "Stack Overflow" - : GetSiCodeName(sig, si->si_code), + : DescribeSiCode(sig, si->si_code), host, getpid(), gettid(), program_invocation_name, strerror(err), names.sysname, names.version, names.nodename, names.release); if (ctx) { diff --git a/libc/log/oncrash_arm64.c b/libc/log/oncrash_arm64.c index a8b5e806d..8b5f0d56e 100644 --- a/libc/log/oncrash_arm64.c +++ b/libc/log/oncrash_arm64.c @@ -28,6 +28,7 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/ucontext.h" #include "libc/errno.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" #include "libc/log/internal.h" #include "libc/log/log.h" @@ -132,9 +133,10 @@ static bool AppendFileLine(struct Buffer *b, const char *addr2line, sys_close(pfd[0]); sys_dup2(pfd[1], 1, 0); sys_close(2); - __sys_execve(addr2line, - (char *const[]){addr2line, "-pifCe", debugbin, buf, 0}, - (char *const[]){0}); + __sys_execve( + addr2line, + (char *const[]){(char *)addr2line, "-pifCe", (char *)debugbin, buf, 0}, + (char *const[]){0}); _Exit(127); } sys_close(pfd[1]); @@ -202,7 +204,7 @@ relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) { (ctx->uc_mcontext.sp & (GetStackSize() - 1)) <= getauxval(AT_PAGESZ)) { kind = "Stack Overflow"; } else { - kind = GetSiCodeName(sig, si->si_code); + kind = DescribeSiCode(sig, si->si_code); } Append(b, "%serror%s: Uncaught %G (%s) on %s pid %d tid %d\n" @@ -216,7 +218,6 @@ relegated void __oncrash_arm64(int sig, struct siginfo *si, void *arg) { names.release); if (ctx) { long pc; - char line[256]; char *mem = 0; size_t memsz = 0; int addend, symbol; diff --git a/libc/log/printwindowsmemory.c b/libc/log/printwindowsmemory.c index b96e12ec8..44447696f 100644 --- a/libc/log/printwindowsmemory.c +++ b/libc/log/printwindowsmemory.c @@ -56,7 +56,6 @@ static const char *DescribeNtMemType(char buf[64], uint32_t x) { */ void PrintWindowsMemory(const char *high, size_t size) { char *p, b[5][64]; - const char *start, *stop; struct NtMemoryBasicInformation mi; kprintf("%-12s %-12s %10s %16s %16s %32s %32s\n", "Allocation", "BaseAddress", "RegionSize", "State", "Type", "AllocationProtect", "Protect"); diff --git a/libc/log/vflogf.c b/libc/log/vflogf.c index 3cadd97cd..99dd72379 100644 --- a/libc/log/vflogf.c +++ b/libc/log/vflogf.c @@ -51,7 +51,6 @@ static struct timespec vflogf_ts; */ static void vflogf_onfail(FILE *f) { errno_t err; - int64_t size; struct stat st; if (IsTiny()) return; err = ferror_unlocked(f); @@ -93,7 +92,6 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, char buf32[32]; const char *prog; const char *sign; - bool issamesecond; struct timespec t2; if (!f) f = __log_file; if (!f) return; diff --git a/libc/log/watch.c b/libc/log/watch.c index 1ad71baf7..5c24be248 100644 --- a/libc/log/watch.c +++ b/libc/log/watch.c @@ -41,7 +41,6 @@ static dontinstrument inline void Copy(char *p, char *q, size_t n) { } static dontinstrument inline int Cmp(char *p, char *q, size_t n) { - int c; if (n == 8) return READ64LE(p) != READ64LE(q); if (n == 4) return READ32LE(p) != READ32LE(q); for (; n; ++p, ++q, --n) { diff --git a/libc/mem/critbit0_emplace.c b/libc/mem/critbit0_emplace.c index 1272df6a1..1c1da22f6 100644 --- a/libc/mem/critbit0_emplace.c +++ b/libc/mem/critbit0_emplace.c @@ -42,7 +42,7 @@ int critbit0_emplace(struct critbit0 *t, const void *u, size_t ulen) { unsigned char *p = t->root; if (!p) { if ((u = critbit0_dup(u, ulen))) { - t->root = u; + t->root = (void *)u; t->count = 1; return 1; } else { diff --git a/libc/mem/gc.c b/libc/mem/gc.c index 538f38361..02a24783e 100644 --- a/libc/mem/gc.c +++ b/libc/mem/gc.c @@ -33,7 +33,6 @@ forceinline bool PointerNotOwnedByParentStackFrame(struct StackFrame *frame, } static void TeardownGc(void) { - int i; struct Garbages *g; struct CosmoTib *t; if (__tls_enabled) { diff --git a/libc/nt/createfile.h b/libc/nt/createfile.h index ae1a11072..82ee48e14 100644 --- a/libc/nt/createfile.h +++ b/libc/nt/createfile.h @@ -6,14 +6,14 @@ COSMOPOLITAN_C_START_ int64_t CreateFile( const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode, - struct NtSecurityAttributes *opt_lpSecurityAttributes, + const struct NtSecurityAttributes *opt_lpSecurityAttributes, int dwCreationDisposition, uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */ int64_t opt_hTemplateFile) paramsnonnull((1)); int64_t CreateFileA( const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode, - struct NtSecurityAttributes *opt_lpSecurityAttributes, + const struct NtSecurityAttributes *opt_lpSecurityAttributes, int dwCreationDisposition, uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */ int64_t opt_hTemplateFile) paramsnonnull((1)); diff --git a/libc/nt/memory.h b/libc/nt/memory.h index fd7e3557a..0473c9270 100644 --- a/libc/nt/memory.h +++ b/libc/nt/memory.h @@ -66,8 +66,8 @@ void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize, bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType); bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect, uint32_t *lpflOldProtect) paramsnonnull(); -bool32 VirtualLock(void *lpAddress, size_t dwSize); -bool32 VirtualUnlock(void *lpAddress, size_t dwSize); +bool32 VirtualLock(const void *lpAddress, size_t dwSize); +bool32 VirtualUnlock(const void *lpAddress, size_t dwSize); uint64_t VirtualQuery(const void *lpAddress, struct NtMemoryBasicInformation *lpBuffer, uint64_t dwLength); diff --git a/libc/nt/nt/file.h b/libc/nt/nt/file.h index 051f3bae3..a34eeec90 100644 --- a/libc/nt/nt/file.h +++ b/libc/nt/nt/file.h @@ -42,7 +42,7 @@ struct NtObjectAttributes; NtStatus NtClose(int64_t handle); NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess, - struct NtObjectAttributes *ObjectAttributes, + const struct NtObjectAttributes *ObjectAttributes, struct NtIoStatusBlock *out_IoStatusBlock, int64_t *opt_AllocationSize, uint32_t FileAttributes, uint32_t ShareAccess, uint32_t CreateDisposition, diff --git a/libc/nt/struct/objectattributes.h b/libc/nt/struct/objectattributes.h index 0dc240f83..e02f55585 100644 --- a/libc/nt/struct/objectattributes.h +++ b/libc/nt/struct/objectattributes.h @@ -7,7 +7,7 @@ struct NtObjectAttributes { uint32_t Length; int64_t RootDirectory; - struct NtUnicodeString *ObjectName; + const struct NtUnicodeString *ObjectName; uint32_t Attributes; /* OBJ_INHERIT, etc. */ struct NtSecurityDescriptor *SecurityDescriptor; void *SecurityQualityOfService; diff --git a/libc/nt/synchronization.h b/libc/nt/synchronization.h index 68bf3cdc3..c6e1b28b6 100644 --- a/libc/nt/synchronization.h +++ b/libc/nt/synchronization.h @@ -50,7 +50,7 @@ typedef void (*NtWaitOrTimerCallback)(void *lpParameter, void WakeByAddressAll(void *Address); void WakeByAddressSingle(void *Address); -bool32 WaitOnAddress(volatile void *Address, void *CompareAddress, +bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress, size_t AddressSize, uint32_t opt_dwMilliseconds); void Sleep(uint32_t dwMilliseconds); diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index 59065f263..53643053f 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -52,7 +52,7 @@ #include "libc/thread/openbsd.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" #include "libc/thread/xnu.internal.h" #define kMaxThreadIds 32768 @@ -215,8 +215,6 @@ XnuThreadMain(void *pthread, // rdi static errno_t CloneXnu(int (*fn)(void *), char *stk, size_t stksz, int flags, void *arg, void *tls, int *ptid, int *ctid) { - int rc; - bool failed; static bool once; struct CloneArgs *wt; if (!once) { diff --git a/libc/runtime/cocmd.c b/libc/runtime/cocmd.c index 9a907e02b..41450410b 100644 --- a/libc/runtime/cocmd.c +++ b/libc/runtime/cocmd.c @@ -95,7 +95,6 @@ static wontreturn void UnsupportedSyntax(unsigned char c) { } static void Open(const char *path, int fd, int flags) { - const char *err; close(fd); if (open(path, flags, 0644) == -1) { perror(path); @@ -118,7 +117,7 @@ static int GetSignalByName(const char *s) { return 0; } -static void PutEnv(char **p, const char *kv) { +static void PutEnv(char **p, char *kv) { struct Env e; e = __getenv(p, kv); p[e.i] = kv; @@ -182,7 +181,6 @@ static int Waiter(int pid) { } static int Wait(void) { - char ibuf[12]; int e, ws, pid; if (n > 1) { if ((pid = atoi(args[1])) <= 0) { @@ -719,7 +717,7 @@ static void Pipe(void) { } static int ShellSpawn(void) { - int rc, ws, pid; + int rc, pid; if ((rc = TryBuiltin()) == -1) { switch ((pid = fork())) { case 0: @@ -804,8 +802,7 @@ static bool CopyVar(void) { } static char *Tokenize(void) { - const char *s; - int c, t, j, k, rc; + int c, t, rc; for (t = STATE_WHITESPACE;; ++p) { switch (t) { @@ -954,8 +951,8 @@ static const char *GetRedirectArg(const char *prog, const char *arg, int n) { } int _cocmd(int argc, char **argv, char **envp) { + size_t i; char *arg; - size_t i, j; size_t globCount = 0; int globFlags = 0; glob_t globTheBuilder; diff --git a/libc/runtime/cosmo2.c b/libc/runtime/cosmo2.c index c041dbf6b..9ce1c100f 100644 --- a/libc/runtime/cosmo2.c +++ b/libc/runtime/cosmo2.c @@ -101,7 +101,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1) { __oldstack = (intptr_t)sp; // detect apple m1 environment - char *magnums; + const char *magnums; if (SupportsXnu() && (__syslib = m1)) { hostos = _HOSTXNU; magnums = syscon_xnu; @@ -112,15 +112,6 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1) { notpossible; } - // get page size - unsigned long pagesz = 4096; - for (int i = 0; auxv[i]; i += 2) { - if (auxv[i] == AT_PAGESZ) { - pagesz = auxv[i + 1]; - break; - } - } - // setup system magic numbers for (long *mp = syscon_start; mp < syscon_end; ++mp) { magnums = DecodeMagnum(magnums, mp); diff --git a/libc/runtime/efimain.greg.c b/libc/runtime/efimain.greg.c index f20c69566..7f421f35b 100644 --- a/libc/runtime/efimain.greg.c +++ b/libc/runtime/efimain.greg.c @@ -41,8 +41,8 @@ struct EfiArgs { char ArgBlock[0xC00]; }; -static const EFI_GUID kEfiLoadedImageProtocol = LOADED_IMAGE_PROTOCOL; -static const EFI_GUID kEfiGraphicsOutputProtocol = GRAPHICS_OUTPUT_PROTOCOL; +static EFI_GUID kEfiLoadedImageProtocol = LOADED_IMAGE_PROTOCOL; +static EFI_GUID kEfiGraphicsOutputProtocol = GRAPHICS_OUTPUT_PROTOCOL; extern const char vga_console[]; extern void _EfiPostboot(struct mman *, uint64_t *, uintptr_t, char **); @@ -143,7 +143,6 @@ static void EfiInitVga(struct mman *mm, EFI_SYSTEM_TABLE *SystemTable) { */ __msabi dontasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { - int type, x87cw = 0x037f; struct mman *mm; uint32_t DescVersion; uintptr_t i, j, MapSize; @@ -152,7 +151,7 @@ __msabi dontasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, EFI_MEMORY_DESCRIPTOR *Map, *Desc; uint64_t Address; uintptr_t Args, MapKey, DescSize; - uint64_t p, pe, cr4, *m, *pd, *sp, *pml4t, *pdt1, *pdt2, *pdpt1, *pdpt2; + uint64_t *pd, *pml4t, *pdt1, *pdt2, *pdpt1, *pdpt2; extern char os asm("__hostos"); os = _HOSTMETAL; diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 93bef1449..867ce8907 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -97,7 +97,7 @@ _Alignas(TLS_ALIGNMENT) static char __static_tls[6016]; */ textstartup void __enable_tls(void) { int tid; - size_t hiz, siz; + size_t siz; char *mem, *tls; struct CosmoTib *tib; @@ -150,7 +150,7 @@ textstartup void __enable_tls(void) { #elif defined(__aarch64__) - hiz = ROUNDUP(sizeof(*tib) + 2 * sizeof(void *), I(_tls_align)); + size_t hiz = ROUNDUP(sizeof(*tib) + 2 * sizeof(void *), I(_tls_align)); siz = hiz + I(_tls_size); if (siz <= sizeof(__static_tls)) { mem = __static_tls; diff --git a/libc/runtime/fork-nt.c b/libc/runtime/fork-nt.c index 757418d07..3ea2c65ec 100644 --- a/libc/runtime/fork-nt.c +++ b/libc/runtime/fork-nt.c @@ -192,13 +192,11 @@ static textwindows int OnForkCrash(struct NtExceptionPointers *ep) { } textwindows void WinMainForked(void) { - bool ok; jmp_buf jb; int64_t reader; + int64_t savetsc; char *addr, *shad; - struct DirectMap dm; uint64_t size, upsize; - int64_t oncrash, savetsc; struct MemoryInterval *maps; char16_t fvar[21 + 1 + 21 + 1]; uint32_t i, varlen, oldprot, savepid; @@ -215,7 +213,7 @@ textwindows void WinMainForked(void) { NTTRACE("WinMainForked()"); SetEnvironmentVariable(u"_FORK", NULL); #ifdef SYSDEBUG - oncrash = AddVectoredExceptionHandler(1, NT2SYSV(OnForkCrash)); + int64_t oncrash = AddVectoredExceptionHandler(1, NT2SYSV(OnForkCrash)); #endif ParseInt(fvar, &reader); @@ -321,14 +319,13 @@ textwindows void WinMainForked(void) { textwindows int sys_fork_nt(uint32_t dwCreationFlags) { jmp_buf jb; uint32_t op; - uint32_t oldprot; + char **args; char ok, threaded; - char **args, **args2; struct CosmoTib *tib; char16_t pipename[64]; int64_t reader, writer; struct NtStartupInfo startinfo; - int i, n, pid, untrackpid, rc = -1; + int i, pid, untrackpid, rc = -1; char *p, forkvar[6 + 21 + 1 + 21 + 1]; struct NtProcessInformation procinfo; threaded = __threaded; @@ -353,6 +350,8 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) { // If --strace was passed to this program, then propagate it the // forked process since the flag was removed by __intercept_flag if (strace_enabled(0) > 0) { + int n; + char **args2; for (n = 0; args[n];) ++n; args2 = alloca((n + 2) * sizeof(char *)); for (i = 0; i < n; ++i) args2[i] = args[i]; diff --git a/libc/runtime/fork.c b/libc/runtime/fork.c index ef15fe8ca..127b786da 100644 --- a/libc/runtime/fork.c +++ b/libc/runtime/fork.c @@ -37,6 +37,7 @@ int _fork(uint32_t dwCreationFlags) { struct CosmoTib *tib; struct PosixThread *pt; int ax, dx, tid, parent; + (void)parent; BLOCK_SIGNALS; if (__threaded && _weaken(_pthread_onfork_prepare)) { _weaken(_pthread_onfork_prepare)(); diff --git a/libc/runtime/ftracer.c b/libc/runtime/ftracer.c index 42a4041f3..9cdc9cee6 100644 --- a/libc/runtime/ftracer.c +++ b/libc/runtime/ftracer.c @@ -28,7 +28,7 @@ #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" /** * @fileoverview Plain-text function call logging. @@ -48,7 +48,7 @@ static struct CosmoFtrace g_ftrace; -static privileged inline int GetNestingLevelImpl(struct StackFrame *frame) { +__funline int GetNestingLevelImpl(struct StackFrame *frame) { int nesting = -2; while (frame) { ++nesting; @@ -57,8 +57,7 @@ static privileged inline int GetNestingLevelImpl(struct StackFrame *frame) { return MAX(0, nesting); } -static privileged inline int GetNestingLevel(struct CosmoFtrace *ft, - struct StackFrame *sf) { +__funline int GetNestingLevel(struct CosmoFtrace *ft, struct StackFrame *sf) { int nesting; nesting = GetNestingLevelImpl(sf); if (nesting < ft->ft_skew) ft->ft_skew = nesting; diff --git a/libc/runtime/getdosenviron.c b/libc/runtime/getdosenviron.c index 474094c78..ddd386ed5 100644 --- a/libc/runtime/getdosenviron.c +++ b/libc/runtime/getdosenviron.c @@ -30,7 +30,7 @@ forceinline int IsAlpha(int c) { forceinline char *MemChr(const char *s, unsigned char c, unsigned long n) { for (; n; --n, ++s) { if ((*s & 255) == c) { - return s; + return (char *)s; } } return 0; @@ -42,7 +42,7 @@ Recode16to8(char *dst, size_t dstsize, const char16_t *src) { axdx_t r; uint64_t w; wint_t x, y; - for (v = r.ax = 0, r.dx = 0;;) { + for (v = false, r.ax = 0, r.dx = 0;;) { if (!(x = src[r.dx++])) break; if (!IsUcs2(x)) { y = src[r.dx++]; @@ -72,7 +72,6 @@ Recode16to8(char *dst, size_t dstsize, const char16_t *src) { textwindows dontinstrument dontasan void FixPath(char *path) { char *p; - size_t i; // turn backslash into slash for (p = path; *p; ++p) { diff --git a/libc/runtime/getinterpreterexecutablename.c b/libc/runtime/getinterpreterexecutablename.c index 25658bb00..33ca49202 100644 --- a/libc/runtime/getinterpreterexecutablename.c +++ b/libc/runtime/getinterpreterexecutablename.c @@ -45,10 +45,8 @@ */ char *GetInterpreterExecutableName(char *p, size_t n) { int e; - size_t m; int cmd[4]; ssize_t rc; - char *r, *t; e = errno; if (n < 2) { errno = ENAMETOOLONG; diff --git a/libc/runtime/getlogin.c b/libc/runtime/getlogin.c index b6a1b8038..58f1be9f4 100644 --- a/libc/runtime/getlogin.c +++ b/libc/runtime/getlogin.c @@ -57,5 +57,5 @@ char *getlogin(void) { res = 0; } STRACE("getlogin() → %#s% m", res); - return res; + return (char *)res; } diff --git a/libc/runtime/getsymboltable.c b/libc/runtime/getsymboltable.c index 91d307881..a683177ae 100644 --- a/libc/runtime/getsymboltable.c +++ b/libc/runtime/getsymboltable.c @@ -25,11 +25,11 @@ #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/symbols.internal.h" +#include "libc/runtime/zipos.internal.h" #include "libc/str/str.h" #include "libc/thread/thread.h" #include "libc/x/x.h" #include "libc/zip.internal.h" -#include "libc/runtime/zipos.internal.h" #include "third_party/puff/puff.h" __static_yoink("__get_symbol"); @@ -56,8 +56,8 @@ static ssize_t GetZipFile(struct Zipos *zipos, const char *name) { * @note This code can't depend on dlmalloc() */ static struct SymbolTable *GetSymbolTableFromZip(struct Zipos *zipos) { + ssize_t cf, lf; size_t size, size2; - ssize_t rc, cf, lf; struct SymbolTable *res = 0; if ((cf = GetZipFile(zipos, ".symtab." _ARCH_NAME)) != -1 || (cf = GetZipFile(zipos, ".symtab")) != -1) { @@ -93,7 +93,6 @@ static struct SymbolTable *GetSymbolTableFromZip(struct Zipos *zipos) { * @note This code can't depend on dlmalloc() */ static struct SymbolTable *GetSymbolTableFromElf(void) { - int e; const char *s; if (PLEDGED(RPATH) && (s = FindDebugBinary())) { return OpenSymbolTable(s); diff --git a/libc/runtime/interceptflag.greg.c b/libc/runtime/interceptflag.greg.c index 026ea4dbe..759ee5869 100644 --- a/libc/runtime/interceptflag.greg.c +++ b/libc/runtime/interceptflag.greg.c @@ -37,7 +37,7 @@ textstartup bool __intercept_flag(int *argc, char *argv[], const char *flag) { * todo: update this to allow ------strace etc. */ if (a && a[0] == '-' && a[1] == '-' && !__strcmp(a + 2, flag)) { - a = flag; + a = (char *)flag; } argv[i++] = a; } diff --git a/libc/runtime/internal.h b/libc/runtime/internal.h index c13c001dc..d5a9bf548 100644 --- a/libc/runtime/internal.h +++ b/libc/runtime/internal.h @@ -40,7 +40,6 @@ void *__cxa_finalize(void *); void __restore_console_win32(void); void __stack_chk_fail(void) wontreturn relegated; void __stack_chk_fail_local(void) wontreturn relegated; -void __asan_init(int, char **, char **, intptr_t *); void _jmpstack(void *, void *, ...) wontreturn; long _setstack(void *, void *, ...); int GetDosArgv(const char16_t *, char *, size_t, char **, size_t); diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index 3abde65ab..2670cfe94 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -240,10 +240,10 @@ static textwindows dontinline dontasan void *__map_memories( dontasan inline void *__mmap_unlocked(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { + int a, f, n, x; char *p = addr; struct DirectMap dm; size_t requested_size; - int a, b, i, f, m, n, x; bool needguard, clashes; unsigned long page_size; size_t virtualused, virtualneed; @@ -465,12 +465,14 @@ dontasan inline void *__mmap_unlocked(void *addr, size_t size, int prot, */ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { void *res; +#ifdef SYSDEBUG size_t toto = 0; -#if defined(SYSDEBUG) && (_KERNTRACE || _NTTRACE) +#if _KERNTRACE || _NTTRACE if (IsWindows()) { STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → ...", addr, size, DescribeProtFlags(prot), DescribeMapFlags(flags), fd, off); } +#endif #endif __mmi_lock(); if (!__isfdkind(fd, kFdZip)) { diff --git a/libc/runtime/munmap.c b/libc/runtime/munmap.c index cae2744d2..b482e0952 100644 --- a/libc/runtime/munmap.c +++ b/libc/runtime/munmap.c @@ -70,7 +70,7 @@ static dontasan void __munmap_impl(char *p, size_t n) { char *q; size_t m; intptr_t a, b, c; - int i, l, r, rc, beg, end; + int i, l, r, beg, end; KERNTRACE("__munmap_impl(%p, %'zu)", p, n); l = FRAME(p); r = FRAME(p + n - 1); @@ -113,9 +113,6 @@ static dontasan void __munmap_impl(char *p, size_t n) { } dontasan int __munmap_unlocked(char *p, size_t n) { - unsigned i; - char poison; - intptr_t a, b, x, y; unassert(!__vforked); if (UNLIKELY(!n)) { STRACE("munmap n is 0"); @@ -154,11 +151,10 @@ dontasan int __munmap_unlocked(char *p, size_t n) { */ int munmap(void *p, size_t n) { int rc; - size_t toto; __mmi_lock(); rc = __munmap_unlocked(p, n); #if SYSDEBUG - toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0; + size_t toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0; #endif __mmi_unlock(); STRACE("munmap(%.12p, %'zu) → %d% m (%'zu bytes total)", p, n, rc, toto); diff --git a/libc/runtime/printargs.c b/libc/runtime/printargs.c index 60b42fce9..d0f883459 100644 --- a/libc/runtime/printargs.c +++ b/libc/runtime/printargs.c @@ -159,24 +159,25 @@ dontasan textstartup void __printargs(const char *prologue) { {"%-14d", AT_MINSIGSTKSZ, "AT_MINSIGSTKSZ"}, }; - long key; + int e, x; char **env; sigset_t ss; bool gotsome; - int e, x, flags; + unsigned i, n; uintptr_t *auxp; - unsigned i, n, b; struct rlimit rlim; struct utsname uts; struct sigaction sa; struct sched_param sp; struct termios termios; - struct AuxiliaryValue *auxinfo; + const struct AuxiliaryValue *auxinfo; union { char path[PATH_MAX]; struct pollfd pfds[128]; } u; + (void)x; + if (!PLEDGED(STDIO)) return; ftrace_enabled(-1); @@ -351,7 +352,7 @@ dontasan textstartup void __printargs(const char *prologue) { PRINT(""); PRINT("CAPABILITIES"); if (prctl(PR_CAPBSET_READ, 0) != -1) { - for (gotsome = i = 0; i <= CAP_LAST_CAP; ++i) { + for (gotsome = false, i = 0; i <= CAP_LAST_CAP; ++i) { if (prctl(PR_CAPBSET_READ, i) == 1) { char buf[64]; PRINT(" ☼ %s", (DescribeCapability)(buf, i)); @@ -368,7 +369,7 @@ dontasan textstartup void __printargs(const char *prologue) { PRINT(""); PRINT("RESOURCE LIMITS"); - for (gotsome = i = 0; i < RLIM_NLIMITS; ++i) { + 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; diff --git a/libc/runtime/set_tls.c b/libc/runtime/set_tls.c index 29b98e89c..20a5eae49 100644 --- a/libc/runtime/set_tls.c +++ b/libc/runtime/set_tls.c @@ -25,7 +25,7 @@ #include "libc/nt/thread.h" #include "libc/sysv/consts/arch.h" #include "libc/thread/tls.h" -#include "libc/thread/tls2.h" +#include "libc/thread/tls2.internal.h" int sys_set_tls(); @@ -33,7 +33,6 @@ textstartup void __set_tls(struct CosmoTib *tib) { tib = __adj_tls(tib); #ifdef __x86_64__ // ask the operating system to change the x86 segment register - int ax, dx; if (IsWindows()) { __tls_index = TlsAlloc(); npassert(0 <= __tls_index && __tls_index < 64); diff --git a/libc/runtime/sysconf.c b/libc/runtime/sysconf.c index 0231d1f12..1c44c784b 100644 --- a/libc/runtime/sysconf.c +++ b/libc/runtime/sysconf.c @@ -51,7 +51,6 @@ * @raise EINVAL if `name` isn't valid */ long sysconf(int name) { - int n; switch (name) { case _SC_CLK_TCK: return CLK_TCK; diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index f54c5c711..989a0b937 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -185,7 +185,7 @@ __msabi static textwindows wontreturn void WinMainNew(const char16_t *cmdline) { wa->argv[0][i] = '/'; } } - const char16_t *env16 = __imp_GetEnvironmentStringsW(); + char16_t *env16 = __imp_GetEnvironmentStringsW(); GetDosEnviron(env16, wa->envblock, ARRAYLEN(wa->envblock) - 8, wa->envp, ARRAYLEN(wa->envp) - 1); __imp_FreeEnvironmentStringsW(env16); diff --git a/libc/runtime/zipos-get.c b/libc/runtime/zipos-get.c index b993df004..3e13f7614 100644 --- a/libc/runtime/zipos-get.c +++ b/libc/runtime/zipos-get.c @@ -46,7 +46,7 @@ __static_yoink(APE_COM_NAME); static struct Zipos __zipos; static atomic_uint __zipos_once; -static void __zipos_dismiss(const uint8_t *map, const uint8_t *cdir, long pg) { +static void __zipos_dismiss(uint8_t *map, const uint8_t *cdir, long pg) { uint64_t i, n, c, ef, lf, mo, lo, hi; // determine the byte range of zip file content (excluding central dir) @@ -154,6 +154,7 @@ static void __zipos_init(void) { progpath = 0; msg = -777; } + (void)msg; STRACE("__zipos_get(%#s) → %d% m", progpath, msg); } diff --git a/libc/runtime/zipos-open.c b/libc/runtime/zipos-open.c index 4e9f15edc..8bc0154d0 100644 --- a/libc/runtime/zipos-open.c +++ b/libc/runtime/zipos-open.c @@ -154,7 +154,7 @@ static int __zipos_load(struct Zipos *zipos, size_t cf, int flags, struct ZiposUri *name) { size_t lf; size_t size; - int rc, fd, minfd; + int fd, minfd; struct ZiposHandle *h; if (cf == ZIPOS_SYNTHETIC_DIRECTORY) { size = name->len; diff --git a/libc/sock/accept-nt.c b/libc/sock/accept-nt.c index 75d117ef9..bfb1ed657 100644 --- a/libc/sock/accept-nt.c +++ b/libc/sock/accept-nt.c @@ -46,7 +46,7 @@ struct AcceptExBuffer { textwindows int sys_accept_nt(struct Fd *fd, struct sockaddr_storage *addr, int accept4_flags) { int64_t handle; - int rc, client, oflags; + int client, oflags; uint32_t bytes_received; uint32_t completion_flags; struct AcceptExBuffer buffer; diff --git a/libc/sock/inet_ntop.c b/libc/sock/inet_ntop.c index ba4e8706b..6e4767490 100644 --- a/libc/sock/inet_ntop.c +++ b/libc/sock/inet_ntop.c @@ -32,8 +32,8 @@ */ const char *inet_ntop(int af, const void *src, char *dst, uint32_t size) { char *p; - unsigned char *ip; int i, t, a, b, c, d; + const unsigned char *ip; p = dst; if (!size) return dst; if ((ip = src)) { diff --git a/libc/sock/inet_pton.c b/libc/sock/inet_pton.c index bbf9088bd..2dc67e3d8 100644 --- a/libc/sock/inet_pton.c +++ b/libc/sock/inet_pton.c @@ -46,7 +46,7 @@ static int inet_pton_inet6_impl(const char *src, uint8_t *dst) { unsigned digitsLeft = 32; bool zeroFound = false; uint16_t currentSet = 0; - while (c = *src++) { + while ((c = *src++)) { if (digitsLeft == 0) { return 0; } diff --git a/libc/sock/kntwsadata.c b/libc/sock/kntwsadata.c index b9983a519..982413643 100644 --- a/libc/sock/kntwsadata.c +++ b/libc/sock/kntwsadata.c @@ -37,7 +37,7 @@ struct NtWsaData kNtWsaData; static textwindows void WinSockCleanup(void) { - int i, rc; + int rc; (void)rc; rc = WSACleanup(); NTTRACE("WSACleanup() → %d% lm", rc); diff --git a/libc/sock/nointernet.c b/libc/sock/nointernet.c index 887ac19ca..7af468530 100644 --- a/libc/sock/nointernet.c +++ b/libc/sock/nointernet.c @@ -284,7 +284,6 @@ static int WaitForTrace(int main) { int nointernet(void) { int ws, act, main; sigset_t set, old; - char path[PATH_MAX]; struct sock_fprog prog = {.filter = kInetBpf, .len = ARRAYLEN(kInetBpf)}; // seccomp bpf and ptrace are pretty much just linux for now. diff --git a/libc/sock/pselect.c b/libc/sock/pselect.c index 2e7eaae3b..538a3ddc7 100644 --- a/libc/sock/pselect.c +++ b/libc/sock/pselect.c @@ -60,7 +60,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask) { int rc; - sigset_t oldmask; struct timeval tv, *tvp; struct timespec ts, *tsp; struct { @@ -89,7 +88,8 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, ss.n = 8; rc = sys_pselect(nfds, readfds, writefds, exceptfds, tsp, &ss); } else if (!IsWindows()) { - rc = sys_pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask); + rc = sys_pselect(nfds, readfds, writefds, exceptfds, + (struct timespec *)timeout, sigmask); } else { if (timeout) { tv.tv_sec = timeout->tv_sec; diff --git a/libc/sock/recv.c b/libc/sock/recv.c index c433b3eea..822f32e5a 100644 --- a/libc/sock/recv.c +++ b/libc/sock/recv.c @@ -42,7 +42,7 @@ * @restartable (unless SO_RCVTIMEO) */ ssize_t recv(int fd, void *buf, size_t size, int flags) { - ssize_t rc, got; + ssize_t rc; BEGIN_CANCELLATION_POINT; if (IsAsan() && !__asan_is_valid(buf, size)) { diff --git a/libc/sock/send.c b/libc/sock/send.c index 82eeedf4f..5a41139f7 100644 --- a/libc/sock/send.c +++ b/libc/sock/send.c @@ -54,12 +54,12 @@ ssize_t send(int fd, const void *buf, size_t size, int flags) { rc = sys_sendto(fd, buf, size, flags, 0, 0); } else if (__isfdopen(fd)) { if (__isfdkind(fd, kFdSocket)) { - rc = sys_send_nt(fd, (struct iovec[]){{buf, size}}, 1, flags); + rc = sys_send_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, flags); } else if (__isfdkind(fd, kFdFile)) { if (flags) { rc = einval(); } else { - rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, -1); + rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, -1); } } else { rc = enotsock(); diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index a891f77dd..22e9a903d 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -43,7 +43,6 @@ // sendfile() isn't specified as raising eintr static textwindows int SendfileBlock(int64_t handle, struct NtOverlapped *overlapped) { - int rc; uint32_t i, got, flags = 0; if (WSAGetLastError() != kNtErrorIoPending && WSAGetLastError() != WSAEINPROGRESS) { diff --git a/libc/sock/sendto.c b/libc/sock/sendto.c index 57ce8093e..badea233a 100644 --- a/libc/sock/sendto.c +++ b/libc/sock/sendto.c @@ -74,15 +74,15 @@ ssize_t sendto(int fd, const void *buf, size_t size, int flags, } } else if (__isfdopen(fd)) { if (__isfdkind(fd, kFdSocket)) { - rc = sys_sendto_nt(fd, (struct iovec[]){{buf, size}}, 1, flags, opt_addr, - addrsize); + rc = sys_sendto_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, flags, + opt_addr, addrsize); } else if (__isfdkind(fd, kFdFile)) { if (flags) { rc = einval(); } else if (opt_addr) { rc = eisconn(); } else { - rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, -1); + rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, -1); } } else { rc = enotsock(); diff --git a/libc/sock/setsockopt-nt.c b/libc/sock/setsockopt-nt.c index d9f1ebf09..aca8c612b 100644 --- a/libc/sock/setsockopt-nt.c +++ b/libc/sock/setsockopt-nt.c @@ -34,9 +34,9 @@ __msabi extern typeof(__sys_setsockopt_nt) *const __imp_setsockopt; textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname, const void *optval, uint32_t optlen) { int64_t ms, micros; - struct timeval *tv; - struct linger *linger; struct SockFd *sockfd; + const struct timeval *tv; + const struct linger *linger; union { uint32_t millis; struct linger_nt linger; diff --git a/libc/sock/sockdebug.c b/libc/sock/sockdebug.c index bf74ee730..8553dcfd0 100644 --- a/libc/sock/sockdebug.c +++ b/libc/sock/sockdebug.c @@ -32,7 +32,6 @@ const char *(DescribeSockaddr)(char buf[128], const struct sockaddr *sa, size_t sasize) { int e; size_t n; - uint16_t port; char *p, ip[72]; e = errno; stpcpy(buf, "NULL"); diff --git a/libc/sock/socketpair-nt.c b/libc/sock/socketpair-nt.c index 171724b16..c5180d5fc 100644 --- a/libc/sock/socketpair-nt.c +++ b/libc/sock/socketpair-nt.c @@ -33,8 +33,8 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) { uint32_t mode; + int64_t hpipe, h1; char16_t pipename[64]; - int64_t hpipe, h1, h2; int rc, reader, writer, oflags; // Supports only AF_UNIX diff --git a/libc/sock/syslog.c b/libc/sock/syslog.c index cfea998f3..37031cdce 100644 --- a/libc/sock/syslog.c +++ b/libc/sock/syslog.c @@ -19,7 +19,6 @@ #include "libc/sock/syslog.h" #include "libc/calls/blockcancel.internal.h" #include "libc/calls/calls.h" -#include "libc/stdio/dprintf.h" #include "libc/calls/struct/timespec.h" #include "libc/calls/weirdtypes.h" #include "libc/dce.h" @@ -32,6 +31,7 @@ #include "libc/nt/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/sockaddr.h" +#include "libc/stdio/dprintf.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/af.h" @@ -261,7 +261,6 @@ int setlogmask(int maskpri) { * @asyncsignalsafe */ void openlog(const char *ident, int opt, int facility) { - size_t n; BLOCK_CANCELLATIONS; if (log_facility == -1) __initlog(); if (!ident) ident = firstnonnull(program_invocation_short_name, "unknown"); diff --git a/libc/sock/wsablock.c b/libc/sock/wsablock.c index 7f8b33b6d..439c9b6ae 100644 --- a/libc/sock/wsablock.c +++ b/libc/sock/wsablock.c @@ -43,8 +43,8 @@ static textwindows void __wsablock_abort(int64_t handle, textwindows int __wsablock(struct Fd *fd, struct NtOverlapped *overlapped, uint32_t *flags, int sigops, uint32_t timeout) { + int abort_errno; uint32_t i, got; - int rc, abort_errno; if (WSAGetLastError() != kNtErrorIoPending) { // our i/o operation never happened because it failed return __winsockerr(); diff --git a/libc/stdio/ctermid.c b/libc/stdio/ctermid.c index c2bdc1182..f1bfb20fa 100644 --- a/libc/stdio/ctermid.c +++ b/libc/stdio/ctermid.c @@ -42,6 +42,6 @@ char *ctermid(char *s) { if (s) { return strcpy(s, tty); } else { - return tty; + return (char *)tty; } } diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index 143f2f722..1e605f440 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -294,13 +294,13 @@ DIR *fdopendir(int fd) { // get path of this file descriptor and ensure trailing slash size_t len; - char *name; + const char *name; if (h->cfile != ZIPOS_SYNTHETIC_DIRECTORY) { len = ZIP_CFILE_NAMESIZE(h->zipos->map + h->cfile); name = ZIP_CFILE_NAME(h->zipos->map + h->cfile); } else { len = h->size; - name = (char *)h->data; + name = (const char *)h->data; } if (len + 2 > ZIPOS_PATH_MAX) { free(dir); @@ -385,13 +385,13 @@ static struct dirent *readdir_zipos(DIR *dir) { ent->d_ino = __zipos_inode( dir->zip.zipos, __zipos_scan(dir->zip.zipos, &p), p.path, p.len); } else { - uint8_t *s = ZIP_CFILE_NAME(dir->zip.zipos->map + dir->zip.offset); + const char *s = ZIP_CFILE_NAME(dir->zip.zipos->map + dir->zip.offset); size_t n = ZIP_CFILE_NAMESIZE(dir->zip.zipos->map + dir->zip.offset); if (n > dir->zip.prefix.len && !memcmp(dir->zip.prefix.path, s, dir->zip.prefix.len)) { s += dir->zip.prefix.len; n -= dir->zip.prefix.len; - uint8_t *p = memchr(s, '/', n); + const char *p = memchr(s, '/', n); if (p) n = p - s; if ((n = MIN(n, sizeof(ent->d_name) - 1)) && critbit0_emplace(&dir->zip.found, s, n) == 1) { diff --git a/libc/stdio/dprintf.h b/libc/stdio/dprintf.h index 0b2f7dde0..67d35f7ab 100644 --- a/libc/stdio/dprintf.h +++ b/libc/stdio/dprintf.h @@ -3,7 +3,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int dprintf(int, const char *, ...) printfesque(2) paramsnonnull((2)); +int dprintf(int, const char *, ...) paramsnonnull((2)); int vdprintf(int, const char *, va_list) paramsnonnull(); COSMOPOLITAN_C_END_ diff --git a/libc/stdio/fmemopen.c b/libc/stdio/fmemopen.c index b68d6bcb4..e2c67c73f 100644 --- a/libc/stdio/fmemopen.c +++ b/libc/stdio/fmemopen.c @@ -38,7 +38,6 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) { FILE *f; char *p; int iomode; - unsigned flags; iomode = fopenflags(mode); if ((size && size > 0x7ffff000) || // (!buf && (iomode & O_ACCMODE) != O_RDWR)) { diff --git a/libc/stdio/fmt.c b/libc/stdio/fmt.c index 58233cf3e..2e16cd388 100644 --- a/libc/stdio/fmt.c +++ b/libc/stdio/fmt.c @@ -398,7 +398,7 @@ static int __fmt_stoa(int out(const char *, void *, size_t), void *arg, unsigned n; emit_f emit; char *p, buf[1]; - unsigned w, c, pad; + unsigned w, pad; bool justdobytes, ignorenul; p = data; @@ -604,7 +604,7 @@ static void __fmt_ldfpbits(union U *u, struct FPBits *b) { // returns number of hex digits minus 1, or 0 for zero static int __fmt_fpiprec(struct FPBits *b) { - FPI *fpi; + const FPI *fpi; int i, j, k, m; uint32_t *bits; if (b->kind == STRTOG_Zero) return (b->ex = 0); @@ -794,10 +794,10 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { wchar_t charbuf[1]; const char *alphabet; unsigned char signbit, log2base; + int c, k, i1, bw, rc, bex, prec1, decpt; int (*out)(const char *, void *, size_t); char *se, *s0, *s, *q, qchar, special[8]; int d, w, n, sign, prec, flags, width, lasterr; - int c, k, i1, ui, bw, rc, bex, sgn, prec1, decpt; x = 0; lasterr = errno; @@ -852,7 +852,7 @@ int __fmt(void *fn, void *arg, const char *format, va_list va) { continue; } else if (format[1] == '.' && format[2] == '*' && format[3] == 's') { n = va_arg(va, unsigned); // FAST PATH: PRECISION STRING - s = va_arg(va, const char *); + const char *s = va_arg(va, const char *); if (s) { n = strnlen(s, n); } else { diff --git a/libc/stdio/fseek_unlocked.c b/libc/stdio/fseek_unlocked.c index 1a9eefdee..ceafb91b4 100644 --- a/libc/stdio/fseek_unlocked.c +++ b/libc/stdio/fseek_unlocked.c @@ -38,7 +38,6 @@ */ int fseek_unlocked(FILE *f, int64_t offset, int whence) { int res; - ssize_t rc; int64_t pos; if (f->fd != -1) { if (__fflush_impl(f) == -1) return -1; diff --git a/libc/stdio/ftell.c b/libc/stdio/ftell.c index eb188372a..2dcd9c5f2 100644 --- a/libc/stdio/ftell.c +++ b/libc/stdio/ftell.c @@ -26,7 +26,6 @@ static inline int64_t ftell_unlocked(FILE *f) { int64_t pos; - uint32_t skew; if (f->fd != -1) { if (__fflush_impl(f) == -1) return -1; if ((pos = lseek(f->fd, 0, SEEK_CUR)) != -1) { diff --git a/libc/stdio/fwrite_unlocked.c b/libc/stdio/fwrite_unlocked.c index b459395cb..67d36f847 100644 --- a/libc/stdio/fwrite_unlocked.c +++ b/libc/stdio/fwrite_unlocked.c @@ -101,7 +101,7 @@ size_t fwrite_unlocked(const void *data, size_t stride, size_t count, FILE *f) { // (2) we avoid need for malloc() when it's out of room iov[0].iov_base = f->buf; iov[0].iov_len = f->beg; - iov[1].iov_base = data; + iov[1].iov_base = (void *)data; iov[1].iov_len = n; n += f->beg; if (__robust_writev(f->fd, iov, 2) == -1) { diff --git a/libc/stdio/iconv.c b/libc/stdio/iconv.c index cb147b149..c6e902449 100644 --- a/libc/stdio/iconv.c +++ b/libc/stdio/iconv.c @@ -220,7 +220,7 @@ static void put_16(unsigned char *s, unsigned c, int e) static unsigned get_32(const unsigned char *s, int e) { e &= 3; - return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3]; + return (s[e]+0U)<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3]; } static void put_32(unsigned char *s, unsigned c, int e) @@ -240,7 +240,7 @@ static unsigned legacy_map(const unsigned char *map, unsigned c) { if (c < 4*map[-1]) return c; unsigned x = c - 4*map[-1]; - x = map[x*5/4]>>2*x%8 | map[x*5/4+1]<<8-2*x%8 & 1023; + x = (map[x*5/4]>>(2*x%8)) | ((map[x*5/4+1]<<(8-(2*x%8))) & 1023); return x < 256 ? x : legacy_chars[x-256]; } @@ -535,7 +535,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri if (c >= 93 || d >= 94) { c += (0xa1-0x81); d += 0xa1; - if (c >= 93 || c>=0xc6-0x81 && d>0x52) + if (c >= 93 || ((c>=0xc6-0x81) && d>0x52)) goto ilseq; if (d-'A'<26) d = d-'A'; else if (d-'a'<26) d = d-'a'+26; diff --git a/libc/stdio/popen.c b/libc/stdio/popen.c index b848d3903..5f81966a1 100644 --- a/libc/stdio/popen.c +++ b/libc/stdio/popen.c @@ -77,7 +77,14 @@ FILE *popen(const char *cmdline, const char *mode) { // 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])); - _Exit(_cocmd(3, (char *[]){"popen", "-c", cmdline, 0}, environ)); + _Exit(_cocmd(3, + (char *[]){ + "popen", + "-c", + (char *)cmdline, + 0, + }, + environ)); default: f->pid = pid; unassert(!close(pipefds[!dir])); diff --git a/libc/stdio/posix_spawn.internal.h b/libc/stdio/posix_spawn.internal.h index 103823917..06051e3e1 100644 --- a/libc/stdio/posix_spawn.internal.h +++ b/libc/stdio/posix_spawn.internal.h @@ -31,7 +31,7 @@ struct _posix_faction { int newfildes; unsigned mode; }; - const char *path; + char *path; }; COSMOPOLITAN_C_END_ diff --git a/libc/stdio/posix_spawn_file_actions.c b/libc/stdio/posix_spawn_file_actions.c index e7a061bdb..4f360391e 100644 --- a/libc/stdio/posix_spawn_file_actions.c +++ b/libc/stdio/posix_spawn_file_actions.c @@ -117,13 +117,14 @@ int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions, 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 (IsWindows() && fildes > 2) return ENOTSUP; - if (!(path = strdup(path))) return ENOMEM; + if (!(path2 = strdup(path))) return ENOMEM; return AddFileAction(file_actions, (struct _posix_faction){ .action = _POSIX_SPAWN_OPEN, .fildes = fildes, - .path = path, + .path = path2, .oflag = oflag, .mode = mode, }); diff --git a/libc/stdio/puts.c b/libc/stdio/puts.c index 459332ba7..0d395c025 100644 --- a/libc/stdio/puts.c +++ b/libc/stdio/puts.c @@ -20,20 +20,6 @@ #include "libc/stdio/stdio.h" #include "libc/str/str.h" -static inline int puts_unlocked(const char *s, FILE *f) { - size_t n, r; - if ((n = strlen(s))) { - r = fwrite_unlocked(s, 1, n, f); - if (!r) return -1; - if (r < n) return r; - } - if (fputc_unlocked('\n', f) == -1) { - if (feof_unlocked(f)) return n; - return -1; - } - return n + 1; -} - /** * Writes string w/ trailing newline to stdout. * @@ -41,11 +27,9 @@ static inline int puts_unlocked(const char *s, FILE *f) { * `errno` set and the `ferror(stdout)` state is updated */ int puts(const char *s) { - FILE *f; int bytes; - f = stdout; - flockfile(f); - bytes = puts_unlocked(s, f); - funlockfile(f); + flockfile(stdout); + bytes = puts_unlocked(s); + funlockfile(stdout); return bytes; } diff --git a/libc/log/getsicodename.c b/libc/stdio/puts_unlocked.c similarity index 75% rename from libc/log/getsicodename.c rename to libc/stdio/puts_unlocked.c index 70e751a40..c8d945ed4 100644 --- a/libc/log/getsicodename.c +++ b/libc/stdio/puts_unlocked.c @@ -1,7 +1,7 @@ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,13 +16,25 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/describeflags.internal.h" -#include "libc/log/log.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" /** - * Returns symbolic name for siginfo::si_code value. + * Writes string w/ trailing newline to stdout. + * + * @return non-negative number on success, or `EOF` on error with + * `errno` set and the `ferror(stdout)` state is updated */ -const char *GetSiCodeName(int sig, int si_code) { - static char b[17]; - return (DescribeSiCode)(b, sig, si_code); +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 (fputc_unlocked('\n', stdout) == -1) { + if (feof_unlocked(stdout)) return n; + return -1; + } + return n + 1; } diff --git a/libc/stdio/rngset.c b/libc/stdio/rngset.c index 601a1d92e..3421cb358 100644 --- a/libc/stdio/rngset.c +++ b/libc/stdio/rngset.c @@ -43,7 +43,7 @@ */ dontasan void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) { size_t m; - uint64_t i, x, t = 0; + uint64_t x, t = 0; unsigned char *p = b; if (IsAsan()) { __asan_verify(b, n); diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index 8b3933e46..2b14fdd7f 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -123,6 +123,7 @@ int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque; ╚────────────────────────────────────────────────────────────────────────────│*/ int getc_unlocked(FILE *) paramsnonnull(); +int puts_unlocked(const char *); int getchar_unlocked(void); int putc_unlocked(int, FILE *) paramsnonnull(); int putchar_unlocked(int); diff --git a/libc/stdio/system.c b/libc/stdio/system.c index 57175e1b3..5a883cdfe 100644 --- a/libc/stdio/system.c +++ b/libc/stdio/system.c @@ -72,7 +72,7 @@ int system(const char *cmdline) { sigprocmask(SIG_BLOCK, &chldmask, &savemask); if (!(pid = fork())) { sigprocmask(SIG_SETMASK, &savemask, 0); - _Exit(_cocmd(3, (char *[]){"system", "-c", cmdline, 0}, environ)); + _Exit(_cocmd(3, (char *[]){"system", "-c", (char *)cmdline, 0}, environ)); } else if (pid == -1) { wstatus = -1; } else { diff --git a/libc/stdio/vcscanf.c b/libc/stdio/vcscanf.c index 8fb3d6cff..6ea12ae5d 100644 --- a/libc/stdio/vcscanf.c +++ b/libc/stdio/vcscanf.c @@ -326,7 +326,6 @@ int __vcscanf(int callback(void *), // } else if (tpdecodecb((wint_t *)&c, c, (void *)callback, arg) != -1) { if (charbytes == sizeof(char16_t)) { - size_t k = 0; unsigned w = EncodeUtf16(c); do { if ((j + 1) * 2 < bufsize) { diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c index d64486215..7e2471772 100644 --- a/libc/stdio/vdprintf.c +++ b/libc/stdio/vdprintf.c @@ -40,7 +40,7 @@ static int vdprintf_putc(const char *s, struct VdprintfState *t, size_t n) { } else { iov[0].iov_base = t->b; iov[0].iov_len = t->n; - iov[1].iov_base = s; + iov[1].iov_base = (void *)s; iov[1].iov_len = n; if (__robust_writev(t->fd, iov, 2) == -1) { return -1; diff --git a/libc/str/bcmp.c b/libc/str/bcmp.c index 3bfabb7f2..d79594d2c 100644 --- a/libc/str/bcmp.c +++ b/libc/str/bcmp.c @@ -33,8 +33,8 @@ static int bcmp_sse(const char *p, const char *q, size_t n) { q += 16; n -= 16; } - a = *(const xmm_t *)p ^ *(const xmm_t *)q | - *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16); + a = (*(const xmm_t *)p ^ *(const xmm_t *)q) | + (*(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16)); return !!(a[0] | a[1]); } #endif @@ -65,8 +65,8 @@ _Microarchitecture("avx") static int bcmp_avx(const char *p, const char *q, n -= 16; } } - a = *(const xmm_t *)p ^ *(const xmm_t *)q | - *(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16); + a = (*(const xmm_t *)p ^ *(const xmm_t *)q) | + (*(const xmm_t *)(p + n - 16) ^ *(const xmm_t *)(q + n - 16)); return !!(a[0] | a[1]); } #endif @@ -103,7 +103,6 @@ _Microarchitecture("avx") static int bcmp_avx(const char *p, const char *q, */ int bcmp(const void *a, const void *b, size_t n) { int c; - unsigned u; uint32_t i, j; uint64_t x, y; const char *p, *q; diff --git a/libc/str/c16rtomb.c b/libc/str/c16rtomb.c index 15e90379e..0ee3b413b 100644 --- a/libc/str/c16rtomb.c +++ b/libc/str/c16rtomb.c @@ -46,7 +46,7 @@ size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) { return 1; } if (!*x && c16 - 0xd800u < 0x400) { - *x = c16 - 0xd7c0 << 10; + *x = (c16 - 0xd7c0) << 10; return 0; } if (*x) { diff --git a/libc/str/dosdatetimetounix.c b/libc/str/dosdatetimetounix.c index edf9facfb..158b65a10 100644 --- a/libc/str/dosdatetimetounix.c +++ b/libc/str/dosdatetimetounix.c @@ -27,7 +27,7 @@ * @see PKZIP, FAT */ int64_t DosDateTimeToUnix(unsigned date, unsigned time) { - unsigned weekday, year, month, day, hour, minute, second, yday, leap; + unsigned year, month, day, hour, minute, second, yday, leap; year = ((date & 0xfffffe00) >> 9) + 1980 - 1900; month = MAX(1, MIN(12, (date & 0x01e0) >> 5)); day = (date & 0x001f) ? (date & 0x001f) - 1 : 0; diff --git a/libc/str/getzipcdircomment.c b/libc/str/getzipcdircomment.c index 5b1f68fec..95ccc0e06 100644 --- a/libc/str/getzipcdircomment.c +++ b/libc/str/getzipcdircomment.c @@ -21,7 +21,7 @@ /** * Returns comment of zip central directory. */ -void *GetZipCdirComment(const uint8_t *eocd) { +const void *GetZipCdirComment(const uint8_t *eocd) { if (READ32LE(eocd) == kZipCdir64HdrMagic && ZIP_CDIR64_COMMENTSIZE(eocd)) { return ZIP_CDIR64_COMMENT(eocd); } else { diff --git a/libc/str/getzipeocd.c b/libc/str/getzipeocd.c index a6ae6069b..45f0dbfd3 100644 --- a/libc/str/getzipeocd.c +++ b/libc/str/getzipeocd.c @@ -38,7 +38,6 @@ typedef long long v2di __attribute__((__vector_size__(16), __aligned__(1))); * @return pointer to EOCD64 or EOCD, otherwise null */ void *GetZipEocd(const void *f, size_t n, int *e) { - v2di x; int err; size_t i, j; uint32_t magic; @@ -53,7 +52,7 @@ void *GetZipEocd(const void *f, size_t n, int *e) { READ16LE("PK"), READ16LE("PK"), READ16LE("PK"), READ16LE("PK")}; asm("" : "+x"(pk)); if (i >= 14) { - x = *(const v2di *)(p + i - 14); + v2di x = *(const v2di *)(p + i - 14); if (!(__builtin_ia32_pmovmskb128( (v16qi)__builtin_ia32_pcmpeqw128((v8hi)x, pk)) | __builtin_ia32_pmovmskb128((v16qi)__builtin_ia32_pcmpeqw128( @@ -70,7 +69,7 @@ void *GetZipEocd(const void *f, size_t n, int *e) { } if (magic == kZipCdir64LocatorMagic && i + kZipCdir64LocatorSize <= n && (err = IsZipEocd64(p, n, ZIP_LOCATE64_OFFSET(p + i))) == kZipOk) { - return p + ZIP_LOCATE64_OFFSET(p + i); + return (void *)(p + ZIP_LOCATE64_OFFSET(p + i)); } else if (magic == kZipCdirHdrMagic && (err = IsZipEocd32(p, n, i)) == kZipOk) { j = i; @@ -78,10 +77,10 @@ void *GetZipEocd(const void *f, size_t n, int *e) { if (READ32LE(p + j) == kZipCdir64LocatorMagic && j + kZipCdir64LocatorSize <= n && IsZipEocd64(p, n, ZIP_LOCATE64_OFFSET(p + j)) == kZipOk) { - return p + ZIP_LOCATE64_OFFSET(p + j); + return (void *)(p + ZIP_LOCATE64_OFFSET(p + j)); } } while (j-- && i - j < 128); - return p + i; + return (void *)(p + i); } } while (i > 0 && i-- + 0x10000 + 0x1000 >= n); if (e) *e = err; diff --git a/libc/str/isutf8.c b/libc/str/isutf8.c index 4231f1de1..25d5ceb55 100644 --- a/libc/str/isutf8.c +++ b/libc/str/isutf8.c @@ -51,7 +51,6 @@ static const char kUtf8Dispatch[] = { */ dontasan bool isutf8(const void *data, size_t size) { long c; - unsigned m; const char *p, *e; if (size == -1) size = data ? strlen(data) : 0; if (IsAsan()) __asan_verify(data, size); @@ -62,6 +61,7 @@ dontasan bool isutf8(const void *data, size_t size) { typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); if (!((intptr_t)p & 15)) { for (;;) { + unsigned m; if ((m = __builtin_ia32_pmovmskb128(*(xmm_t *)p >= (xmm_t){0}) ^ 0xffff)) { m = __builtin_ctzll(m); diff --git a/libc/str/iswlower.c b/libc/str/iswlower.c index 57d9ed92a..66a6dc0c4 100644 --- a/libc/str/iswlower.c +++ b/libc/str/iswlower.c @@ -22,7 +22,6 @@ * Returns nonzero if c is lowercase letter. */ int iswlower(wint_t c) { - int r; if (c < 0200) { return 'a' <= c && c <= 'z'; } else { diff --git a/libc/str/iswupper.c b/libc/str/iswupper.c index e13ca81d8..35c809c91 100644 --- a/libc/str/iswupper.c +++ b/libc/str/iswupper.c @@ -22,7 +22,6 @@ * Returns nonzero if c is uppercase letter. */ int iswupper(wint_t c) { - int r; if (c < 0200) { return 'A' <= c && c <= 'Z'; } else { diff --git a/libc/str/lz4cpy.c b/libc/str/lz4cpy.c index c2859d47e..d89bd3752 100644 --- a/libc/str/lz4cpy.c +++ b/libc/str/lz4cpy.c @@ -32,7 +32,8 @@ * @see rldecode() for a 16-byte decompressor */ textstartup void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) { - unsigned char *op, *ip, *ipe, *match; + unsigned char *op, *match; + const unsigned char *ip, *ipe; unsigned token, length, fifteen, offset, matchlen; for (op = dest, ip = blockdata, ipe = ip + blocksize;;) { token = *ip++; diff --git a/libc/str/lz4len.c b/libc/str/lz4len.c index 6ef059245..23ed940b3 100644 --- a/libc/str/lz4len.c +++ b/libc/str/lz4len.c @@ -28,8 +28,8 @@ * @see lz4cpy() */ size_t lz4len(const void *blockdata, size_t blocksize) { - unsigned char *ip, *ipe; - unsigned token, length, fifteen, offset, matchlen; + const unsigned char *ip, *ipe; + unsigned token, length, fifteen, matchlen; size_t unpacklen = 0; for (ip = blockdata, ipe = ip + blocksize;;) { token = *ip++; @@ -43,7 +43,6 @@ size_t lz4len(const void *blockdata, size_t blocksize) { ip += length; unpacklen += length; if (ip >= ipe) break; - offset = READ16LE(ip); matchlen = token & fifteen; ip += 2; if (matchlen == fifteen) { diff --git a/libc/str/mbrtowc.c b/libc/str/mbrtowc.c index 2a760a1dc..e3c1aae46 100644 --- a/libc/str/mbrtowc.c +++ b/libc/str/mbrtowc.c @@ -64,7 +64,7 @@ size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) { if (n) { if (OOB(c, *s)) goto ilseq; loop: - c = c << 6 | *s++ - 0x80; + c = c << 6 | (*s++ - 0x80); n--; if (!(c & (1U << 31))) { *(unsigned *)st = 0; diff --git a/libc/str/mbsrtowcs.c b/libc/str/mbsrtowcs.c index 3e90b46bc..a50fb38bc 100644 --- a/libc/str/mbsrtowcs.c +++ b/libc/str/mbsrtowcs.c @@ -114,19 +114,19 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) { s--; break; } - c = (c << 6) | *s++ - 0x80; + c = (c << 6) | (*s++ - 0x80); if (c & (1U << 31)) { if (*s - 0x80u >= 0x40) { s -= 2; break; } - c = (c << 6) | *s++ - 0x80; + c = (c << 6) | (*s++ - 0x80); if (c & (1U << 31)) { if (*s - 0x80u >= 0x40) { s -= 3; break; } - c = (c << 6) | *s++ - 0x80; + c = (c << 6) | (*s++ - 0x80); } } *ws++ = c; diff --git a/libc/str/mbtowc.c b/libc/str/mbtowc.c index ecd39af9a..d5fefe906 100644 --- a/libc/str/mbtowc.c +++ b/libc/str/mbtowc.c @@ -51,19 +51,19 @@ int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) { * insufficient to read a character */ if (n < 4 && ((c << (6 * n - 6)) & (1U << 31))) goto ilseq; if (OOB(c, *s)) goto ilseq; - c = c << 6 | *s++ - 0x80; + c = c << 6 | (*s++ - 0x80); if (!(c & (1U << 31))) { *wc = c; return 2; } if (*s - 0x80u >= 0x40) goto ilseq; - c = c << 6 | *s++ - 0x80; + c = c << 6 | (*s++ - 0x80); if (!(c & (1U << 31))) { *wc = c; return 3; } if (*s - 0x80u >= 0x40) goto ilseq; - *wc = c << 6 | *s++ - 0x80; + *wc = c << 6 | (*s++ - 0x80); return 4; ilseq: errno = EILSEQ; diff --git a/libc/str/memmem.c b/libc/str/memmem.c index aa2d63703..0f3c49981 100644 --- a/libc/str/memmem.c +++ b/libc/str/memmem.c @@ -36,12 +36,13 @@ dontasan void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { #if defined(__x86_64__) && !defined(__chibicc__) char c; - xmm_t n, *v; + xmm_t n; + const xmm_t *v; unsigned i, k, m; const char *p, *q, *e; if (IsAsan()) __asan_verify(needle, needlelen); if (IsAsan()) __asan_verify(haystack, haystacklen); - if (!needlelen) return haystack; + if (!needlelen) return (void *)haystack; if (UNLIKELY(needlelen > haystacklen)) return 0; q = needle; c = *q; @@ -72,7 +73,7 @@ dontasan void *memmem(const void *haystack, size_t haystacklen, } #else size_t i, j; - if (!needlelen) return haystack; + if (!needlelen) return (void *)haystack; if (needlelen > haystacklen) return 0; for (i = 0; i < haystacklen; ++i) { for (j = 0;; ++j) { diff --git a/libc/str/memrchr16.c b/libc/str/memrchr16.c index 654190f99..35ce9c8e8 100644 --- a/libc/str/memrchr16.c +++ b/libc/str/memrchr16.c @@ -38,7 +38,7 @@ static inline const char16_t *memrchr16_pure(const char16_t *s, char16_t c, dontasan static inline const char16_t *memrchr16_sse(const char16_t *s, char16_t c, size_t n) { size_t i; - unsigned k, m; + unsigned m; xmm_t v, t = {c, c, c, c, c, c, c, c}; for (i = n; i >= 8;) { v = *(const xmm_t *)(s + (i -= 8)); @@ -77,6 +77,6 @@ void *memrchr16(const void *s, int c, size_t n) { } return (void *)r; #else - return memrchr16_pure(s, c, n); + return (void *)memrchr16_pure(s, c, n); #endif } diff --git a/libc/str/rawmemchr.c b/libc/str/rawmemchr.c index 3d4f806d8..6b1a45a2c 100644 --- a/libc/str/rawmemchr.c +++ b/libc/str/rawmemchr.c @@ -37,8 +37,8 @@ dontasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) { unsigned k; unsigned m; - xmm_t v, *p; - xmm_t n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; + const xmm_t *p; + xmm_t v, n = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c}; k = (uintptr_t)s & 15; p = (const xmm_t *)((uintptr_t)s & -16); v = *p; @@ -54,7 +54,7 @@ dontasan static inline const char *rawmemchr_sse(const char *s, } #endif -static inline dontasan uint64_t UncheckedAlignedRead64(unsigned char *p) { +static inline dontasan uint64_t UncheckedAlignedRead64(const unsigned char *p) { return (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 | (uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 | (uint64_t)p[1] << 010 | (uint64_t)p[0] << 000; @@ -84,7 +84,7 @@ void *rawmemchr(const void *s, int c) { c &= 255; v = 0x0101010101010101ul * c; for (; (uintptr_t)p & 7; ++p) { - if (*p == c) return p; + if (*p == c) return (void *)p; } for (;; p += 8) { w = UncheckedAlignedRead64(p); @@ -94,6 +94,6 @@ void *rawmemchr(const void *s, int c) { } } assert(*p == c); - return p; + return (void *)p; #endif } diff --git a/libc/str/setlocale.c b/libc/str/setlocale.c index b7ebd61f0..a395f49da 100644 --- a/libc/str/setlocale.c +++ b/libc/str/setlocale.c @@ -24,9 +24,7 @@ /** * Sets program locale. * - * Cosmopolitan only supports the C or POSIX locale. - * - * "You can have any locale you want as long as it's C." -- Henry Ford + * Cosmopolitan only supports the C or POSIX locale with UTF-8. */ char *setlocale(int category, const char *locale) { char *res; @@ -36,7 +34,7 @@ char *setlocale(int category, const char *locale) { !strcmp(locale, "POSIX") || // !strcmp(locale, "C.UTF-8") || // !strcmp(locale, "en_US.UTF-8")) { - res = locale; + res = (char *)locale; } else { res = NULL; } diff --git a/libc/str/str.h b/libc/str/str.h index 071653de4..d66128f77 100644 --- a/libc/str/str.h +++ b/libc/str/str.h @@ -23,38 +23,38 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -int isascii(int) pureconst; -int isspace(int) pureconst; -int isalpha(int) pureconst; -int isdigit(int) pureconst; -int isalnum(int) pureconst; -int isxdigit(int) pureconst; -int isprint(int) pureconst; -int islower(int) pureconst; -int isupper(int) pureconst; -int isblank(int) pureconst; -int iscntrl(int) pureconst; -int isgraph(int) pureconst; -int tolower(int) pureconst; -int ispunct(int) pureconst; -int toupper(int) pureconst; -int toascii(int) pureconst; +int isascii(int); +int isspace(int); +int isalpha(int); +int isdigit(int); +int isalnum(int); +int isxdigit(int); +int isprint(int); +int islower(int); +int isupper(int); +int isblank(int); +int iscntrl(int); +int isgraph(int); +int tolower(int); +int ispunct(int); +int toupper(int); +int toascii(int); -int iswalnum(wint_t) pureconst; -int iswalpha(wint_t) pureconst; -int iswblank(wint_t) pureconst; -int iswcntrl(wint_t) pureconst; -int iswdigit(wint_t) pureconst; -int iswgraph(wint_t) pureconst; -int iswlower(wint_t) pureconst; -int iswspace(wint_t) pureconst; -int iswupper(wint_t) pureconst; -int iswxdigit(wint_t) pureconst; -int iswpunct(wint_t) pureconst; -int iswprint(wint_t) pureconst; -int iswseparator(wint_t) pureconst; -wint_t towlower(wint_t) pureconst; -wint_t towupper(wint_t) pureconst; +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); +int iswpunct(wint_t); +int iswprint(wint_t); +int iswseparator(wint_t); +wint_t towlower(wint_t); +wint_t towupper(wint_t); void bzero(void *, size_t) memcpyesque; void *memset(void *, int, size_t) memcpyesque; @@ -191,7 +191,7 @@ bool startswithi(const char *, const char *) strlenesque; bool endswith(const char *, const char *) strlenesque; bool istext(const void *, size_t) libcesque; bool isutf8(const void *, size_t) libcesque; -char *strsignal_r(int, char[15]) returnsnonnull libcesque dontdiscard; +char *strsignal_r(int, char[21]) returnsnonnull libcesque dontdiscard; int strerror_wr(int, uint32_t, char *, size_t) dontthrow nocallback; char16_t *chomp16(char16_t *) libcesque; diff --git a/libc/str/strcasecmp.c b/libc/str/strcasecmp.c index 0878aed5c..c10827062 100644 --- a/libc/str/strcasecmp.c +++ b/libc/str/strcasecmp.c @@ -32,7 +32,7 @@ dontasan int strcasecmp(const char *a, const char *b) { int x, y; size_t i = 0; - uint64_t v, w, d; + uint64_t v, w; if (a == b) return 0; if (IsAsan()) __asan_verify_str(a); if (IsAsan()) __asan_verify_str(b); diff --git a/libc/str/strcasestr.c b/libc/str/strcasestr.c index bac10770b..27e8205d7 100644 --- a/libc/str/strcasestr.c +++ b/libc/str/strcasestr.c @@ -38,13 +38,13 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); dontasan char *strcasestr(const char *haystack, const char *needle) { #if defined(__x86_64__) && !defined(__chibicc__) char c; - xmm_t *p; size_t i; unsigned k, m; + const xmm_t *p; xmm_t v, n1, n2, z = {0}; if (IsAsan()) __asan_verify(needle, 1); if (IsAsan()) __asan_verify(haystack, 1); - if (haystack == needle || !*needle) return 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]; @@ -71,8 +71,7 @@ dontasan char *strcasestr(const char *haystack, const char *needle) { return 0; #else size_t i; - unsigned k, m; - if (haystack == needle || !*needle) return haystack; + if (haystack == needle || !*needle) return (void *)haystack; for (;;) { for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; diff --git a/libc/str/strstr.c b/libc/str/strstr.c index e15b2a7e5..0d25edeab 100644 --- a/libc/str/strstr.c +++ b/libc/str/strstr.c @@ -37,13 +37,13 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16))); */ dontasan char *strstr(const char *haystack, const char *needle) { #if defined(__x86_64__) && !defined(__chibicc__) - xmm_t *p; size_t i; unsigned k, m; + const xmm_t *p; xmm_t v, n, z = {0}; if (IsAsan()) __asan_verify(needle, 1); if (IsAsan()) __asan_verify(haystack, 1); - if (haystack == needle || !*needle) return 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}; @@ -69,8 +69,7 @@ dontasan char *strstr(const char *haystack, const char *needle) { return 0; #else size_t i; - unsigned k, m; - if (haystack == needle || !*needle) return haystack; + if (haystack == needle || !*needle) return (void *)haystack; for (;;) { for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; diff --git a/libc/str/thompike.h b/libc/str/thompike.h index 4cf4bb13e..c4c4512b3 100644 --- a/libc/str/thompike.h +++ b/libc/str/thompike.h @@ -6,6 +6,6 @@ #define ThomPikeByte(x) ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3)) #define ThomPikeLen(x) (7 - ThomPikeMsb(x)) #define ThomPikeMsb(x) ((255 & (x)) < 252 ? _bsr(255 & ~(x)) : 1) -#define ThomPikeMerge(x, y) ((x) << 6 | 077 & (y)) +#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y))) #endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */ diff --git a/libc/str/tprecode8to16.c b/libc/str/tprecode8to16.c index 4dd15b28f..13547c0cc 100644 --- a/libc/str/tprecode8to16.c +++ b/libc/str/tprecode8to16.c @@ -58,7 +58,7 @@ static inline dontasan axdx_t tprecode8to16_sse2(char16_t *dst, size_t dstsize, axdx_t tprecode8to16(char16_t *dst, size_t dstsize, const char *src) { axdx_t r; unsigned w; - int x, y, a, b, i, n; + int x, a, b, i, n; r.ax = 0; r.dx = 0; for (;;) { diff --git a/libc/str/wcschr.c b/libc/str/wcschr.c index 9ebd25e29..2b60b910f 100644 --- a/libc/str/wcschr.c +++ b/libc/str/wcschr.c @@ -23,7 +23,7 @@ */ wchar_t *wcschr(const wchar_t *s, wchar_t c) { for (;; ++s) { - if (*s == c) return s; + if (*s == c) return (wchar_t *)s; if (!*s) return 0; } } diff --git a/libc/str/wcschrnul.c b/libc/str/wcschrnul.c index 58d5253d9..3a33efc7f 100644 --- a/libc/str/wcschrnul.c +++ b/libc/str/wcschrnul.c @@ -20,7 +20,7 @@ wchar_t *wcschrnul(const wchar_t *s, wchar_t c) { for (;; ++s) { - if (*s == c) return s; - if (!*s) return s; + if (*s == c) return (wchar_t *)s; + if (!*s) return (wchar_t *)s; } } diff --git a/libc/str/wmemrchr.c b/libc/str/wmemrchr.c index d8f2567ac..8da8e616f 100644 --- a/libc/str/wmemrchr.c +++ b/libc/str/wmemrchr.c @@ -39,7 +39,7 @@ static inline const wchar_t *wmemrchr_pure(const wchar_t *s, wchar_t c, dontasan static inline const wchar_t *wmemrchr_sse(const wchar_t *s, wchar_t c, size_t n) { size_t i; - unsigned k, m; + unsigned m; xmm_t v, t = {c, c, c, c}; for (i = n; i >= 4;) { v = *(const xmm_t *)(s + (i -= 4)); @@ -78,6 +78,6 @@ void *wmemrchr(const wchar_t *s, wchar_t c, size_t n) { r = wmemrchr_sse(s, c, n); return (void *)r; #else - return wmemrchr_pure(s, c, n); + return (void *)wmemrchr_pure(s, c, n); #endif } diff --git a/libc/testlib/benchrunner.c b/libc/testlib/benchrunner.c index 74fce870e..273342092 100644 --- a/libc/testlib/benchrunner.c +++ b/libc/testlib/benchrunner.c @@ -63,7 +63,6 @@ void EnableCruiseControlForCool(void) { * @see BENCH() */ void testlib_runallbenchmarks(void) { - int e; __log_level = kLogWarn; EnableCruiseControlForCool(); testlib_runtestcases(__bench_start, __bench_end, testlib_benchwarmup); diff --git a/libc/testlib/comborunner.c b/libc/testlib/comborunner.c index 9de2fd06b..d53656584 100644 --- a/libc/testlib/comborunner.c +++ b/libc/testlib/comborunner.c @@ -68,7 +68,8 @@ static void testlib_describecombo(struct ComboProduct *product, static void testlib_callcombos(struct ComboProduct *product, const struct TestFixture *combos, - testfn_t *test_start, testfn_t *test_end) { + const testfn_t *test_start, + const testfn_t *test_end) { for (;;) { testlib_describecombo(product, combos); for (unsigned i = 0; i < product->n; ++i) { @@ -88,7 +89,7 @@ static void testlib_callcombos(struct ComboProduct *product, * @see ape/ape.lds * @see libc/testlib/testlib.h */ -void testlib_runcombos(testfn_t *test_start, testfn_t *test_end, +void testlib_runcombos(const testfn_t *test_start, const testfn_t *test_end, const struct TestFixture *combo_start, const struct TestFixture *combo_end) { struct ComboProduct *product; diff --git a/libc/testlib/ezbench.h b/libc/testlib/ezbench.h index 1e60fdb1d..15cde5064 100644 --- a/libc/testlib/ezbench.h +++ b/libc/testlib/ezbench.h @@ -151,6 +151,9 @@ COSMOPOLITAN_C_START_ __testlib_yield(); \ Core = __testlib_getcore(); \ Interrupts = __testlib_getinterrupts(); \ + (void)Toto; \ + (void)Core; \ + (void)Interrupts; \ EXPR; \ Speculative = BENCHLOOPER(__startbench, __endbench, 32, (EXPR)); \ } while (++Tries < EZBENCH_TRIES && !Speculative); \ diff --git a/libc/testlib/fixturerunner.c b/libc/testlib/fixturerunner.c index d61d3e598..59071ef89 100644 --- a/libc/testlib/fixturerunner.c +++ b/libc/testlib/fixturerunner.c @@ -31,7 +31,7 @@ int testlib_countfixtures(const struct TestFixture *start, * @see ape/ape.lds * @see libc/testlib/testlib.h */ -void testlib_runfixtures(testfn_t *test_start, testfn_t *test_end, +void testlib_runfixtures(const testfn_t *test_start, const testfn_t *test_end, const struct TestFixture *fixture_start, const struct TestFixture *fixture_end) { unsigned i, count; diff --git a/libc/testlib/quota.c b/libc/testlib/quota.c index 111c424a0..1fcd21318 100644 --- a/libc/testlib/quota.c +++ b/libc/testlib/quota.c @@ -46,7 +46,6 @@ static dontasan dontubsan relegated uint64_t CountMappedBytes(void) { } static relegated void DieBecauseOfQuota(int rc, const char *message) { - int e = errno; char hostname[32]; stpcpy(hostname, "unknown"); gethostname(hostname, sizeof(hostname)); diff --git a/libc/testlib/showerror.c b/libc/testlib/showerror.c index 5edb74e41..774272d4b 100644 --- a/libc/testlib/showerror.c +++ b/libc/testlib/showerror.c @@ -40,7 +40,6 @@ const char *testlib_showerror_symbol; void testlib_showerror(const char *file, int line, const char *func, const char *method, const char *symbol, const char *code, char *v1, char *v2) { - char *p; char hostname[128]; __stpcpy(hostname, "unknown"); gethostname(hostname, sizeof(hostname)); diff --git a/libc/testlib/testlib.h b/libc/testlib/testlib.h index 071e6780c..432ce727a 100644 --- a/libc/testlib/testlib.h +++ b/libc/testlib/testlib.h @@ -388,10 +388,11 @@ void testlib_runalltests(void); const char *testlib_strerror(void); void testlib_runallbenchmarks(void); bool testlib_memoryexists(const void *); -void testlib_runtestcases(testfn_t *, testfn_t *, testfn_t); -void testlib_runcombos(testfn_t *, testfn_t *, const struct TestFixture *, - const struct TestFixture *); -void testlib_runfixtures(testfn_t *, testfn_t *, const struct TestFixture *, +void testlib_runtestcases(const testfn_t *, const testfn_t *, testfn_t); +void testlib_runcombos(const testfn_t *, const testfn_t *, + const struct TestFixture *, const struct TestFixture *); +void testlib_runfixtures(const testfn_t *, const testfn_t *, + const struct TestFixture *, const struct TestFixture *); int testlib_countfixtures(const struct TestFixture *, const struct TestFixture *); diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index dbcb93d98..4fbbd5f04 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -166,8 +166,6 @@ static void SetLimit(int resource, uint64_t soft, uint64_t hard) { * Generic test program main function. */ dontasan int main(int argc, char *argv[]) { - unsigned cpus; - const char *comdbg; __log_level = kLogInfo; GetOpts(argc, argv); setenv("GDB", "", true); diff --git a/libc/testlib/testrunner.c b/libc/testlib/testrunner.c index e4fe5dc3a..91744303c 100644 --- a/libc/testlib/testrunner.c +++ b/libc/testlib/testrunner.c @@ -101,7 +101,8 @@ static void TearDownTmpDir(void) { /** * Runs all test case functions in sorted order. */ -void testlib_runtestcases(testfn_t *start, testfn_t *end, testfn_t warmup) { +void testlib_runtestcases(const testfn_t *start, const testfn_t *end, + testfn_t warmup) { // getpid() calls are inserted to help visually see tests in traces // which can be performed on Linux, FreeBSD, OpenBSD, and XNU: // diff --git a/libc/thread/makecontext.c b/libc/thread/makecontext.c index bd75b2418..02af6ea57 100644 --- a/libc/thread/makecontext.c +++ b/libc/thread/makecontext.c @@ -94,7 +94,6 @@ void makecontext(ucontext_t *uc, void func(), int argc, ...) { va_list va; long sp, sb; struct Gadget *call; - struct StackFrame *sf; // allocate call sp = sb = (long)uc->uc_stack.ss_sp; diff --git a/libc/thread/mktls.c b/libc/thread/mktls.c index 5c687fb2e..5839d1502 100644 --- a/libc/thread/mktls.c +++ b/libc/thread/mktls.c @@ -86,8 +86,8 @@ static char *_mktls_below(struct CosmoTib **out_tib) { static char *_mktls_above(struct CosmoTib **out_tib) { size_t hiz, siz; + struct CosmoTib *tib; char *mem, *dtv, *tls; - struct CosmoTib *tib, *old; // allocate memory for tdata, tbss, and tib hiz = ROUNDUP(sizeof(*tib) + 2 * sizeof(void *), I(_tls_align)); diff --git a/libc/thread/pthread_atfork.c b/libc/thread/pthread_atfork.c index 2aaf7b31d..2e7bb84d4 100644 --- a/libc/thread/pthread_atfork.c +++ b/libc/thread/pthread_atfork.c @@ -47,7 +47,6 @@ static void _pthread_purge(void) { static void _pthread_onfork(int i) { struct AtFork *a; - struct PosixThread *pt; unassert(0 <= i && i <= 2); if (!i) pthread_spin_lock(&_atforks.lock); for (a = _atforks.list; a; a = a->p[!i]) { @@ -91,7 +90,7 @@ void _pthread_onfork_child(void) { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&__mmi_lock_obj, &attr); pthread_mutex_init(&__fds_lock_obj, &attr); - pthread_spin_init(&_pthread_lock, 0); + (void)pthread_spin_init(&_pthread_lock, 0); // call user-supplied forked child callbacks _pthread_onfork(2); diff --git a/libc/thread/pthread_cancel.c b/libc/thread/pthread_cancel.c index ec38015e6..8dd2d3d1c 100644 --- a/libc/thread/pthread_cancel.c +++ b/libc/thread/pthread_cancel.c @@ -343,7 +343,6 @@ void pthread_testcancel(void) { * in masked mode when the calling thread has been cancelled */ errno_t pthread_testcancel_np(void) { - int rc; struct PosixThread *pt; if (!__tls_enabled) return 0; if (!(pt = (struct PosixThread *)__get_tls()->tib_pthread)) return 0; diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index 5c031edba..12b8ee5a3 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -74,14 +74,12 @@ void _pthread_free(struct PosixThread *pt) { void pthread_kill_siblings_np(void) { struct Dll *e, *e2; struct PosixThread *pt, *self; - enum PosixThreadStatus status; self = (struct PosixThread *)__get_tls()->tib_pthread; pthread_spin_lock(&_pthread_lock); for (e = dll_first(_pthread_list); e; e = e2) { e2 = dll_next(_pthread_list, e); pt = POSIXTHREAD_CONTAINER(e); if (pt != self) { - status = atomic_load_explicit(&pt->status, memory_order_acquire); pthread_kill((pthread_t)pt, SIGKILL); dll_remove(&_pthread_list, e); pthread_spin_unlock(&_pthread_lock); @@ -95,7 +93,6 @@ static int PosixThread(void *arg, int tid) { void *rc; struct sigaltstack ss; struct PosixThread *pt = arg; - enum PosixThreadStatus status; unassert(__get_tls()->tib_tid > 0); if (pt->altstack) { ss.ss_flags = 0; diff --git a/libc/thread/pthread_ungarbage.c b/libc/thread/pthread_ungarbage.c index 636e94c88..cdcdd7d13 100644 --- a/libc/thread/pthread_ungarbage.c +++ b/libc/thread/pthread_ungarbage.c @@ -21,7 +21,6 @@ #include "libc/thread/tls.h" void _pthread_ungarbage(void) { - int i; struct Garbages *g; struct CosmoTib *tib; tib = __get_tls(); diff --git a/libc/thread/sem_open.c b/libc/thread/sem_open.c index 02f0c55d3..9017d9096 100644 --- a/libc/thread/sem_open.c +++ b/libc/thread/sem_open.c @@ -136,7 +136,7 @@ static struct Semaphore *sem_open_reopen(const char *path) { static struct Semaphore *sem_open_get(const sem_t *sem, struct Semaphore ***out_prev) { - struct Semaphore *s, *t, **p; + struct Semaphore *s, **p; for (p = &g_semaphores.list, s = *p; s; p = &s->next, s = s->next) { if (s && sem == s->sem) { *out_prev = p; @@ -176,9 +176,10 @@ static struct Semaphore *sem_open_get(const sem_t *sem, sem_t *sem_open(const char *name, int oflag, ...) { sem_t *sem; va_list va; + const char *path; struct Semaphore *s; + char pathbuf[PATH_MAX]; unsigned mode = 0, value = 0; - char *path, pathbuf[PATH_MAX]; if (oflag & ~(O_CREAT | O_EXCL)) { einval(); return SEM_FAILED; @@ -300,9 +301,10 @@ int sem_close(sem_t *sem) { * @raise ENAMETOOLONG if too long */ int sem_unlink(const char *name) { + const char *path; int rc, e = errno; struct Semaphore *s; - char *path, pathbuf[PATH_MAX]; + char pathbuf[PATH_MAX]; if (!(path = sem_path_np(name, pathbuf, sizeof(pathbuf)))) return -1; if ((rc = unlink(path)) == -1 && IsWindows() && errno == EACCES) { sem_open_init(); diff --git a/libc/thread/sem_timedwait.c b/libc/thread/sem_timedwait.c index 33e7e7320..04e92f14e 100644 --- a/libc/thread/sem_timedwait.c +++ b/libc/thread/sem_timedwait.c @@ -53,7 +53,6 @@ static void sem_timedwait_cleanup(void *arg) { */ int sem_timedwait(sem_t *sem, const struct timespec *abstime) { int e, i, v, rc; - struct timespec ts; e = errno; for (i = 0; i < 7; ++i) { diff --git a/libc/thread/thread.h b/libc/thread/thread.h index 482d52222..51832fb01 100644 --- a/libc/thread/thread.h +++ b/libc/thread/thread.h @@ -218,11 +218,12 @@ void pthread_testcancel(void); #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 && \ !defined(__STRICT_ANSI__) && !defined(MODE_DBG) extern const errno_t EBUSY; -#define pthread_spin_lock(pSpin) \ - ({ \ - pthread_spinlock_t *_s = pSpin; \ - while (__atomic_test_and_set(&_s->_lock, __ATOMIC_ACQUIRE)) donothing; \ - 0; \ +#define pthread_spin_lock(pSpin) \ + ({ \ + pthread_spinlock_t *_s = pSpin; \ + while (__atomic_test_and_set(&_s->_lock, __ATOMIC_ACQUIRE)) { \ + } \ + 0; \ }) #define pthread_spin_unlock(pSpin) \ ({ \ diff --git a/libc/thread/tls2.h b/libc/thread/tls2.internal.h similarity index 95% rename from libc/thread/tls2.h rename to libc/thread/tls2.internal.h index 49cae06c7..d046f8d35 100644 --- a/libc/thread/tls2.h +++ b/libc/thread/tls2.internal.h @@ -12,7 +12,7 @@ COSMOPOLITAN_C_START_ * This should be favored over __get_tls() for .privileged code that * can't be self-modified by __enable_tls(). */ -privileged static inline struct CosmoTib *__get_tls_privileged(void) { +__funline struct CosmoTib *__get_tls_privileged(void) { char *tib, *lin = (char *)0x30; if (IsLinux() || IsFreebsd() || IsNetbsd() || IsOpenbsd() || IsMetal()) { asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory"); diff --git a/libc/thread/wait0.c b/libc/thread/wait0.c index 5972b5290..0ad3ca213 100644 --- a/libc/thread/wait0.c +++ b/libc/thread/wait0.c @@ -41,7 +41,7 @@ * @raise EBUSY if `abstime` was specified and deadline expired * @cancellationpoint */ -errno_t _wait0(const atomic_int *ctid, struct timespec *abstime) { +errno_t _wait0(atomic_int *ctid, struct timespec *abstime) { int x, e, rc = 0; // "The behavior is undefined if the value specified by the thread // argument to pthread_join() refers to the calling thread." diff --git a/libc/thread/wait0.internal.h b/libc/thread/wait0.internal.h index 5b716dec9..d2fc59aab 100644 --- a/libc/thread/wait0.internal.h +++ b/libc/thread/wait0.internal.h @@ -1,11 +1,10 @@ #ifndef COSMOPOLITAN_LIBC_INTRIN_WAIT0_H_ #define COSMOPOLITAN_LIBC_INTRIN_WAIT0_H_ -#include "libc/atomic.h" #include "libc/calls/struct/timespec.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -errno_t _wait0(const atomic_int *, struct timespec *); +errno_t _wait0(_Atomic(int) *, struct timespec *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/tinymath/acos.c b/libc/tinymath/acos.c index b5320e055..e9695f496 100644 --- a/libc/tinymath/acos.c +++ b/libc/tinymath/acos.c @@ -110,7 +110,7 @@ double acos(double x) /* |x| >= 1 or nan */ if (ix >= 0x3ff00000) { lx = u.i; - if ((ix-0x3ff00000 | lx) == 0) { + if (((ix-0x3ff00000) | lx) == 0) { /* acos(1)=0, acos(-1)=pi */ if (hx >> 31) return 2*pio2_hi + 0x1p-120f; diff --git a/libc/tinymath/asin.c b/libc/tinymath/asin.c index eecd92803..19b38879b 100644 --- a/libc/tinymath/asin.c +++ b/libc/tinymath/asin.c @@ -119,7 +119,7 @@ double asin(double x) /* |x| >= 1 or nan */ if (ix >= 0x3ff00000) { lx = u.i; - if (!(ix-0x3ff00000 | lx)) + if (!((ix-0x3ff00000) | lx)) /* asin(1) = +-pi/2 with inexact */ return x*pio2_hi + 0x1p-120f; return 0/(x-x); diff --git a/libc/tinymath/ceil.c b/libc/tinymath/ceil.c index 66dee5e66..26eccf25a 100644 --- a/libc/tinymath/ceil.c +++ b/libc/tinymath/ceil.c @@ -43,7 +43,6 @@ asm(".include \"libc/disclaimer.inc\""); #elif FLT_EVAL_METHOD==2 #define EPS LDBL_EPSILON #endif -static const double_t toint = 1/EPS; /** * Returns smallest integral value not less than 𝑥. @@ -74,6 +73,7 @@ double ceil(double x) #else + static const double_t toint = 1/EPS; union {double f; uint64_t i;} u = {x}; int e = u.i >> 52 & 0x7ff; double_t y; diff --git a/libc/tinymath/feval.internal.h b/libc/tinymath/feval.internal.h index 00feadff2..5a262326d 100644 --- a/libc/tinymath/feval.internal.h +++ b/libc/tinymath/feval.internal.h @@ -5,14 +5,17 @@ COSMOPOLITAN_C_START_ static inline void fevalf(float x) { volatile float y = x; + (void)y; } static inline void feval(double x) { volatile double y = x; + (void)y; } static inline void fevall(long double x) { volatile long double y = x; + (void)y; } COSMOPOLITAN_C_END_ diff --git a/libc/tinymath/floor.c b/libc/tinymath/floor.c index 48768bb92..21074f27d 100644 --- a/libc/tinymath/floor.c +++ b/libc/tinymath/floor.c @@ -43,7 +43,6 @@ asm(".include \"libc/disclaimer.inc\""); #elif FLT_EVAL_METHOD==2 #define EPS LDBL_EPSILON #endif -static const double_t toint = 1/EPS; /** * Returns largest integral value not greater than 𝑥. @@ -74,6 +73,7 @@ double floor(double x) #else + static const double_t toint = 1/EPS; union {double f; uint64_t i;} u = {x}; int e = u.i >> 52 & 0x7ff; double_t y; diff --git a/libc/tinymath/fma.c b/libc/tinymath/fma.c index 25892c0fb..453c5cc81 100644 --- a/libc/tinymath/fma.c +++ b/libc/tinymath/fma.c @@ -154,7 +154,7 @@ double fma(double x, double y, double z) if (d > 0) { if (d < 64) { zlo = nz.m<>64-d; + zhi = nz.m>>(64-d); } else { zlo = 0; zhi = nz.m; @@ -162,7 +162,7 @@ double fma(double x, double y, double z) d -= 64; if (d == 0) { } else if (d < 64) { - rlo = rhi<<64-d | rlo>>d | !!(rlo<<64-d); + rlo = rhi<<(64-d) | rlo>>d | !!(rlo<<(64-d)); rhi = rhi>>d; } else { rlo = 1; @@ -175,7 +175,7 @@ double fma(double x, double y, double z) if (d == 0) { zlo = nz.m; } else if (d < 64) { - zlo = nz.m>>d | !!(nz.m<<64-d); + zlo = nz.m>>d | !!(nz.m<<(64-d)); } else { zlo = 1; } @@ -207,7 +207,7 @@ double fma(double x, double y, double z) e += 64; d = a_clz_64(rhi)-1; /* note: d > 0 */ - rhi = rhi<>64-d | !!(rlo<>(64-d) | !!(rlo<>d | !!(rhi<<64-d) ) << d; + i = ( rhi>>d | !!(rhi<<(64-d)) ) << d; if (sign) i = -i; r = i; diff --git a/libc/vga/tty-graph.inc b/libc/vga/tty-graph.inc index 5b05bd974..e5688d832 100644 --- a/libc/vga/tty-graph.inc +++ b/libc/vga/tty-graph.inc @@ -257,7 +257,7 @@ static MAYUNROLLLOOPS void FILLRECT(struct Tty *tty, size_t gy, size_t gx, size_t fill_ht, size_t fill_wid, COLOR bg) { size_t xs = tty->xs; char *cplotter = tty->canvas + gy * xs + gx * sizeof(COLOR); - size_t yleft = fill_ht, xleft; + size_t yleft = fill_ht; while (yleft-- != 0) { COLOR *plotter = (COLOR *)cplotter; size_t i; diff --git a/libc/vga/tty.greg.c b/libc/vga/tty.greg.c index 953d735af..daa9d9a30 100644 --- a/libc/vga/tty.greg.c +++ b/libc/vga/tty.greg.c @@ -313,7 +313,6 @@ static void TtySetXlat(struct Tty *tty, wchar_t *xlat) { } static void TtySetCodepage(struct Tty *tty, char id) { - unsigned i; switch (id) { default: case 'B': @@ -676,7 +675,7 @@ static void TtyEraseLine(struct Tty *tty) { } static void TtyEraseCells(struct Tty *tty) { - int yn, xn, yi, xi, n, left; + int yn, xn, yi, xi, left; yn = Yn(tty); xn = Xn(tty); yi = tty->y; @@ -1310,8 +1309,8 @@ ssize_t _TtyWriteInput(struct Tty *tty, const void *data, size_t n) { int c; bool cr; char *p; + size_t i, j; const char *q; - size_t i, j, m; q = data; p = tty->input.p; i = tty->input.i; @@ -1341,7 +1340,6 @@ ssize_t _TtyWriteInput(struct Tty *tty, const void *data, size_t n) { } ssize_t _TtyRead(struct Tty *tty, void *buf, size_t size) { - char *p; size_t n; n = MIN(size, tty->input.i); #ifdef VGA_PERSNICKETY_STATUS diff --git a/libc/x/utf16to32.c b/libc/x/utf16to32.c index 95d455def..b09946eb7 100644 --- a/libc/x/utf16to32.c +++ b/libc/x/utf16to32.c @@ -31,9 +31,7 @@ wchar_t *utf16to32(const char16_t *p, size_t n, size_t *z) { wint_t x, y; wchar_t *r, *q; - unsigned m, j, w; 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 ((q = r = malloc(n * 4 + 8 + 1))) { diff --git a/libc/x/utf16to8.c b/libc/x/utf16to8.c index 574099d5b..7cfbc5834 100644 --- a/libc/x/utf16to8.c +++ b/libc/x/utf16to8.c @@ -41,9 +41,9 @@ static const int16_t kDel16[8] = {127, 127, 127, 127, 127, 127, 127, 127}; * @param z if non-NULL receives output length */ char *utf16to8(const char16_t *p, size_t n, size_t *z) { + unsigned w; char *r, *q; wint_t x, y; - unsigned m, j, w; const char16_t *e; int16_t v1[8], v2[8], v3[8], vz[8]; if (z) *z = 0; diff --git a/libc/x/utf8to32.c b/libc/x/utf8to32.c index 0208d5e41..147c03f30 100644 --- a/libc/x/utf8to32.c +++ b/libc/x/utf8to32.c @@ -37,7 +37,6 @@ * @param z if non-NULL receives output length */ wchar_t *utf8to32(const char *p, size_t n, size_t *z) { - int e; size_t i; unsigned m, j; wint_t x, a, b; diff --git a/libc/x/xasprintf.h b/libc/x/xasprintf.h index a7d7db47b..eb8471ad2 100644 --- a/libc/x/xasprintf.h +++ b/libc/x/xasprintf.h @@ -3,7 +3,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -char *xasprintf(const char *, ...) printfesque(1) paramsnonnull((1)) +char *xasprintf(const char *, ...) paramsnonnull((1)) returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; char *xvasprintf(const char *, va_list) paramsnonnull() returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull; diff --git a/libc/x/xbarf.c b/libc/x/xbarf.c index e6c6d9ed6..4e9fd9748 100644 --- a/libc/x/xbarf.c +++ b/libc/x/xbarf.c @@ -31,9 +31,9 @@ * @note this is uninterruptible */ int xbarf(const char *path, const void *data, size_t size) { - char *p; ssize_t rc; int fd, res; + const char *p; size_t i, wrote; res = 0; p = data; diff --git a/libc/x/xbasename.c b/libc/x/xbasename.c index edf97680d..c9d81dcaa 100644 --- a/libc/x/xbasename.c +++ b/libc/x/xbasename.c @@ -26,8 +26,9 @@ */ char *xbasename(const char *path) { char *base; - path = xstrdup(path); - base = xstrdup(basename(path)); - free(path); + char *path2; + path2 = xstrdup(path); + base = xstrdup(basename(path2)); + free(path2); return base; } diff --git a/libc/x/xdirname.c b/libc/x/xdirname.c index cb728a877..582c444fb 100644 --- a/libc/x/xdirname.c +++ b/libc/x/xdirname.c @@ -25,8 +25,9 @@ */ char *xdirname(const char *path) { char *dirp; - path = xstrdup(path); - dirp = xstrdup(dirname(path)); - free(path); + char *path2; + path2 = xstrdup(path); + dirp = xstrdup(dirname(path2)); + free(path2); return dirp; } diff --git a/libc/x/xhomedir.c b/libc/x/xhomedir.c index dce954f45..7564d221e 100644 --- a/libc/x/xhomedir.c +++ b/libc/x/xhomedir.c @@ -25,7 +25,6 @@ * Returns home directory. */ char *xhomedir(void) { - int fd; const char *a, *b; if ((a = getenv("HOME"))) { b = ""; diff --git a/libc/x/xslurp.c b/libc/x/xslurp.c index 610859763..28773d274 100644 --- a/libc/x/xslurp.c +++ b/libc/x/xslurp.c @@ -33,8 +33,8 @@ */ void *xslurp(const char *path, size_t *opt_out_size) { int fd; + char *res; size_t i, got; - char *res, *p; ssize_t rc, size; res = NULL; if ((fd = open(path, O_RDONLY)) != -1) { diff --git a/libc/x/xstrmul.c b/libc/x/xstrmul.c index 970b258ce..7a50174bc 100644 --- a/libc/x/xstrmul.c +++ b/libc/x/xstrmul.c @@ -25,7 +25,7 @@ */ char *xstrmul(const char *s, size_t n) { char *p; - size_t i, m, size; + size_t i, m; m = strlen(s); p = xcalloc(n + 1, m); for (i = 0; i < n; ++i) memcpy(p + i * m, s, m); diff --git a/libc/zip.internal.h b/libc/zip.internal.h index 5dc300daa..8893d384c 100644 --- a/libc/zip.internal.h +++ b/libc/zip.internal.h @@ -225,7 +225,7 @@ int IsZipEocd64(const uint8_t *, size_t, size_t); int GetZipCfileMode(const uint8_t *); uint64_t GetZipCdirOffset(const uint8_t *); uint64_t GetZipCdirRecords(const uint8_t *); -void *GetZipCdirComment(const uint8_t *); +const void *GetZipCdirComment(const uint8_t *); uint64_t GetZipCdirSize(const uint8_t *); uint64_t GetZipCdirCommentSize(const uint8_t *); uint64_t GetZipCfileUncompressedSize(const uint8_t *); diff --git a/net/finger/describesyn.c b/net/finger/describesyn.c index 2d0ac4195..2d8d5c745 100644 --- a/net/finger/describesyn.c +++ b/net/finger/describesyn.c @@ -52,7 +52,7 @@ */ char *DescribeSyn(char *q, size_t m, const char *p, size_t n) { char *e; - int i, j, k, r, iplen, tcplen, ttl, wsize, mss; + int i, j, k, iplen, tcplen, ttl, wsize, mss; if (n >= 20 + 20 && n >= (iplen = (p[0] & 0x0F) * 4) + 20 && n >= iplen + (tcplen = ((p[iplen + 12] & 0xF0) >> 4) * 4)) { e = q + m; diff --git a/net/finger/fingersyn.c b/net/finger/fingersyn.c index 096cd04ff..e2d343aa3 100644 --- a/net/finger/fingersyn.c +++ b/net/finger/fingersyn.c @@ -27,7 +27,7 @@ */ uint32_t FingerSyn(const char *p, size_t n) { uint32_t h = 0; - int i, j, k, q, r, iplen, tcplen, ttl; + int i, j, k, iplen, tcplen, ttl; if (n >= 20 + 20 && n >= (iplen = (p[0] & 0x0F) * 4) + 20 && n >= iplen + (tcplen = ((p[iplen + 12] & 0xF0) >> 4) * 4)) { n = iplen + tcplen; diff --git a/net/http/decodelatin1.c b/net/http/decodelatin1.c index 04ec84bd7..69010d847 100644 --- a/net/http/decodelatin1.c +++ b/net/http/decodelatin1.c @@ -53,7 +53,7 @@ char *DecodeLatin1(const char *p, size_t n, size_t *z) { *q++ = c; } else { *q++ = 0300 | c >> 6; - *q++ = 0200 | c & 077; + *q++ = 0200 | (c & 077); } } if (z) *z = q - r; diff --git a/net/http/encodelatin1.c b/net/http/encodelatin1.c index abb15c433..a6deb74c1 100644 --- a/net/http/encodelatin1.c +++ b/net/http/encodelatin1.c @@ -51,7 +51,7 @@ char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) { c = p[i++] & 0xff; if (c >= 0300) { if ((c <= 0303) && i < n && (p[i] & 0300) == 0200) { - c = (c & 037) << 6 | p[i++] & 077; + c = (c & 037) << 6 | (p[i++] & 077); } else { goto Invalid; } diff --git a/net/http/escapeurl.c b/net/http/escapeurl.c index eacbcc55f..d46e55d76 100644 --- a/net/http/escapeurl.c +++ b/net/http/escapeurl.c @@ -45,7 +45,7 @@ char *EscapeUrl(const char *p, size_t n, size_t *z, const char T[256]) { if (n == -1) n = p ? strlen(p) : 0; if (z) *z = 0; if ((q = r = malloc(n * 6 + 1))) { - v.p = p, v.n = n; + v.p = (char *)p, v.n = n; q = EscapeUrlView(r, &v, T); if (z) *z = q - r; *q++ = '\0'; diff --git a/net/http/foldheader.c b/net/http/foldheader.c index 5d019d2d1..bd010dff4 100644 --- a/net/http/foldheader.c +++ b/net/http/foldheader.c @@ -24,7 +24,7 @@ /** * Collapses repeating headers onto a single line. */ -char *FoldHeader(struct HttpMessage *msg, char *b, int h, size_t *z) { +char *FoldHeader(struct HttpMessage *msg, const char *b, int h, size_t *z) { char *p, *p2; size_t i, n, m; struct HttpHeader *x; diff --git a/net/http/http.h b/net/http/http.h index aa12ffe90..5e70c0370 100644 --- a/net/http/http.h +++ b/net/http/http.h @@ -214,7 +214,7 @@ bool IsMimeType(const char *, size_t, const char *); ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *); const char *FindContentType(const char *, size_t); bool IsNoCompressExt(const char *, size_t); -char *FoldHeader(struct HttpMessage *, char *, int, size_t *); +char *FoldHeader(struct HttpMessage *, const char *, int, size_t *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/net/http/indentlines.c b/net/http/indentlines.c index be1305e7f..d5c226af2 100644 --- a/net/http/indentlines.c +++ b/net/http/indentlines.c @@ -33,7 +33,7 @@ char *IndentLines(const char *p, size_t n, size_t *z, size_t j) { char *r, *q; const char *l; - size_t i, t, m, a; + size_t t, m, a; if (n == -1) n = p ? strlen(p) : 0; r = 0; t = 0; diff --git a/net/http/isnocompressext.c b/net/http/isnocompressext.c index 941c6ede2..4ece9f373 100644 --- a/net/http/isnocompressext.c +++ b/net/http/isnocompressext.c @@ -39,7 +39,7 @@ static const char kNoCompressExts[][8] = { }; static bool BisectNoCompressExts(uint64_t ext) { - int c, m, l, r; + int m, l, r; l = 0; r = ARRAYLEN(kNoCompressExts) - 1; while (l <= r) { diff --git a/net/http/parsehttpdatetime.c b/net/http/parsehttpdatetime.c index 5924760d8..41db6c052 100644 --- a/net/http/parsehttpdatetime.c +++ b/net/http/parsehttpdatetime.c @@ -17,8 +17,8 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" -#include "libc/time/time.h" #include "libc/str/str.h" +#include "libc/time/time.h" #include "net/http/http.h" static unsigned ParseMonth(const char *p) { @@ -41,7 +41,7 @@ static unsigned ParseMonth(const char *p) { * @see FormatHttpDateTime() */ int64_t ParseHttpDateTime(const char *p, size_t n) { - unsigned weekday, year, month, day, hour, minute, second, yday, leap; + unsigned year, month, day, hour, minute, second, yday, leap; if (n == -1) n = p ? strlen(p) : 0; if (n != 29) return 0; day = (p[5] - '0') * 10 + (p[6] - '0') - 1; diff --git a/net/http/parseurl.c b/net/http/parseurl.c index 70dd0b4dc..469591a13 100644 --- a/net/http/parseurl.c +++ b/net/http/parseurl.c @@ -33,7 +33,7 @@ struct UrlParser { static void EmitLatin1(char **p, int c) { (*p)[0] = 0300 | c >> 6; - (*p)[1] = 0200 | c & 077; + (*p)[1] = 0200 | (c & 077); *p += 2; } @@ -149,7 +149,7 @@ static void ParseAuthority(struct UrlParser *u, struct Url *h) { if (c) { h->user.p = u->q; h->user.n = c - 1 - u->q; - h->pass.p = c; + h->pass.p = (char *)c; h->pass.n = u->p - c; c = NULL; t = 1; @@ -169,7 +169,7 @@ static void ParseAuthority(struct UrlParser *u, struct Url *h) { if (t == 2) { h->host.p = u->q; h->host.n = c - 1 - u->q; - h->port.p = c; + h->port.p = (char *)c; h->port.n = u->p - c; c = NULL; } else { diff --git a/net/http/tokenbucket.c b/net/http/tokenbucket.c index 354ac8999..d2f1f42a6 100644 --- a/net/http/tokenbucket.c +++ b/net/http/tokenbucket.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/atomic.h" #include "net/http/tokenbucket.h" +#include "libc/intrin/atomic.h" /** * Atomically increments all signed bytes in array, without overflowing. @@ -40,7 +40,7 @@ void ReplenishTokens(atomic_uint_fast64_t *w, size_t n) { if (a == 0x7f7f7f7f7f7f7f7f) continue; uint64_t b = 0x8080808080808080; uint64_t c = 0x7f7f7f7f7f7f7f7f ^ a; - uint64_t d = ((c >> 1 | b) - c & b ^ b) >> 7; + uint64_t d = ((((c >> 1 | b) - c) & b) ^ b) >> 7; atomic_fetch_add_explicit(w + i, d, memory_order_relaxed); } } diff --git a/net/https/formatx509name.c b/net/https/formatx509name.c index b5084d8da..d7a39fcf4 100644 --- a/net/https/formatx509name.c +++ b/net/https/formatx509name.c @@ -19,7 +19,7 @@ #include "libc/log/check.h" #include "net/https/https.h" -char *FormatX509Name(mbedtls_x509_name *name) { +char *FormatX509Name(const mbedtls_x509_name *name) { char *s = calloc(1, 1000); CHECK_GT(mbedtls_x509_dn_gets(s, 1000, name), 0); return s; diff --git a/net/https/https.h b/net/https/https.h index f83229875..d05be2dc4 100644 --- a/net/https/https.h +++ b/net/https/https.h @@ -24,7 +24,7 @@ void FormatSslTime(char[restrict hasatleast 16], struct tm *); void ChooseCertificateLifetime(char[16], char[16]); void LogCertificate(const char *, mbedtls_x509_crt *); bool IsSelfSigned(mbedtls_x509_crt *); -char *FormatX509Name(mbedtls_x509_name *); +char *FormatX509Name(const mbedtls_x509_name *); void TlsDie(const char *, int) wontreturn; bool ChainCertificate(mbedtls_x509_crt *, mbedtls_x509_crt *); bool CertHasIp(const mbedtls_x509_crt *, uint32_t); diff --git a/net/https/initializekey.c b/net/https/initializekey.c index 22cbdcb45..de7626d0e 100644 --- a/net/https/initializekey.c +++ b/net/https/initializekey.c @@ -22,9 +22,7 @@ mbedtls_pk_context *InitializeKey(struct Cert *ca, mbedtls_x509write_cert *wcert, mbedtls_md_type_t md_alg, int type) { - mbedtls_pk_context *k; - mbedtls_ctr_drbg_context kr; - k = calloc(1, sizeof(mbedtls_pk_context)); + mbedtls_pk_context *k = calloc(1, sizeof(mbedtls_pk_context)); mbedtls_x509write_crt_init(wcert); mbedtls_x509write_crt_set_issuer_key(wcert, ca ? ca->key : k); mbedtls_x509write_crt_set_subject_key(wcert, k); diff --git a/net/https/initializerng.c b/net/https/initializerng.c index c37d002d6..cca528849 100644 --- a/net/https/initializerng.c +++ b/net/https/initializerng.c @@ -22,7 +22,7 @@ #include "third_party/mbedtls/ctr_drbg.h" void InitializeRng(mbedtls_ctr_drbg_context *r) { - volatile unsigned char b[64]; + unsigned char b[64]; mbedtls_ctr_drbg_init(r); CHECK(getrandom(b, 64, 0) == 64); CHECK(!mbedtls_ctr_drbg_seed(r, GetEntropy, 0, b, 64)); diff --git a/net/https/sslcache.c b/net/https/sslcache.c index 68854bfc0..c4ddd0862 100644 --- a/net/https/sslcache.c +++ b/net/https/sslcache.c @@ -40,7 +40,7 @@ #define PROT (PROT_READ | PROT_WRITE) #define FLAGS MAP_SHARED -static uint32_t HashSslSession(mbedtls_ssl_session *session) { +static uint32_t HashSslSession(const mbedtls_ssl_session *session) { int i; uint32_t h; h = session->ciphersuite; diff --git a/net/turfwar/blackholed.c b/net/turfwar/blackholed.c index d4ede885e..dec36f33c 100644 --- a/net/turfwar/blackholed.c +++ b/net/turfwar/blackholed.c @@ -214,7 +214,7 @@ void GetOpts(int argc, char *argv[]) { } void OnTerm(int sig) { - char tmp[15]; + char tmp[21]; LOG("got %s", strsignal_r(sig, tmp)); g_shutdown = sig; } @@ -231,12 +231,12 @@ void BlockIp(uint32_t ip) { if (g_iptables) { execve(g_iptables, (char *const[]){ - "iptables", // - "-t", "raw", // - "-I", g_chain, // - "-s", FormatIp(ip), // - "-j", "DROP", // - 0, // + "iptables", // + "-t", "raw", // + "-I", (char *)g_chain, // + "-s", FormatIp(ip), // + "-j", "DROP", // + 0, // }, (char *const[]){0}); } else if (g_pfctl) { diff --git a/net/turfwar/turfwar.c b/net/turfwar/turfwar.c index e81038e15..15b551e53 100644 --- a/net/turfwar/turfwar.c +++ b/net/turfwar/turfwar.c @@ -629,7 +629,7 @@ int GetClaims(struct Claims *q, struct Claim *out, int len) { // parses request uri query string and extracts ?name=value static bool GetNick(char *inbuf, struct HttpMessage *msg, struct Claim *v) { - size_t i, n; + size_t i; struct Url url; void *f[2] = {0}; bool found = false; @@ -826,7 +826,6 @@ void *HttpWorker(void *arg) { // connection loop while (GetClient(&g_clients, &client)) { struct Data d; - struct Url url; ssize_t got, sent; uint32_t ip, clientip; int tok, inmsglen, outmsglen; @@ -1890,7 +1889,6 @@ void *Supervisor(void *arg) { } void CheckDatabase(void) { - int rc; sqlite3 *db; if (g_integrity) { CHECK_SQL(DbOpen("db.sqlite3", &db)); diff --git a/test/dsp/core/alaw_test.c b/test/dsp/core/alaw_test.c index 6a681563f..6d19c8aa8 100644 --- a/test/dsp/core/alaw_test.c +++ b/test/dsp/core/alaw_test.c @@ -18,8 +18,8 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/core/core.h" #include "libc/macros.internal.h" -#include "libc/mem/mem.h" #include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" @@ -188,7 +188,6 @@ TEST(unalaw, test) { } BENCH(alaw, bench) { - char *p = gc(malloc(kHyperionSize)); EZBENCH2("alaw -32k", donothing, alaw(-32768)); EZBENCH2("alaw 32k", donothing, alaw(32767)); EZBENCH2("unalaw 0", donothing, unalaw(0)); diff --git a/test/dsp/scale/magikarp_test.c b/test/dsp/scale/magikarp_test.c index a29ba606d..2ce9f3d12 100644 --- a/test/dsp/scale/magikarp_test.c +++ b/test/dsp/scale/magikarp_test.c @@ -146,7 +146,6 @@ noooopppqqqqqqqqqqqqqqqppoooonn", #define HDY (1080 / 4) BENCH(magikarp, bench) { /* 30ms */ - unsigned char kMagkern[16] = {4, 12, 12, 4}; signed char kMagikarp[16] = {-1, -3, 3, 17, 17, 3, -3, -1}; unsigned char(*Me)[HDY][HDX] = gc(malloc((HDX + 1) * (HDY + 1))); unsigned char(*Mo)[HDY][HDX] = gc(malloc((HDX + 1) * (HDY + 1))); diff --git a/test/dsp/tty/windex_test.c b/test/dsp/tty/windex_test.c deleted file mode 100644 index 210dd6cce..000000000 --- a/test/dsp/tty/windex_test.c +++ /dev/null @@ -1,131 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "dsp/tty/windex.h" -#include "libc/assert.h" -#include "libc/intrin/bits.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/mem/gc.internal.h" -#include "libc/mem/mem.h" -#include "libc/nexgen32e/x86feature.h" -#include "libc/str/str.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -unsigned windex_k8(short *, size_t); -unsigned windex_avx2(short *, size_t); -unsigned windex_sse4(short *, size_t); - -const short kW[64] forcealign(32) = { - 8281, 3883, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, - 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, - 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33, - 1085, 7806, 3248, 1186, 1357, 6738, 1311, 1092, 6195, 7089, 6631, - 1261, 1364, 9007, 8289, 1409, 1090, 8358, 1502, 7658, 2668, 3522, - 1730, 2041, 7707, 5096, 6876, 1324, 1242, 5283, 0x7fff, -}; - -const short kW2[32] forcealign(32) = { - 8281, 1, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, - 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, - 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, -}; - -const short kW3[64] forcealign(32) = { - 8281, 0x7fff, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923, - 3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905, - 2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33, - 1085, 7806, 3248, 1186, 1357, 6738, 1311, 1092, 6195, 7089, 6631, - 1261, 1364, 9007, 8289, 1409, 1090, 8358, 1502, 7658, 2668, 3522, - 1730, 2041, 7707, 5096, 6876, 1324, 1242, 7, 0x7fff, -}; - -#define TestIt(impl, index, value, n, array) \ - ({ \ - short *a = memcpy(gc(memalign(32, n * 2)), array, n * 2); \ - unsigned res = impl(array, n); \ - ASSERT_EQ(index, res); \ - ASSERT_EQ(value, a[res]); \ - }) - -TEST(windex, testRealWorldPicks) { - const short kPicks[96] forcealign(32) = { - 103, 85, 145, 146, 121, 103, 145, 187, 146, 189, - 121, 103, 139, 121, 63, 105, 105, 147, 60, 103, - 103, 146, 121, 103, 139, 121, 139, 121, 157, 139, - 199, 200, 163, 223, 164, 225, 81, 141, 105, 165, - 78, 139, 103, 164, 61, 103, 103, 145, 79, 139, - 103, 163, 21, 63, 21, 81, 63, 45, 105, 106, - 106, 107, 102, 103, 103, 104, 64, 107, 107, 150, - 82, 143, 107, 168, 108, 109, 109, 110, 21, 64, - 21, 82, 105, 106, 64, 46, 106, 107, 0x7fff, 0x7fff, - 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, 0x7fff, - }; - /* multiple valid answers are fine if it's deterministic */ - TestIt(windex_k8, 52, 21, ARRAYLEN(kPicks), kPicks); - if (X86_HAVE(AVX2)) TestIt(windex_avx2, 78, 21, ARRAYLEN(kPicks), kPicks); - if (X86_HAVE(SSE4_2)) TestIt(windex_sse4, 80, 21, ARRAYLEN(kPicks), kPicks); -} - -TEST(windex, test) { - TestIt(windex, 13, 32, ARRAYLEN(kW), kW); - TestIt(windex, 1, 1, ARRAYLEN(kW2), kW2); - TestIt(windex, 62, 7, ARRAYLEN(kW3), kW3); -} - -TEST(windex_avx2, test) { - if (X86_HAVE(AVX2)) { - TestIt(windex_avx2, 13, 32, ARRAYLEN(kW), kW); - TestIt(windex_avx2, 1, 1, ARRAYLEN(kW2), kW2); - TestIt(windex_avx2, 62, 7, ARRAYLEN(kW3), kW3); - } -} - -TEST(windex_sse4, test) { - if (X86_HAVE(SSE4_2)) { - TestIt(windex_sse4, 13, 32, ARRAYLEN(kW), kW); - TestIt(windex_sse4, 1, 1, ARRAYLEN(kW2), kW2); - TestIt(windex_sse4, 62, 7, ARRAYLEN(kW3), kW3); - } -} - -TEST(windex_k8, test) { - TestIt(windex_k8, 13, 32, ARRAYLEN(kW), kW); - TestIt(windex_k8, 1, 1, ARRAYLEN(kW2), kW2); - TestIt(windex_k8, 62, 7, ARRAYLEN(kW3), kW3); -} - -//////////////////////////////////////////////////////////////////////////////// - -BENCH(windex, bench) { - EZBENCH(donothing, windex(kW, ARRAYLEN(kW))); -} -BENCH(windex_k8, bench) { - EZBENCH(donothing, windex_k8(kW, ARRAYLEN(kW))); -} -BENCH(windex_avx2, bench) { - if (X86_HAVE(AVX2)) { - EZBENCH(donothing, windex_avx2(kW, ARRAYLEN(kW))); - } -} -BENCH(windex_sse4, bench) { - if (X86_HAVE(SSE4_2)) { - EZBENCH(donothing, windex_sse4(kW, ARRAYLEN(kW))); - } -} diff --git a/test/libc/calls/access_test.c b/test/libc/calls/access_test.c index 86fc4038f..09ef0a405 100644 --- a/test/libc/calls/access_test.c +++ b/test/libc/calls/access_test.c @@ -63,7 +63,6 @@ TEST(access, test) { TEST(access, testRequestWriteOnReadOnly_returnsEaccess) { return; /* TODO(jart): maybe we need root to help? */ - int fd; 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/clock_gettime_test.c b/test/libc/calls/clock_gettime_test.c index 3c9c74b4c..1fe94ed7a 100644 --- a/test/libc/calls/clock_gettime_test.c +++ b/test/libc/calls/clock_gettime_test.c @@ -37,12 +37,12 @@ TEST(clock_gettime, fault) { } TEST(clock_gettime, test) { - bool isfast; struct timespec ts = {0}; ASSERT_EQ(0, clock_gettime(0, &ts)); ASSERT_NE(0, ts.tv_sec); ASSERT_NE(0, ts.tv_nsec); #ifndef __aarch64__ + bool isfast; // we support vdso on aarch64 but qemu-aarch64 won't let us test it if (__is_linux_2_6_23()) { ASSERT_GT((intptr_t)__clock_gettime_get(&isfast), diff --git a/test/libc/calls/commandv_test.c b/test/libc/calls/commandv_test.c index 3c55dc331..545ba1b46 100644 --- a/test/libc/calls/commandv_test.c +++ b/test/libc/calls/commandv_test.c @@ -45,7 +45,6 @@ void SetUpOnce(void) { } void SetUp(void) { - static int x; mkdir("bin", 0755); mkdir("home", 0755); oldpath = strdup(nulltoempty(getenv("PATH"))); diff --git a/test/libc/calls/execve_test.c b/test/libc/calls/execve_test.c index f6eaa6709..24f4b4e34 100644 --- a/test/libc/calls/execve_test.c +++ b/test/libc/calls/execve_test.c @@ -111,7 +111,7 @@ TEST(execve, ziposAPE) { void ExecvTinyElf(const char *path) { int ws; if (!vfork()) { - execv(path, (char *[]){path, 0}); + execv(path, (char *[]){(char *)path, 0}); abort(); } ASSERT_NE(-1, wait(&ws)); @@ -121,7 +121,7 @@ void ExecvTinyElf(const char *path) { void ExecvpTinyElf(const char *path) { int ws; if (!vfork()) { - execvp(path, (char *[]){path, 0}); + execvp(path, (char *[]){(char *)path, 0}); abort(); } ASSERT_NE(-1, wait(&ws)); @@ -131,7 +131,7 @@ void ExecvpTinyElf(const char *path) { void ExecveTinyElf(const char *path) { int ws; if (!vfork()) { - execve(path, (char *[]){path, 0}, (char *[]){0}); + execve(path, (char *[]){(char *)path, 0}, (char *[]){0}); abort(); } ASSERT_NE(-1, wait(&ws)); diff --git a/test/libc/calls/ioctl_test.c b/test/libc/calls/ioctl_test.c index 2707246ca..1b4cfe4ca 100644 --- a/test/libc/calls/ioctl_test.c +++ b/test/libc/calls/ioctl_test.c @@ -42,7 +42,6 @@ TEST(siocgifconf, test) { int socketfd; struct ifreq *ifr; struct ifconf conf; - char addrbuf[1024]; uint32_t ip, netmask; bool foundloopback = false; data = gc(malloc((n = 4096))); diff --git a/test/libc/calls/lock2_test.c b/test/libc/calls/lock2_test.c index a472513d3..ae883eb65 100644 --- a/test/libc/calls/lock2_test.c +++ b/test/libc/calls/lock2_test.c @@ -31,7 +31,6 @@ char testlib_enable_tmp_setup_teardown; TEST(lock, wholeFile) { - char buf[512]; ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644)); ASSERT_SYS(0, 0, fcntl(3, F_SETLK, &(struct flock){.l_type = F_RDLCK})); ASSERT_SYS(0, 0, fcntl(3, F_SETLK, &(struct flock){.l_type = F_UNLCK})); @@ -39,7 +38,6 @@ TEST(lock, wholeFile) { } TEST(lock, testUpgradeFromReadToWriteLock) { - char buf[512]; ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644)); ASSERT_SYS(0, 0, fcntl(3, F_SETLK, @@ -59,7 +57,6 @@ TEST(lock, testUpgradeFromReadToWriteLock) { } TEST(lock, testUpgradeWriteToWriteLock) { - char buf[512]; ASSERT_SYS(0, 3, open("db", O_RDWR | O_CREAT | O_EXCL, 0644)); ASSERT_SYS(0, 0, fcntl(3, F_SETLK, diff --git a/test/libc/calls/mkdir_test.c b/test/libc/calls/mkdir_test.c index 8ab1bd86f..c3427349a 100644 --- a/test/libc/calls/mkdir_test.c +++ b/test/libc/calls/mkdir_test.c @@ -72,7 +72,7 @@ TEST(makedirs, pathExists_isSuccess) { TEST(mkdir, enametoolong) { int i; size_t n = 2048; - char *d, *s = gc(calloc(1, n)); + char *s = gc(calloc(1, n)); for (i = 0; i < n - 1; ++i) s[i] = 'x'; s[i] = 0; EXPECT_SYS(ENAMETOOLONG, -1, mkdir(s, 0644)); diff --git a/test/libc/calls/pledge_test.c b/test/libc/calls/pledge_test.c index 6c0a71ae0..9a18f0dc4 100644 --- a/test/libc/calls/pledge_test.c +++ b/test/libc/calls/pledge_test.c @@ -365,7 +365,7 @@ TEST(pledge, inet_forbidsOtherSockets) { TEST(pledge, anet_forbidsUdpSocketsAndConnect) { if (IsOpenbsd()) return; // b/c testing linux bpf - int ws, pid, yes = 1; + int ws, pid; ASSERT_NE(-1, (pid = fork())); if (!pid) { ASSERT_SYS(0, 0, pledge("stdio anet", 0)); @@ -612,7 +612,7 @@ int LockWorker(void *arg, int tid) { TEST(pledge, threadWithLocks_canCodeMorph) { struct spawn worker; - int ws, pid; + int ws; // not sure how this works on OpenBSD but it works! if (!fork()) { __enable_threads(); @@ -627,7 +627,7 @@ TEST(pledge, threadWithLocks_canCodeMorph) { } TEST(pledge, everything) { - int ws, pid; + int ws; if (!fork()) { // contains 591 bpf instructions [2022-07-24] ASSERT_SYS(0, 0, @@ -668,7 +668,6 @@ TEST(pledge, execWithoutRpath) { } BENCH(pledge, bench) { - int pid; if (!fork()) { ASSERT_SYS(0, 0, pledge("stdio", 0)); EZBENCH2("sched_yield", donothing, sched_yield()); diff --git a/test/libc/calls/poll_test.c b/test/libc/calls/poll_test.c index 82260f133..07e4a0096 100644 --- a/test/libc/calls/poll_test.c +++ b/test/libc/calls/poll_test.c @@ -131,6 +131,7 @@ TEST(poll, pipe_hasInput) { char buf[2]; sigset_t chldmask, savemask; int ws, pid, sync[2], pipefds[2]; + (void)sync; EXPECT_EQ(0, sigemptyset(&chldmask)); EXPECT_EQ(0, sigaddset(&chldmask, SIGCHLD)); EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &chldmask, &savemask)); diff --git a/test/libc/calls/raise_race_test.c b/test/libc/calls/raise_race_test.c index 57a04836f..a1c178231 100644 --- a/test/libc/calls/raise_race_test.c +++ b/test/libc/calls/raise_race_test.c @@ -99,7 +99,7 @@ TEST(raise, test) { if (IsXnu()) return; // no support for realtime signals yet if (IsWindows()) return; // TODO(jart): why does it exit 128+SIGRTMIN? void *p; - int r, i, s; + int r, i; pthread_t t; if (signal(SIGRTMIN, handler0) == SIG_ERR) t_error("registering signal handler failed: %s\n", strerror(errno)); diff --git a/test/libc/calls/readlinkat_test.c b/test/libc/calls/readlinkat_test.c index 9589025e9..b213efe7a 100644 --- a/test/libc/calls/readlinkat_test.c +++ b/test/libc/calls/readlinkat_test.c @@ -50,7 +50,7 @@ TEST(readlink, enotdir) { } TEST(readlinkat, test) { - char buf[128], *p, *q; + char buf[128]; memset(buf, -1, sizeof(buf)); ASSERT_NE(-1, xbarf("hello→", "hi", -1)); ASSERT_STREQ("hi", gc(xslurp("hello→", 0))); @@ -103,7 +103,6 @@ TEST(readlinkat, statReadsNameLength) { } TEST(readlinkat, realpathReturnsLongPath) { - struct stat st; char buf[PATH_MAX]; if (!IsWindows()) return; if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return; diff --git a/test/libc/calls/reservefd_test.c b/test/libc/calls/reservefd_test.c index 7218e725a..ea06866c5 100644 --- a/test/libc/calls/reservefd_test.c +++ b/test/libc/calls/reservefd_test.c @@ -120,19 +120,3 @@ int Worker(void *p, int tid) { } return 0; } - -TEST(reservefd, tortureTest) { - int i; - struct spawn th[THREADS]; - struct sigaction oldsa; - struct itimerval oldit; - struct itimerval it = {{0, 10000}, {0, 100}}; - struct sigaction sa = {.sa_sigaction = OnSigAlrm, - .sa_flags = 0 /* SA_NODEFER */}; - // ASSERT_SYS(0, 0, sigaction(SIGALRM, &sa, &oldsa)); - // ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &it, &oldit)); - for (i = 0; i < THREADS; ++i) _spawn(Worker, 0, th + i); - for (i = 0; i < THREADS; ++i) _join(th + i); - // EXPECT_SYS(0, 0, sigaction(SIGALRM, &oldsa, 0)); - // EXPECT_SYS(0, 0, setitimer(ITIMER_REAL, &oldit, 0)); -} diff --git a/test/libc/calls/sched_getaffinity_test.c b/test/libc/calls/sched_getaffinity_test.c index 6a6112ad0..1c20849ea 100644 --- a/test/libc/calls/sched_getaffinity_test.c +++ b/test/libc/calls/sched_getaffinity_test.c @@ -91,11 +91,11 @@ __attribute__((__constructor__)) static void init(void) { #ifdef __x86_64__ TEST(sched_setaffinity, isInheritedAcrossExecve) { - cpu_set_t x, y; + cpu_set_t x; CPU_ZERO(&x); CPU_SET(0, &x); ASSERT_SYS(0, 0, sched_setaffinity(0, sizeof(x), &x)); - int rc, ws, pid; + int ws, pid; char *prog = GetProgramExecutableName(); char *args[] = {program_invocation_name, NULL}; char *envs[] = {"THE_DOGE=42", NULL}; diff --git a/test/libc/calls/setrlimit_test.c b/test/libc/calls/setrlimit_test.c index f135ed884..80b5a287c 100644 --- a/test/libc/calls/setrlimit_test.c +++ b/test/libc/calls/setrlimit_test.c @@ -55,8 +55,7 @@ void OnSigxfsz(int sig) { } TEST(setrlimit, testCpuLimit) { - char *p; - int i, wstatus; + int wstatus; long double start; struct rlimit rlim; double matrices[3][3][3]; @@ -84,7 +83,6 @@ TEST(setrlimit, testCpuLimit) { } TEST(setrlimit, testFileSizeLimit) { - char *p; char junkdata[512]; int i, fd, wstatus; struct rlimit rlim; @@ -129,7 +127,7 @@ TEST(setrlimit, testMemoryLimit) { ASSERT_NE(-1, (wstatus = xspawn(0))); if (wstatus == -2) { ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM)); - for (gotsome = i = 0; i < (MEM * 2) / getauxval(AT_PAGESZ); ++i) { + for (gotsome = false, i = 0; i < (MEM * 2) / getauxval(AT_PAGESZ); ++i) { p = mmap(0, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0); if (p != MAP_FAILED) { @@ -228,7 +226,7 @@ wontreturn void OnVfork(void *ctx) { } TEST(setrlimit, isVforkSafe) { - int pid, ws; + int ws; struct rlimit rlim[2]; if (IsWindows()) return; /* of course it doesn't work on windows */ ASSERT_EQ(0, getrlimit(RLIMIT_CPU, rlim)); diff --git a/test/libc/calls/sigprocmask_test.c b/test/libc/calls/sigprocmask_test.c index aff4a62f0..94ea33eca 100644 --- a/test/libc/calls/sigprocmask_test.c +++ b/test/libc/calls/sigprocmask_test.c @@ -37,7 +37,6 @@ void OnSig(int sig, siginfo_t *si, void *ctx) { } TEST(sigprocmask, testMultipleBlockedDeliveries) { - int pid, ws; sigset_t neu, old; struct sigaction oldusr1, oldusr2; struct sigaction sa = {.sa_sigaction = OnSig, .sa_flags = SA_SIGINFO}; @@ -58,7 +57,6 @@ TEST(sigprocmask, testMultipleBlockedDeliveries) { } TEST(sigprocmask, testMultipleBlockedDeliveriesOfSameSignal) { - int pid, ws; sigset_t neu, old; struct sigaction oldusr2; struct sigaction sa = {.sa_sigaction = OnSig, .sa_flags = SA_SIGINFO}; diff --git a/test/libc/calls/timespec_test.c b/test/libc/calls/timespec_test.c index e9564226a..256ac0397 100644 --- a/test/libc/calls/timespec_test.c +++ b/test/libc/calls/timespec_test.c @@ -102,7 +102,6 @@ TEST(timespec_sub, math) { for (int i = 0; i < 1000; ++i) { struct timespec x = {mod(lemur64(), 10), mod(lemur64(), 10)}; struct timespec y = {mod(lemur64(), 10), mod(lemur64(), 10)}; - struct timespec z = timespec_add(timespec_sub(x, y), y); EXPECT_TRUE(!timespec_cmp(x, timespec_add(timespec_sub(x, y), y))); } } diff --git a/test/libc/calls/tkill_test.c b/test/libc/calls/tkill_test.c index 58cd62781..44b1583f1 100644 --- a/test/libc/calls/tkill_test.c +++ b/test/libc/calls/tkill_test.c @@ -40,8 +40,8 @@ void *Worker(void *arg) { TEST(tkill, test) { if (IsWindows()) return; // TODO(jart): fix me + int tid; void *res; - int i, tid; pthread_t t; sigset_t ss, oldss; sighandler_t oldsig; diff --git a/test/libc/dns/parsehoststxt_test.c b/test/libc/dns/parsehoststxt_test.c index 5ea5a164f..358dc62ac 100644 --- a/test/libc/dns/parsehoststxt_test.c +++ b/test/libc/dns/parsehoststxt_test.c @@ -69,7 +69,7 @@ TEST(ParseHostsTxt, testIpv6_isIgnored) { const char kInput[] = "::1 boop\n" "203.0.113.2 cat # ignore me\n"; struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt)); - FILE *f = fmemopen(kInput, strlen(kInput), "r+"); + FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+"); ASSERT_EQ(0, ParseHostsTxt(ht, f)); ASSERT_EQ(1, ht->entries.i); EXPECT_STREQ("cat", &ht->strings.p[ht->entries.p[0].name]); diff --git a/test/libc/dns/parseresolvconf_test.c b/test/libc/dns/parseresolvconf_test.c index b47333601..fe86ae46f 100644 --- a/test/libc/dns/parseresolvconf_test.c +++ b/test/libc/dns/parseresolvconf_test.c @@ -45,7 +45,7 @@ TEST(ParseResolvConf, testCorrectlyTokenizes) { "nameserver 203.0.113.2 \n" " nameserver 203.0.113.1\n"; struct ResolvConf *rv = calloc(1, sizeof(struct ResolvConf)); - FILE *f = fmemopen(kInput, strlen(kInput), "r+"); + FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+"); ASSERT_EQ(2, ParseResolvConf(rv, f)); ASSERT_EQ(2, rv->nameservers.i); EXPECT_EQ(AF_INET, rv->nameservers.p[0].sin_family); diff --git a/test/libc/dns/resolvehoststxt_test.c b/test/libc/dns/resolvehoststxt_test.c index 8bff7bd33..1c9e68838 100644 --- a/test/libc/dns/resolvehoststxt_test.c +++ b/test/libc/dns/resolvehoststxt_test.c @@ -47,7 +47,7 @@ static const char kInput[] = "127.0.0.1 localhost\n" TEST(ResolveHostsTxt, testBasicLookups) { struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt)); - FILE *f = fmemopen(kInput, strlen(kInput), "r+"); + FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+"); ASSERT_EQ(0, ParseHostsTxt(ht, f)); ASSERT_EQ(5, ht->entries.i); EXPECT_STREQ("127.0.0.1", EzIp4Lookup(ht, "localhost")); @@ -63,7 +63,7 @@ TEST(ResolveHostsTxt, testBasicLookups) { TEST(ResolveHostsTxt, testCanonicalize) { struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt)); - FILE *f = fmemopen(kInput, strlen(kInput), "r+"); + FILE *f = fmemopen((void *)kInput, strlen(kInput), "r+"); ASSERT_EQ(0, ParseHostsTxt(ht, f)); ASSERT_EQ(5, ht->entries.i); EXPECT_STREQ("localhost", EzCanonicalize(ht, "localhost")); diff --git a/test/libc/fmt/formathex64_test.c b/test/libc/fmt/formathex64_test.c index d03236170..9240de080 100644 --- a/test/libc/fmt/formathex64_test.c +++ b/test/libc/fmt/formathex64_test.c @@ -22,7 +22,7 @@ #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" -char buf[19]; +char buf[100]; void SetUp(void) { memset(buf, 0x55, sizeof(buf)); diff --git a/test/libc/intrin/kprintf_test.c b/test/libc/intrin/kprintf_test.c index 0a2197067..59f44e3f7 100644 --- a/test/libc/intrin/kprintf_test.c +++ b/test/libc/intrin/kprintf_test.c @@ -222,12 +222,11 @@ TEST(ksnprintf, testSymbols) { } TEST(ksnprintf, fuzzTheUnbreakable) { - int e; size_t i; uint64_t x; char *f, b[32]; _Alignas(FRAMESIZE) static const char weasel[FRAMESIZE]; - f = __veil("r", weasel); + f = (void *)__veil("r", weasel); EXPECT_SYS(0, 0, mprotect(f, FRAMESIZE, PROT_READ | PROT_WRITE)); strcpy(f, "hello %s\n"); EXPECT_EQ(12, ksnprintf(b, sizeof(b), f, "world")); @@ -245,7 +244,6 @@ TEST(ksnprintf, fuzzTheUnbreakable) { TEST(kprintf, testFailure_wontClobberErrnoAndBypassesSystemCallSupport) { int n; - const char *s = 0; ASSERT_EQ(0, errno); EXPECT_SYS(0, 3, dup(2)); // diff --git a/test/libc/intrin/memmove_test.c b/test/libc/intrin/memmove_test.c index ddaffb2c5..b950d6d7b 100644 --- a/test/libc/intrin/memmove_test.c +++ b/test/libc/intrin/memmove_test.c @@ -43,7 +43,7 @@ static void *golden(void *a, const void *b, size_t n) { } TEST(memmove, hug) { - char *a, *b, *c; + char *a, *b; int i, o1, o2; int N[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31, 32, 33, 63, 64, 65, 80, 81, 1000, 1024, 1025}; @@ -63,7 +63,7 @@ TEST(memmove, hug) { } TEST(memmove, bighug) { - char *a, *b, *c; + char *a, *b; int i, o1, o2; int N[] = {5 * 1024 * 1024}; a = gc(malloc(6291456)); @@ -82,19 +82,18 @@ TEST(memmove, bighug) { } BENCH(memmove, bench) { - volatile char *r; int n, max = 128 * 1024 * 1024; char *volatile p = gc(calloc(max, 1)); char *volatile q = gc(calloc(max, 1)); EZBENCH_N("memmove", 0, memmove(p, q, 0)); for (n = 0; n < 127; ++n) { - EZBENCH_N("memmove", n, r = memmove(p, q, n)); + EZBENCH_N("memmove", n, memmove(p, q, n)); } for (n = 128; n <= max; n *= 2) { - EZBENCH_N("memmove", n - 1, r = memmove(p, q, n - 1)); - EZBENCH_N("memmove", n, r = memmove(p, q, n)); + EZBENCH_N("memmove", n - 1, memmove(p, q, n - 1)); + EZBENCH_N("memmove", n, memmove(p, q, n)); } for (n = 500; n <= 1000; n += 100) { - EZBENCH_N("memmove", n, r = memmove(p, q, n)); + EZBENCH_N("memmove", n, memmove(p, q, n)); } } diff --git a/test/libc/intrin/memset_test.c b/test/libc/intrin/memset_test.c index 16fe462e5..e128ae53a 100644 --- a/test/libc/intrin/memset_test.c +++ b/test/libc/intrin/memset_test.c @@ -88,14 +88,13 @@ BENCH(memset, bench) { } BENCH(strlen, bench) { - volatile size_t r; int n, max = 8 * 1024 * 1024; char *volatile p = gc(calloc(max + 1, 1)); EZBENCH_N("strlen", 0, strlen(p)); for (n = 2; n <= max; n *= 2) { memset(p, -1, n - 1); - EZBENCH_N("strlen", n - 1, r = strlen(p)); + EZBENCH_N("strlen", n - 1, strlen(p)); p[n - 1] = -1; - EZBENCH_N("strlen", n, r = strlen(p)); + EZBENCH_N("strlen", n, strlen(p)); } } diff --git a/test/libc/intrin/pthread_atfork_test.c b/test/libc/intrin/pthread_atfork_test.c index 4fd22c198..1d363e036 100644 --- a/test/libc/intrin/pthread_atfork_test.c +++ b/test/libc/intrin/pthread_atfork_test.c @@ -44,7 +44,6 @@ void *ForceThreadingMode(void *arg) { } TEST(pthread_atfork, test) { - int pid; __enable_threads(); SPAWN(fork); ASSERT_EQ(0, pthread_atfork(prepare1, parent1, child1)); diff --git a/test/libc/intrin/pthread_mutex_lock_test.c b/test/libc/intrin/pthread_mutex_lock_test.c index 5ce92d1b7..5402c9ab2 100644 --- a/test/libc/intrin/pthread_mutex_lock_test.c +++ b/test/libc/intrin/pthread_mutex_lock_test.c @@ -57,14 +57,6 @@ void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio rpath", 0)); } -TEST(pthread_mutex_lock, initializer) { - struct sqlite3_mutex { - pthread_mutex_t mutex; - } mu[] = {{ - PTHREAD_MUTEX_INITIALIZER, - }}; -} - TEST(pthread_mutex_lock, normal) { pthread_mutex_t lock; pthread_mutexattr_t attr; diff --git a/test/libc/intrin/rand64_test.c b/test/libc/intrin/rand64_test.c index ed0ca88cf..05c570599 100644 --- a/test/libc/intrin/rand64_test.c +++ b/test/libc/intrin/rand64_test.c @@ -58,7 +58,7 @@ int Thrasher(void *arg, int tid) { TEST(_rand64, testLcg_doesntProduceIdenticalValues) { int i, j; - bzero(A, sizeof(A)); + bzero((void *)A, sizeof(A)); for (i = 0; i < ARRAYLEN(A); ++i) { A[i] = _rand64(); } @@ -72,13 +72,13 @@ TEST(_rand64, testLcg_doesntProduceIdenticalValues) { } TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) { - int i, j, rc, ws; + int i, j; sigset_t ss, oldss; struct sigaction oldsa; struct spawn th[THREADS]; struct sigaction sa = {.sa_handler = OnChld, .sa_flags = SA_RESTART}; EXPECT_NE(-1, sigaction(SIGCHLD, &sa, &oldsa)); - bzero(A, sizeof(A)); + bzero((void *)A, sizeof(A)); sigemptyset(&ss); sigaddset(&ss, SIGCHLD); EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &ss, &oldss)); diff --git a/test/libc/intrin/strchr_test.c b/test/libc/intrin/strchr_test.c index 98d1e4cba..fb0bb3e02 100644 --- a/test/libc/intrin/strchr_test.c +++ b/test/libc/intrin/strchr_test.c @@ -72,7 +72,6 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) { } char *strchr_pure(const char *s, int c) { - char *r; for (c &= 0xff;; ++s) { if ((*s & 0xff) == c) return (char *)s; if (!*s) return NULL; @@ -108,7 +107,7 @@ 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 p; + if (*p == c) return (void *)p; } return NULL; } @@ -127,10 +126,9 @@ TEST(memchr, fuzz) { } char *strchrnul_pure(const char *s, int c) { - char *r; for (c &= 0xff;; ++s) { if ((*s & 0xff) == c) return (char *)s; - if (!*s) return s; + if (!*s) return (void *)s; } } @@ -150,7 +148,7 @@ 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 s; + if (*s == c) return (void *)s; } } diff --git a/test/libc/intrin/strcmp_test.c b/test/libc/intrin/strcmp_test.c index e54c9b4e0..037d4d36a 100644 --- a/test/libc/intrin/strcmp_test.c +++ b/test/libc/intrin/strcmp_test.c @@ -602,10 +602,10 @@ BENCH(bench_01_strcasecmp, bench) { BENCH(memcmp, bench) { volatile char *copy = gc(strdup(kHyperion)); EZBENCH2("memcmp big", donothing, - __expropriate(memcmp(kHyperion, copy, kHyperionSize))); + __expropriate(memcmp(kHyperion, (void *)copy, kHyperionSize))); copy = gc(strdup("tough little ship")); EZBENCH2("memcmp 18", donothing, - __expropriate(memcmp("tough little ship", copy, 18))); + __expropriate(memcmp("tough little ship", (void *)copy, 18))); } /* jart diff --git a/test/libc/mem/malloc_test.c b/test/libc/mem/malloc_test.c index 50ffe6c5c..56ea2b7cd 100644 --- a/test/libc/mem/malloc_test.c +++ b/test/libc/mem/malloc_test.c @@ -99,7 +99,7 @@ TEST(realloc_in_place, test) { BENCH(realloc_in_place, bench) { volatile int i = 1000; - volatile char *x = malloc(i); + char *volatile x = malloc(i); EZBENCH2("malloc", donothing, free(malloc(i))); EZBENCH2("memalign", donothing, free(memalign(16, i))); EZBENCH2("memalign", donothing, free(memalign(32, i))); @@ -116,10 +116,11 @@ void AppendStuff(char **p, size_t *n) { } TEST(malloc, test) { + size_t n; char *big = 0; - size_t n, bigsize = 0; static struct stat st; - static volatile int i, j, k, *A[4096], fds[M], *maps[M], mapsizes[M]; + static int *A[4096], *maps[M]; + static int i, j, k, fds[M], mapsizes[M]; memset(fds, -1, sizeof(fds)); memset(maps, -1, sizeof(maps)); for (i = 0; i < N * M; ++i) { diff --git a/test/libc/mem/sortedints_test.c b/test/libc/mem/sortedints_test.c index f77f89543..898fe555e 100644 --- a/test/libc/mem/sortedints_test.c +++ b/test/libc/mem/sortedints_test.c @@ -107,6 +107,8 @@ TEST(sortedints, fuzz) { b = ContainsInt(&T, x); b = ContainsInt(&T, -x); y = CountInt(&T, x); + (void)b; + (void)y; } for (int i = 1; i < T.n; ++i) { ASSERT_GE(T.p[i], T.p[i - 1]); @@ -123,4 +125,5 @@ BENCH(sortedints, bench) { } EZBENCH2("insert big", donothing, InsertInt(&T, lemur64(), true)); EZBENCH2("contains big", donothing, ContainsInt(&T, lemur64())); + (void)x; } diff --git a/test/libc/nexgen32e/gclongjmp_test.c b/test/libc/nexgen32e/gclongjmp_test.c index 722b9eae7..eecc684f2 100644 --- a/test/libc/nexgen32e/gclongjmp_test.c +++ b/test/libc/nexgen32e/gclongjmp_test.c @@ -82,7 +82,6 @@ TEST(gclongjmp, test) { } void crawl(const char *path) { - const char *dir; if (!strcmp(path, "/") || !strcmp(path, ".")) return; crawl(_gc(xdirname(path))); } @@ -100,7 +99,6 @@ TEST(gc, torture) { } void crawl2(jmp_buf jb, const char *path) { - const char *dir; if (!strcmp(path, "/") || !strcmp(path, ".")) _gclongjmp(jb, 1); crawl2(jb, _gc(xdirname(path))); } diff --git a/test/libc/nexgen32e/memset_test.c b/test/libc/nexgen32e/memset_test.c index 60516bdf3..3774ba13a 100644 --- a/test/libc/nexgen32e/memset_test.c +++ b/test/libc/nexgen32e/memset_test.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" -#include "libc/mem/gc.internal.h" #include "libc/testlib/testlib.h" void *_memset(void *, int, size_t) asm("memset"); @@ -68,7 +68,7 @@ TEST(memset, size5) { } TEST(memset, wut) { - char buf[128], *p, *q; + char buf[128]; _memset(buf, -1, sizeof(buf)); EXPECT_EQ(255, buf[8] & 255); } diff --git a/test/libc/runtime/daemon_test.c b/test/libc/runtime/daemon_test.c index 3e5ccd4c8..9300ecb40 100644 --- a/test/libc/runtime/daemon_test.c +++ b/test/libc/runtime/daemon_test.c @@ -30,14 +30,13 @@ char testlib_enable_tmp_setup_teardown; TEST(daemon, test) { - int dirfd; char buf[512]; SPAWN(fork); ASSERT_SYS(0, 3, open(".", O_RDONLY | O_DIRECTORY)); ASSERT_SYS(0, 0, daemon(false, false)); ASSERT_SYS(0, 4, openat(3, "ok", O_WRONLY | O_CREAT | O_TRUNC, 0644)); ASSERT_NE(NULL, getcwd(buf, sizeof(buf))); - ASSERT_SYS(0, 0, write(4, buf, strlen(buf))); + ASSERT_SYS(0, 1, write(4, buf, strlen(buf))); ASSERT_SYS(0, 0, close(4)); ASSERT_SYS(0, 0, close(3)); EXITS(0); diff --git a/test/libc/runtime/fork_test.c b/test/libc/runtime/fork_test.c index ed7f6039f..674d9c64e 100644 --- a/test/libc/runtime/fork_test.c +++ b/test/libc/runtime/fork_test.c @@ -135,7 +135,6 @@ TEST(fork, childToChild) { } TEST(fork, preservesTlsMemory) { - int pid; __get_tls()->tib_errno = 31337; SPAWN(fork); ASSERT_EQ(31337, __get_tls()->tib_errno); diff --git a/test/libc/runtime/mmap_test.c b/test/libc/runtime/mmap_test.c index 494b35c70..230c711fd 100644 --- a/test/libc/runtime/mmap_test.c +++ b/test/libc/runtime/mmap_test.c @@ -354,8 +354,8 @@ TEST(mmap, cow) { TEST(mmap, cowFileMapReadonlyFork) { char *p; - int fd, pid, ws; - char path[PATH_MAX], lol[6]; + int fd, ws; + char path[PATH_MAX]; sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); EXPECT_EQ(6, write(fd, "hello", 6)); @@ -380,7 +380,7 @@ TEST(mmap, cowFileMapReadonlyFork) { TEST(mmap, cowFileMapFork) { char *p; - int fd, pid, ws; + int fd, ws; char path[PATH_MAX], lol[6]; sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); @@ -409,8 +409,8 @@ TEST(mmap, cowFileMapFork) { // SHARED ANONYMOUS MEMORY BETWEEN PROCESSES TEST(mmap, sharedAnonMapFork) { + int ws; char *p; - int pid, ws; EXPECT_NE(MAP_FAILED, (p = mmap(NULL, 6, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0))); strcpy(p, "parnt"); @@ -432,7 +432,7 @@ TEST(mmap, sharedAnonMapFork) { TEST(mmap, sharedFileMapFork) { char *p; - int fd, pid, ws; + int fd, ws; char path[PATH_MAX], lol[6]; sprintf(path, "%s.%ld", program_invocation_short_name, lemur64()); ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644))); diff --git a/test/libc/runtime/mprotect_test.c b/test/libc/runtime/mprotect_test.c index 3d824e842..4b8dd12d0 100644 --- a/test/libc/runtime/mprotect_test.c +++ b/test/libc/runtime/mprotect_test.c @@ -22,6 +22,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/describeflags.internal.h" #include "libc/log/log.h" #include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" @@ -85,7 +86,7 @@ void OnSigBus(int sig, struct siginfo *si, void *vctx) { kprintf("si->si_signo = %G%n", si->si_signo); kprintf("si->si_errno = %s (%d)%n", _strerrno(si->si_errno), si->si_errno); - kprintf("si->si_code = %s (%d)%n", GetSiCodeName(sig, si->si_code), + kprintf("si->si_code = %s (%d)%n", DescribeSiCode(sig, si->si_code), si->si_code); kprintf("┌si->si_addr = %p%n", si->si_addr); kprintf("┼─────────────────%n"); @@ -133,14 +134,15 @@ TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) { p[0] = 1; EXPECT_FALSE(gotsegv); EXPECT_FALSE(gotbusted); - EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ)); + EXPECT_NE(-1, mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ)); __expropriate(p[0]); EXPECT_FALSE(gotsegv); EXPECT_FALSE(gotbusted); p[0] = 2; EXPECT_TRUE(gotsegv | gotbusted); EXPECT_EQ(1, p[0]); - EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE)); + EXPECT_NE(-1, + mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE)); } TEST(mprotect, testExecOnly_canExecute) { @@ -161,10 +163,11 @@ TEST(mprotect, testExecOnly_canExecute) { TEST(mprotect, testProtNone_cantEvenRead) { volatile char *p; p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ))); - EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_NONE)); + EXPECT_NE(-1, mprotect((void *)p, getauxval(AT_PAGESZ), PROT_NONE)); __expropriate(p[0]); EXPECT_TRUE(gotsegv | gotbusted); - EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE)); + EXPECT_NE(-1, + mprotect((void *)p, getauxval(AT_PAGESZ), PROT_READ | PROT_WRITE)); } TEST(mprotect, testExecJit_actuallyWorks) { @@ -223,13 +226,13 @@ TEST(mprotect, testFileMap_canChangeToExecWhileOpenInRdwrMode) { TEST(mprotect, testBadProt_failsEinval) { volatile char *p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ))); - EXPECT_EQ(-1, mprotect(p, 9999, -1)); + EXPECT_EQ(-1, mprotect((void *)p, 9999, -1)); EXPECT_EQ(EINVAL, errno); } TEST(mprotect, testZeroSize_doesNothing) { volatile char *p = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ))); - EXPECT_NE(-1, mprotect(p, 0, PROT_READ)); + EXPECT_NE(-1, mprotect((void *)p, 0, PROT_READ)); p[0] = 1; EXPECT_FALSE(gotsegv); EXPECT_FALSE(gotbusted); diff --git a/test/libc/sock/nonblock_test.c b/test/libc/sock/nonblock_test.c index 193565436..76535d7b8 100644 --- a/test/libc/sock/nonblock_test.c +++ b/test/libc/sock/nonblock_test.c @@ -34,9 +34,7 @@ #include "libc/thread/thread.h" TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) { - int ws, pid; char buf[16] = {0}; - int64_t inoffset; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { .sin_family = AF_INET, @@ -81,9 +79,7 @@ TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) { } TEST(O_NONBLOCK, canBeTunedWithFcntl_toMakeReadNonBlocking) { - int ws, pid; char buf[16] = {0}; - int64_t inoffset; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { .sin_family = AF_INET, diff --git a/test/libc/sock/recvfrom_test.c b/test/libc/sock/recvfrom_test.c index 92e05f6b2..572a997e5 100644 --- a/test/libc/sock/recvfrom_test.c +++ b/test/libc/sock/recvfrom_test.c @@ -32,8 +32,6 @@ // two clients send a udp packet containing their local address // server verifies content of packet matches the peer's address TEST(recvfrom, test) { - int ws, pid; - int64_t inoffset; 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 f768891ab..672c95411 100644 --- a/test/libc/sock/sendfile_test.c +++ b/test/libc/sock/sendfile_test.c @@ -54,7 +54,6 @@ int64_t GetFileOffset(int fd) { TEST(sendfile, testSeeking) { char buf[1024]; - int rc, ws, fds[2]; int64_t inoffset = 0; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { @@ -94,6 +93,7 @@ TEST(sendfile, testSeeking) { ASSERT_SYS(0, 500, read(3, buf + 12, 700)); ASSERT_EQ(0, memcmp(buf, kHyperion, 512)); ASSERT_SYS(0, 0, close(3)); + int ws; ASSERT_NE(-1, wait(&ws)); ASSERT_TRUE(WIFEXITED(ws)); ASSERT_EQ(0, WEXITSTATUS(ws)); @@ -102,7 +102,6 @@ TEST(sendfile, testSeeking) { TEST(sendfile, testPositioning) { // TODO(jart): fix test regression on windows if (IsWindows()) return; - int ws, fds[2]; char buf[1024]; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { @@ -141,6 +140,7 @@ TEST(sendfile, testPositioning) { ASSERT_SYS(0, 0, read(3, buf, 12)); ASSERT_EQ(0, memcmp(buf, kHyperion, 12)); ASSERT_SYS(0, 0, close(3)); + int ws; ASSERT_NE(-1, wait(&ws)); ASSERT_TRUE(WIFEXITED(ws)); ASSERT_EQ(0, WEXITSTATUS(ws)); diff --git a/test/libc/sock/sendrecvmsg_test.c b/test/libc/sock/sendrecvmsg_test.c index 646efb769..68754dadc 100644 --- a/test/libc/sock/sendrecvmsg_test.c +++ b/test/libc/sock/sendrecvmsg_test.c @@ -44,9 +44,9 @@ TEST(sendrecvmsg, testPingPong) { memset(&msg, 0, sizeof(msg)); memset(&data[0], 0, sizeof(data)); - data[0].iov_base = hello; + data[0].iov_base = (void *)hello; data[0].iov_len = strlen(hello); - data[1].iov_base = world; + data[1].iov_base = (void *)world; data[1].iov_len = strlen(world); /* Don't send the '\0' */ msg.msg_iov = &data[0]; diff --git a/test/libc/sock/socket_test.c b/test/libc/sock/socket_test.c index cc84fa786..364d98968 100644 --- a/test/libc/sock/socket_test.c +++ b/test/libc/sock/socket_test.c @@ -34,9 +34,7 @@ #include "libc/testlib/testlib.h" TEST(ipv4, test) { - int ws, pid; char buf[16] = {0}; - int64_t inoffset; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { .sin_family = AF_INET, @@ -61,7 +59,6 @@ TEST(ipv4, test) { TEST(ipv6, test) { char buf[16] = {0}; - int64_t inoffset; uint32_t addrsize = sizeof(struct sockaddr_in6); struct sockaddr_in6 addr = { .sin6_family = AF_INET6, @@ -116,7 +113,6 @@ TEST(getsockname, copiesSafely_givesFullSize) { TEST(socket, canBeInheritedByForkedWorker) { char buf[16] = {0}; - int64_t inoffset; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { .sin_family = AF_INET, @@ -156,7 +152,6 @@ __attribute__((__constructor__)) static void StdioPro(int argc, char *argv[]) { TEST(socket, canBeUsedAsExecutedStdio) { char buf[16] = {0}; - int64_t inoffset; const char *prog; uint32_t addrsize = sizeof(struct sockaddr_in); struct sockaddr_in addr = { @@ -173,7 +168,7 @@ TEST(socket, canBeUsedAsExecutedStdio) { accept4(3, (struct sockaddr *)&addr, &addrsize, SOCK_CLOEXEC)); ASSERT_SYS(0, 1, dup2(4, 1)); SPAWN(vfork); - execve(prog, (char *[]){prog, "StdioProg", 0}, (char *[]){0}); + execve(prog, (char *[]){(void *)prog, "StdioProg", 0}, (char *[]){0}); abort(); PARENT(); ASSERT_SYS(0, 0, close(4)); diff --git a/test/libc/sock/unix_test.c b/test/libc/sock/unix_test.c index 232888744..f96d1906d 100644 --- a/test/libc/sock/unix_test.c +++ b/test/libc/sock/unix_test.c @@ -120,7 +120,6 @@ TEST(unix, stream) { TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine if (IsWindows()) return; if (IsCygwin()) return; - int ws, rc; char buf[8] = {0}; uint32_t len = sizeof(struct sockaddr_un); struct sockaddr_un addr = {AF_UNIX, "foo.sock"}; @@ -138,7 +137,7 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine ASSERT_SYS(0, 0, unlink(addr.sun_path)); ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_DGRAM, 0)); ASSERT_SYS(0, 0, bind(3, (void *)&addr, len)); - rc = write(4, "hello", 5); + int rc = write(4, "hello", 5); ASSERT_TRUE(rc == -1 && (errno == ECONNRESET || // errno == ENOTCONN || // errno == ECONNREFUSED || // @@ -156,7 +155,6 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier if (IsWindows()) return; if (IsCygwin()) return; - int ws, rc; 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/fgetln_test.c b/test/libc/stdio/fgetln_test.c index c31bd7127..b4a6cacbe 100644 --- a/test/libc/stdio/fgetln_test.c +++ b/test/libc/stdio/fgetln_test.c @@ -62,7 +62,6 @@ TEST(fgetln, testEvilLastLine) { } TEST(fgetln, testReadingFromStdin_doesntLeakMemory) { - FILE *f; int oldstdin, pfds[2]; oldstdin = dup(0); EXPECT_SYS(0, 0, pipe(pfds)); diff --git a/test/libc/stdio/getdelim_test.c b/test/libc/stdio/getdelim_test.c index 7b29c9069..c6461a193 100644 --- a/test/libc/stdio/getdelim_test.c +++ b/test/libc/stdio/getdelim_test.c @@ -56,7 +56,7 @@ TEST(getline, testOneWithoutLineFeed) { TEST(getline, testTwoLines) { const char *s = "hello\nthere\n"; - FILE *f = fmemopen(s, strlen(s), "r+"); + FILE *f = fmemopen((void *)s, strlen(s), "r+"); char *line = NULL; size_t linesize = 0; ASSERT_EQ(6, getline(&line, &linesize, f)); @@ -72,7 +72,7 @@ TEST(getline, testTwoLines) { TEST(getline, testBinaryLine_countExcludesOnlyTheBonusNul) { const char s[] = "he\0\3o\n"; - FILE *f = fmemopen(s, sizeof(s), "r+"); + FILE *f = fmemopen((void *)s, sizeof(s), "r+"); char *line = NULL; size_t linesize = 0; ASSERT_EQ(6, getline(&line, &linesize, f)); @@ -96,7 +96,6 @@ void ReadHyperionLines(void) { char *line = NULL; size_t linesize = 0; ASSERT_NE(NULL, (f = fopen("hyperion.txt", "r"))); - int i = 0; for (;;) { rc = getline(&line, &linesize, f); if (rc == -1) break; diff --git a/test/libc/stdio/getentropy_test.c b/test/libc/stdio/getentropy_test.c index 308cb79a9..ef43d3e6e 100644 --- a/test/libc/stdio/getentropy_test.c +++ b/test/libc/stdio/getentropy_test.c @@ -63,7 +63,7 @@ TEST(getentropy, test) { pthread_t child; double e, w = 7.7; struct sigaction sa; - int i, j, k, m, n = 999; + int i, k, m, n = 999; char *buf = _gc(calloc(1, n)); sa.sa_flags = 0; sa.sa_handler = OnSig; diff --git a/test/libc/stdio/getrandom_test.c b/test/libc/stdio/getrandom_test.c index 504ff7821..d6716f650 100644 --- a/test/libc/stdio/getrandom_test.c +++ b/test/libc/stdio/getrandom_test.c @@ -68,8 +68,8 @@ void *TortureWorker(void *arg) { } TEST(getrandom, test) { + int i, n = 999; double e, w = 7.7; - int i, j, n = 999; char *buf = _gc(calloc(1, n)); ASSERT_SYS(0, 0, getrandom(0, 0, 0)); ASSERT_SYS(0, n, getrandom(buf, n, 0)); @@ -91,7 +91,7 @@ TEST(getrandom, test2) { pthread_t child; double e, w = 7.7; struct sigaction sa; - int i, j, k, m, n = 999; + int i, k, m, n = 999; char *buf = _gc(calloc(1, n)); sa.sa_flags = 0; sa.sa_handler = OnSig; @@ -307,7 +307,7 @@ static const struct RandomFunction { TEST(getrandom, sanityTest) { uint64_t q; size_t i, j, k; - double montepi, chip, scc, mean, chisq, ent; + double montepi, scc, mean, chisq, ent; for (k = 0; k < 1; ++k) { for (j = 0; j < ARRAYLEN(kRandomFunctions); ++j) { rt_init(0); @@ -316,8 +316,8 @@ TEST(getrandom, sanityTest) { rt_add(&q, 8); } rt_end(&ent, &chisq, &mean, &montepi, &scc); - chip = pochisq(chisq, 255); #if 0 + double chip = pochisq(chisq, 255); fprintf(stderr, "\n"); fprintf(stderr, "/* %-32s */\n", kRandomFunctions[j].s); fprintf(stderr, "/* entropy: %-12g */\n", ent); diff --git a/test/libc/stdio/mt19937_test.c b/test/libc/stdio/mt19937_test.c index c0df389ce..6b5687ab4 100644 --- a/test/libc/stdio/mt19937_test.c +++ b/test/libc/stdio/mt19937_test.c @@ -47,7 +47,6 @@ int GetEntropy1(void *c, unsigned char *p, size_t n) { } void ctrdrbg1(void *p, size_t n) { - int rc; size_t i, m; mbedtls_ctr_drbg_context rng; mbedtls_ctr_drbg_init(&rng); @@ -65,7 +64,6 @@ int GetEntropy2(void *c, unsigned char *p, size_t n) { } void ctrdrbg2(void *p, size_t n) { - int rc; size_t i, m; mbedtls_ctr_drbg_context rng; mbedtls_ctr_drbg_init(&rng); @@ -153,63 +151,3 @@ TEST(mt19937, test) { ASSERT_EQ(want[i], _mt19937()); } } - -BENCH(mt19937, bench8) { - volatile uint64_t x; - EZBENCH2("lemur64", donothing, x = lemur64()); - EZBENCH2("_rand64", donothing, x = _rand64()); - EZBENCH2("vigna", donothing, x = vigna()); - EZBENCH2("vigna_r", donothing, vigna_r(&x)); - EZBENCH2("xorshift", donothing, x = xorshift()); - EZBENCH2("knuth", donothing, x = knuth()); - EZBENCH2("random", donothing, x = urandom()); - EZBENCH2("mt19937", donothing, x = _mt19937()); - EZBENCH2("rand64char", donothing, x = _rand64()); - size_t i = 0; - volatile uint8_t *p = gc(malloc(3 * 2048 * 2 * 8)); - EZBENCH3("rdrand", 2048, donothing, p[i++] = rdrand()); - EZBENCH3("rdseed", 2048, donothing, p[i++] = rdseed()); - EZBENCH3("getrandom", 2048, donothing, GetRandom(p + i++, 8)); -} - -BENCH(mt19937, bench32k) { - volatile char *p = gc(malloc(32768)); - EZBENCH_N("rngset(_rand64,-1)", 32768, rngset(p, 32768, _rand64, -1)); - EZBENCH_N("rngset(rdseed,512)", 32768, rngset(p, 32768, rdseed, 512)); - EZBENCH_N("ctrdrbg+rdseed [blk]", 32768, ctrdrbg1(p, 32768)); - EZBENCH_N("getrandom [block]", 32768, GetRandom(p, 32768)); - EZBENCH_N("vigna [word]", 32768, rngset(p, 32768, vigna, 0)); - EZBENCH_N("xorshift [word]", 32768, xorshifta(p, 32768)); - EZBENCH_N("knuth [word]", 32768, knutha(p, 32768)); - EZBENCH_N("random [word]", 32768, rngset(p, 32768, urandom, 0)); - EZBENCH_N("mt19937 [word]", 32768, rngset(p, 32768, _mt19937, 0)); - EZBENCH_N("_rand64 [word]", 32768, rngset(p, 32768, _rand64, 0)); - EZBENCH_N("rdrand [word]", 32768, rngset(p, 32768, rdrand, 0)); - EZBENCH_N("rdseed [word]", 32768, rngset(p, 32768, rdseed, 0)); -} - -BENCH(mt19937, bench48) { - volatile char *p = gc(malloc(48)); - EZBENCH_N("rngset(rdrand,0)", 48, rngset(p, 48, rdrand, 0)); - EZBENCH_N("rngset(rdseed,0)", 48, rngset(p, 48, rdseed, 0)); - EZBENCH_N("getrandom", 48, GetRandom(p, 48)); -} - -#if 0 -TEST(mt19937, test) { - int i; - uint64_t init[4] = {0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}; - uint64_t length = 4; - mt19937_init_by_array64(init, length); - printf("1000 outputs of genrand64_int64()\n"); - for (i = 0; i < 1000; i++) { - printf("%20llu ", mt19937_genrand64_int64()); - if (i % 5 == 4) printf("\n"); - } - printf("\n1000 outputs of genrand64_real2()\n"); - for (i = 0; i < 1000; i++) { - printf("%10.8f ", mt19937_genrand64_real2()); - if (i % 5 == 4) printf("\n"); - } -} -#endif diff --git a/test/libc/stdio/posix_spawn_test.c b/test/libc/stdio/posix_spawn_test.c index b8b4810ca..336d716bd 100644 --- a/test/libc/stdio/posix_spawn_test.c +++ b/test/libc/stdio/posix_spawn_test.c @@ -52,7 +52,7 @@ __attribute__((__constructor__)) static void init(void) { } TEST(posix_spawn, test) { - int rc, ws, pid; + int ws, pid; char *prog = GetProgramExecutableName(); char *args[] = {prog, NULL}; char *envs[] = {"THE_DOGE=42", NULL}; @@ -73,7 +73,8 @@ TEST(posix_spawn, pipe) { ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[0])); ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, p[1], 1)); ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, p[1])); - ASSERT_EQ(0, posix_spawnp(&pid, pn, &fa, 0, (char *[]){pn, "hello", 0}, 0)); + ASSERT_EQ( + 0, posix_spawnp(&pid, pn, &fa, 0, (char *[]){(void *)pn, "hello", 0}, 0)); ASSERT_SYS(0, 0, close(p[1])); ASSERT_SYS(0, pid, waitpid(pid, &status, 0)); ASSERT_SYS(0, 6, read(p[0], buf, sizeof(buf))); @@ -91,7 +92,6 @@ void OhMyGoth(int sig) { TEST(posix_spawn, torture) { int n = 10; int ws, pid; - short flags; sigset_t allsig; posix_spawnattr_t attr; posix_spawn_file_actions_t fa; @@ -157,7 +157,7 @@ TEST(posix_spawn, agony) { */ void BenchmarkProcessLifecycle(void) { - int rc, ws, pid; + int ws, pid; char *prog = "/tmp/tiny64"; char *args[] = {"tiny64", NULL}; char *envs[] = {NULL}; diff --git a/test/libc/stdio/sprintf_s_test.c b/test/libc/stdio/sprintf_s_test.c index 37debe004..94637efa2 100644 --- a/test/libc/stdio/sprintf_s_test.c +++ b/test/libc/stdio/sprintf_s_test.c @@ -24,8 +24,6 @@ #include "libc/x/x.h" #include "libc/x/xasprintf.h" -static char buffer[128]; - #define Format(...) _gc(xasprintf(__VA_ARGS__)) /** diff --git a/test/libc/stdio/vappendf_test.c b/test/libc/stdio/vappendf_test.c index 11d16982f..4620b31b5 100644 --- a/test/libc/stdio/vappendf_test.c +++ b/test/libc/stdio/vappendf_test.c @@ -171,7 +171,6 @@ TEST(appendd, nontrivialAmountOfMemory) { } BENCH(vappendf, bench) { - const char t[] = {0}; char *b = 0; EZBENCH2("appendf", donothing, appendf(&b, "hello")); EZBENCH2("kappendf", donothing, kappendf(&b, "hello")); diff --git a/test/libc/str/memcasecmp_test.c b/test/libc/str/memcasecmp_test.c index f98337527..3897ba99f 100644 --- a/test/libc/str/memcasecmp_test.c +++ b/test/libc/str/memcasecmp_test.c @@ -31,9 +31,3 @@ TEST(memcasecmp, test) { EXPECT_EQ(0, memcasecmp("\0ELLo\0ELLo", "\0ELLO\0ELLO", 10)); EXPECT_NE(0, memcasecmp("\0ELLo\0ELLo", "\0ELL-\0ELL-", 10)); } - -BENCH(memcasecmp, bench) { - volatile char *copy = gc(strdup(kHyperion)); - EZBENCH2("memcasecmp", donothing, - __expropriate(memcasecmp(kHyperion, copy, kHyperionSize))); -} diff --git a/test/libc/str/memcpy_test.c b/test/libc/str/memcpy_test.c index 885dd2d97..78cbcf7c6 100644 --- a/test/libc/str/memcpy_test.c +++ b/test/libc/str/memcpy_test.c @@ -136,30 +136,6 @@ TEST(memcpy, overlapping_isFineIfCopyingBackwards) { } } -TEST(stpcpy, test) { - volatile char *p; - volatile char b[16]; - volatile const char *s1 = "hello"; - volatile const char *s2 = "there"; - p = b; - p = stpcpy(p, s1); - EXPECT_EQ((intptr_t)b + 5, (intptr_t)p); - EXPECT_STREQ("hello", b); - p = stpcpy(p, s2); - EXPECT_EQ((intptr_t)b + 10, (intptr_t)p); - EXPECT_STREQ("hellothere", b); -} - -TEST(memcpy, testBackwardsOverlap3) { - volatile char *c; - c = malloc(3); - memcpy(c, "\e[C", 3); - memcpy(c, c + 1, __veil("r", 3) - 1); - EXPECT_EQ('[', c[0]); - EXPECT_EQ('C', c[1]); - free(c); -} - #define B(F, N) \ do { \ char *d = rngset(malloc(N), N, _rand64, -1); \ diff --git a/test/libc/str/memmem_test.c b/test/libc/str/memmem_test.c index 75fc028a8..6a6fd7816 100644 --- a/test/libc/str/memmem_test.c +++ b/test/libc/str/memmem_test.c @@ -31,7 +31,7 @@ void *memmem_naive(const void *haystk, size_t haystklen, // const void *needle, size_t needlelen) { size_t i, j; - if (!needlelen) return haystk; + if (!needlelen) return (void *)haystk; if (needlelen > haystklen) return 0; for (i = 0; i < haystklen; ++i) { for (j = 0;; ++j) { @@ -155,7 +155,7 @@ TEST(memmem, testWut) { } TEST(memmem, fuzz) { - int i, j, k, n, m; + int i, n, m; char a[128], b[128], *p, *q; for (i = 0; i < 10000; ++i) { rngset(a, sizeof(a), lemur64, -1); diff --git a/test/libc/str/strcasestr_test.c b/test/libc/str/strcasestr_test.c index 8452356c6..a4325fc5a 100644 --- a/test/libc/str/strcasestr_test.c +++ b/test/libc/str/strcasestr_test.c @@ -33,8 +33,7 @@ char *strcasestr_naive(const char *haystack, const char *needle) { size_t i; - unsigned k, m; - if (haystack == needle || !*needle) return haystack; + if (haystack == needle || !*needle) return (void *)haystack; for (;;) { for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; diff --git a/test/libc/str/strstr_test.c b/test/libc/str/strstr_test.c index aaa772107..62ea8c500 100644 --- a/test/libc/str/strstr_test.c +++ b/test/libc/str/strstr_test.c @@ -32,8 +32,7 @@ char *strstr_naive(const char *haystack, const char *needle) { size_t i; - unsigned k, m; - if (haystack == needle || !*needle) return haystack; + if (haystack == needle || !*needle) return (void *)haystack; for (;;) { for (i = 0;; ++i) { if (!needle[i]) return (/*unconst*/ char *)haystack; diff --git a/test/libc/str/wcwidth_test.c b/test/libc/str/wcwidth_test.c index 11b1d374f..5199804e5 100644 --- a/test/libc/str/wcwidth_test.c +++ b/test/libc/str/wcwidth_test.c @@ -76,6 +76,5 @@ TEST(strwidth, testTextDelimitingControlCodes_dontHaveSubstance) { } BENCH(wcwidth, bench) { - volatile int x; - EZBENCH2("wcwidth", donothing, x = wcwidth(__veil("r", u'→'))); + EZBENCH2("wcwidth", donothing, __expropriate(wcwidth(__veil("r", u'→')))); } diff --git a/test/libc/thread/pthread_cancel_test.c b/test/libc/thread/pthread_cancel_test.c index 9b2ff3b47..a9b0d7334 100644 --- a/test/libc/thread/pthread_cancel_test.c +++ b/test/libc/thread/pthread_cancel_test.c @@ -68,7 +68,6 @@ TEST(pthread_cancel, self_deferred_waitsForCancellationPoint) { } void *Worker(void *arg) { - int n; char buf[8]; pthread_cleanup_push(OnCleanup, 0); read(pfds[0], buf, sizeof(buf)); @@ -224,8 +223,10 @@ void *CpuBoundWorker(void *arg) { CheckStackIsAligned(); wouldleak = malloc(123); wontleak1 = malloc(123); + (void)wontleak1; pthread_cleanup_push(free, wontleak1); wontleak2 = _gc(malloc(123)); + (void)wontleak2; ASSERT_EQ(0, pthread_setspecific(key, (void *)31337)); ASSERT_EQ(0, pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0)); #ifdef __x86_64__ @@ -262,7 +263,6 @@ TEST(pthread_cancel, async) { } void *CancelSelfWorkerAsync(void *arg) { - char buf[8]; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0); pthread_cleanup_push(OnCleanup, 0); pthread_cancel(pthread_self()); diff --git a/test/libc/thread/pthread_create_test.c b/test/libc/thread/pthread_create_test.c index f4cc79c36..c8973a14a 100644 --- a/test/libc/thread/pthread_create_test.c +++ b/test/libc/thread/pthread_create_test.c @@ -40,7 +40,6 @@ #include "libc/thread/thread2.h" void OnUsr1(int sig, struct siginfo *si, void *vctx) { - struct ucontext *ctx = vctx; } void SetUp(void) { @@ -83,7 +82,7 @@ TEST(pthread_create, testCreateExitJoin) { } static void *CheckSchedule(void *arg) { - int rc, policy; + int policy; struct sched_param prio; ASSERT_EQ(0, pthread_getschedparam(pthread_self(), &policy, &prio)); ASSERT_EQ(SCHED_OTHER, policy); diff --git a/test/libc/thread/pthread_detach_test.c b/test/libc/thread/pthread_detach_test.c index 28bd61f2a..7e3fc9768 100644 --- a/test/libc/thread/pthread_detach_test.c +++ b/test/libc/thread/pthread_detach_test.c @@ -27,7 +27,6 @@ #include "libc/thread/thread.h" void OnUsr1(int sig, struct siginfo *si, void *vctx) { - struct ucontext *ctx = vctx; } void SetUp(void) { diff --git a/test/libc/thread/sem_timedwait_test.c b/test/libc/thread/sem_timedwait_test.c index 53cb55952..1d97b792c 100644 --- a/test/libc/thread/sem_timedwait_test.c +++ b/test/libc/thread/sem_timedwait_test.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" +#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/timespec.h" #include "libc/dce.h" #include "libc/errno.h" @@ -44,54 +45,53 @@ TEST(sem_init, einval) { TEST(sem_post, afterDestroyed_isUndefinedBehavior) { if (!IsModeDbg()) return; - int val; sem_t sem; SPAWN(fork); + signal(SIGABRT, SIG_DFL); ASSERT_SYS(0, 0, sem_init(&sem, 0, 0)); ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_post(&sem); - EXITS(128 + SIGABRT); // see __assert_fail + TERMS(SIGABRT); } TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) { if (!IsModeDbg()) return; - int val; sem_t sem; SPAWN(fork); + signal(SIGABRT, SIG_DFL); ASSERT_SYS(0, 0, sem_init(&sem, 0, 0)); ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_trywait(&sem); - EXITS(128 + SIGABRT); // see __assert_fail + TERMS(SIGABRT); } TEST(sem_wait, afterDestroyed_isUndefinedBehavior) { if (!IsModeDbg()) return; - int val; sem_t sem; SPAWN(fork); + signal(SIGABRT, SIG_DFL); ASSERT_SYS(0, 0, sem_init(&sem, 0, 0)); ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_wait(&sem); - EXITS(128 + SIGABRT); // see __assert_fail + TERMS(SIGABRT); } TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) { if (!IsModeDbg()) return; - int val; sem_t sem; SPAWN(fork); + signal(SIGABRT, SIG_DFL); ASSERT_SYS(0, 0, sem_init(&sem, 0, 0)); ASSERT_SYS(0, 0, sem_destroy(&sem)); IgnoreStderr(); sem_timedwait(&sem, 0); - EXITS(128 + SIGABRT); // see __assert_fail + TERMS(SIGABRT); } void *Worker(void *arg) { - int rc; sem_t **s = arg; struct timespec ts; ASSERT_SYS(0, 0, clock_gettime(CLOCK_REALTIME, &ts)); diff --git a/test/libc/tinymath/sincos_test.c b/test/libc/tinymath/sincos_test.c index 59f6fc73a..2aad10ce5 100644 --- a/test/libc/tinymath/sincos_test.c +++ b/test/libc/tinymath/sincos_test.c @@ -58,9 +58,9 @@ BENCH(sincos, bench) { double _sincos(double, double*, double*) asm("sincos"); float _sincosf(float, float*, float*) asm("sincosf"); long double _sincosl(long double, long double*, long double*) asm("sincosl"); - volatile float sinef, cosinef; - volatile double sine, cosine; - volatile long double sinel, cosinel; + float sinef, cosinef; + double sine, cosine; + long double sinel, cosinel; EZBENCH2("sin+cos", donothing, (_sin(NUM), _cos(NUM))); EZBENCH2("sincos", donothing, _sincos(NUM, &sine, &cosine)); EZBENCH2("sinf+cosf", donothing, (_sinf(NUM), _cosf(NUM))); diff --git a/test/net/http/isacceptablehost_test.c b/test/net/http/isacceptablehost_test.c index 66b35f415..7191abcb0 100644 --- a/test/net/http/isacceptablehost_test.c +++ b/test/net/http/isacceptablehost_test.c @@ -61,8 +61,6 @@ TEST(IsAcceptablePort, test) { } BENCH(IsAcceptableHost, bench) { - uint32_t ip; - uint16_t port; EZBENCH2("IsAcceptableHost 127.0.0.1", donothing, IsAcceptableHost("127.0.0.1", 9)); EZBENCH2("IsAcceptablePort 80", donothing, IsAcceptablePort("80", 2)); diff --git a/test/net/http/parseurl_test.c b/test/net/http/parseurl_test.c index 0ce1641f7..c46ee9ad6 100644 --- a/test/net/http/parseurl_test.c +++ b/test/net/http/parseurl_test.c @@ -556,7 +556,6 @@ TEST(EncodeUrl, testTortureCharacters_doesWhatYouAskItToDoButSchemeCantEscape) { } TEST(EncodeUrl, testUserPassPort_allDependOnHostNonAbsence) { - size_t n; struct Url h; memset(&h, 0, sizeof(h)); h.scheme.n = 1; @@ -582,7 +581,6 @@ TEST(EncodeUrl, testUserPassPort_allDependOnHostNonAbsence) { } TEST(EncodeUrl, testEmptyRegName_isLegal) { - size_t n; struct Url h; memset(&h, 0, sizeof(h)); h.scheme.n = 1; diff --git a/test/net/https/mbedtls_test.c b/test/net/https/mbedtls_test.c index bbbb4fbdf..5c00c54af 100644 --- a/test/net/https/mbedtls_test.c +++ b/test/net/https/mbedtls_test.c @@ -182,7 +182,6 @@ BENCH(p384, bench) { #ifdef MBEDTLS_ECP_C mbedtls_ecp_group_init(&grp); mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP384R1); - uint64_t y[12]; mbedtls_mpi x = {1, 12, _gc(calloc(12, 8))}; EZBENCH2("P-384 modulus MbedTLS MPI lib", donothing, P384_MPI(&x)); EZBENCH2("P-384 modulus Justine rewrite", donothing, P384_JUSTINE(&x)); @@ -224,7 +223,7 @@ TEST(sha1, test) { } TEST(sha224, test) { - uint8_t d[28]; + uint8_t d[50]; uint8_t want[28] = {0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, @@ -244,7 +243,7 @@ TEST(sha256, test) { } TEST(sha384, test) { - uint8_t d[48]; + uint8_t d[70]; uint8_t want[48] = { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, @@ -300,7 +299,6 @@ char *mpi2str(mbedtls_mpi *m) { } mbedtls_mpi *str2mpi(const char *s) { - size_t n; mbedtls_mpi *m; m = calloc(1, sizeof(mbedtls_mpi)); ASSERT_EQ(0, mbedtls_mpi_read_string(m, 10, s)); @@ -315,7 +313,6 @@ char *mpi2str16(mbedtls_mpi *m) { } mbedtls_mpi *str2mpi16(const char *s) { - size_t n; mbedtls_mpi *m; m = calloc(1, sizeof(mbedtls_mpi)); ASSERT_EQ(0, mbedtls_mpi_read_string(m, 16, s)); @@ -618,9 +615,6 @@ TEST(mpi_shift_r, funbye) { } TEST(mpi_shift_l, fun1) { - mbedtls_mpi w = {1, 9, - (uint64_t[]){0, 0, 2 << 1, 4 << 1, 8 << 1, 16 << 1, 32 << 1, - 64 << 1, 128 << 1}}; mbedtls_mpi x = {1, 9, (uint64_t[]){2, 4, 8, 16, 32, 64, 128, 0, 0}}; EXPECT_EQ(0, mbedtls_mpi_shift_l(&x, 129)); EXPECT_EQ(9, x.n); @@ -636,8 +630,6 @@ TEST(mpi_shift_l, fun1) { } TEST(mpi_shift_l, fun2) { - mbedtls_mpi o = {1, 3, (uint64_t[9]){0x8000000000000000, 0, 0}}; - mbedtls_mpi w = {1, 3, (uint64_t[9]){0, 1, 0}}; mbedtls_mpi x = {1, 3, (uint64_t[9]){ 0x8000000000000003, @@ -903,7 +895,7 @@ TEST(endian, big4) { } TEST(Mul4x4, test) { - int i, j, N, M; + int N, M; mbedtls_mpi A, B, C, D; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 4; @@ -926,7 +918,7 @@ TEST(Mul4x4, test) { } BENCH(Mul4x4, bench) { - int i, j, N, M; + int i, N, M; mbedtls_mpi A, B, C, D, E; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 4; @@ -981,7 +973,7 @@ BENCH(Mul4x4, bench) { } BENCH(Mul6x6, bench) { - int i, j, N, M; + int i, N, M; mbedtls_mpi A, B, C, D; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 6; @@ -1018,8 +1010,8 @@ BENCH(Mul6x6, bench) { } BENCH(Mul10x10, bench) { - int i, j, N, M; - mbedtls_mpi A, B, C, D; + int N, M; + mbedtls_mpi A, B, C; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 10; M = 10; @@ -1037,8 +1029,8 @@ BENCH(Mul10x10, bench) { } BENCH(Mul16x16, bench) { - int i, j, N, M; - mbedtls_mpi A, B, C, D; + int N, M; + mbedtls_mpi A, B, C; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 16; M = 16; @@ -1056,7 +1048,7 @@ BENCH(Mul16x16, bench) { } BENCH(Mul32x32, bench) { - int i, j, N, M; + int i, N, M; mbedtls_mpi A, B, C, D, K; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 32; @@ -1097,8 +1089,8 @@ BENCH(Mul32x32, bench) { } BENCH(Mul16x1, bench) { - int i, j, N, M; - mbedtls_mpi A, B, C, D; + int N, M; + mbedtls_mpi A, B, C; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 16; M = 1; @@ -1116,8 +1108,8 @@ BENCH(Mul16x1, bench) { } BENCH(Mul32x1, bench) { - int i, j, N, M; - mbedtls_mpi A, B, C, D; + int N, M; + mbedtls_mpi A, B, C; if (!X86_HAVE(BMI2) || !X86_HAVE(ADX)) return; N = 32; M = 1; diff --git a/test/tool/build/lib/javadown_test.c b/test/tool/build/lib/javadown_test.c index fca500753..47cafb2ed 100644 --- a/test/tool/build/lib/javadown_test.c +++ b/test/tool/build/lib/javadown_test.c @@ -16,12 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/mem.h" +#include "tool/build/lib/javadown.h" #include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" -#include "tool/build/lib/javadown.h" TEST(ParseJavadown, testOneLiner) { const char *comment = "/** Parses javadown. */"; @@ -40,7 +40,6 @@ TEST(ParseJavadown, testShortAndTerse) { * Parses javadown.\n\ * @see love\n\ */"; - const char *title = "Parses javadown and that is the bottom line."; struct Javadown *jd; jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2); EXPECT_FALSE(jd->isfileoverview); @@ -60,7 +59,6 @@ TEST(ParseJavadown, testBlankLineOmitted) { * Description.\n\ * @see love\n\ */"; - const char *title = "Parses javadown and that is the bottom line."; struct Javadown *jd; jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2); EXPECT_FALSE(jd->isfileoverview); diff --git a/test/tool/plinko/plinko_test.c b/test/tool/plinko/plinko_test.c index d1b302ea2..26dcd5767 100644 --- a/test/tool/plinko/plinko_test.c +++ b/test/tool/plinko/plinko_test.c @@ -63,7 +63,6 @@ void SetUpOnce(void) { } TEST(plinko, worksOrPrintsNiceError) { - size_t n; ssize_t rc, got; char buf[1024], drain[64]; sigset_t chldmask, savemask; diff --git a/third_party/bzip2/bzip2.mk b/third_party/bzip2/bzip2.mk index 47f15e952..b7b0a6c71 100644 --- a/third_party/bzip2/bzip2.mk +++ b/third_party/bzip2/bzip2.mk @@ -63,6 +63,7 @@ o/$(MODE)/third_party/bzip2/bzip2recover.com.dbg: \ $(THIRD_PARTY_BZIP2_A_OBJS): private \ CFLAGS += \ + -w \ -ffunction-sections \ -fdata-sections diff --git a/third_party/chibicc/as.c b/third_party/chibicc/as.c index 271309f3f..e05283875 100644 --- a/third_party/chibicc/as.c +++ b/third_party/chibicc/as.c @@ -775,7 +775,7 @@ static void Tokenize(struct As *a, int path) { static int GetSymbol(struct As *a, int name) { struct HashEntry *p; - unsigned i, j, k, n, m, h, n2; + unsigned i, j, k, n, m, h; if (!(h = crc32c(0, a->slices.p[name].p, a->slices.p[name].n))) h = 1; n = a->symbolindex.n; i = 0; @@ -932,7 +932,6 @@ static int NewBinary(struct As *a, enum ExprKind k, int lhs, int rhs) { // | symbol // | reference static int ParsePrimary(struct As *a, int *rest, int i) { - int e; if (IsInt(a, i)) { *rest = i + 1; return NewPrimary(a, EX_INT, a->ints.p[a->things.p[i].i]); @@ -1765,7 +1764,7 @@ static void OnSize(struct As *a, struct Slice s) { } static void OnEqu(struct As *a, struct Slice s) { - int i, j; + int i; i = GetSymbol(a, a->things.p[a->i++].i); ConsumeComma(a); a->symbols.p[i].offset = GetInt(a); @@ -1967,15 +1966,17 @@ static int RemoveRexw(int x) { static int GetRegisterReg(struct As *a) { int reg; - struct Slice wut; - if ((reg = FindRegReg(GetSlice(a))) == -1) InvalidRegister(a); + if ((reg = FindRegReg(GetSlice(a))) == -1) { + InvalidRegister(a); + } return reg; } static int GetRegisterRm(struct As *a) { int reg; - struct Slice wut; - if ((reg = FindRegRm(GetSlice(a))) == -1) InvalidRegister(a); + if ((reg = FindRegRm(GetSlice(a))) == -1) { + InvalidRegister(a); + } return reg; } @@ -1992,7 +1993,7 @@ static int ParseModrm(struct As *a, int *disp) { │││││├──────┐├┐├─┐├─┐ 0b00000000000000000000000000000000*/ struct Slice str; - int reg, scale, modrm = 0; + int reg, modrm = 0; if (!ConsumeSegment(a) && IsRegister(a, a->i)) { *disp = 0; modrm = GetRegisterRm(a) | ISREG; @@ -2057,12 +2058,12 @@ static void EmitImm(struct As *a, int reg, int imm) { } static void EmitModrm(struct As *a, int reg, int modrm, int disp) { - int relo, mod, rm; + int relo, mod; void (*emitter)(struct As *, uint128_t); reg &= 7; reg <<= 3; if (modrm & ISREG) { - EmitByte(a, 0300 | reg | modrm & 7); + EmitByte(a, 0300 | reg | (modrm & 7)); } else { if (modrm & ISRIP) { EmitByte(a, 005 | reg); @@ -2348,7 +2349,7 @@ static dontinline void OpXadd(struct As *a) { } static dontinline int OpF6Impl(struct As *a, struct Slice s, int reg) { - int modrm, imm, disp; + int modrm, disp; modrm = ParseModrm(a, &disp); reg |= GetOpSize(a, s, modrm, 1) << 3; EmitRexOpModrm(a, 0xF6, reg, modrm, disp, 1); @@ -2642,7 +2643,6 @@ static void OnPush(struct As *a, struct Slice s) { } static void OnRdpid(struct As *a, struct Slice s) { - int modrm, disp; EmitVarword(a, 0xf30fc7); EmitByte(a, 0370 | GetRegisterReg(a)); } @@ -2700,6 +2700,8 @@ static void OnFile(struct As *a, struct Slice s) { struct Slice path; fileno = GetInt(a); path = GetSlice(a); + (void)fileno; + (void)path; // TODO: DWARF } @@ -2707,6 +2709,8 @@ static void OnLoc(struct As *a, struct Slice s) { int fileno, lineno; fileno = GetInt(a); lineno = GetInt(a); + (void)fileno; + (void)lineno; // TODO: DWARF } @@ -2762,7 +2766,7 @@ static void OnFxch(struct As *a, struct Slice s) { int rm; rm = !IsSemicolon(a) ? GetRegisterRm(a) : 1; EmitByte(a, 0xD9); - EmitByte(a, 0310 | rm & 7); + EmitByte(a, 0310 | (rm & 7)); } static void OnBswap(struct As *a, struct Slice s) { @@ -2770,7 +2774,7 @@ static void OnBswap(struct As *a, struct Slice s) { srm = GetRegisterRm(a); EmitRex(a, srm); EmitByte(a, 0x0F); - EmitByte(a, 0310 | srm & 7); + EmitByte(a, 0310 | (srm & 7)); } static dontinline void OpFcomImpl(struct As *a, int op) { @@ -2786,7 +2790,7 @@ static dontinline void OpFcomImpl(struct As *a, int op) { } } } - EmitVarword(a, op | rm & 7); + EmitVarword(a, op | (rm & 7)); } static dontinline void OpFcom(struct As *a, int op) { diff --git a/third_party/chibicc/asm.c b/third_party/chibicc/asm.c index 9abd149a4..823732a09 100644 --- a/third_party/chibicc/asm.c +++ b/third_party/chibicc/asm.c @@ -670,7 +670,7 @@ static void PopAsmInputs(Asm *a) { } static void StoreAsmOutputs(Asm *a) { - int i, z, x0, x1; + int i, z; for (i = 0; i < a->n; ++i) { if (a->ops[i].flow == '=' || a->ops[i].flow == '+') { switch (a->ops[i].type) { diff --git a/third_party/chibicc/chibicc.c b/third_party/chibicc/chibicc.c index 06c47247e..a43090738 100644 --- a/third_party/chibicc/chibicc.c +++ b/third_party/chibicc/chibicc.c @@ -424,7 +424,7 @@ static bool NeedsShellQuotes(const char *s) { static bool run_subprocess(char **argv) { int rc, ws; - size_t i, j, n; + size_t i, j; if (opt_verbose) { for (i = 0; argv[i]; i++) { fputc(' ', stderr); diff --git a/third_party/chibicc/chibicc.h b/third_party/chibicc/chibicc.h index 300cd74e4..c3f671834 100644 --- a/third_party/chibicc/chibicc.h +++ b/third_party/chibicc/chibicc.h @@ -180,7 +180,7 @@ struct AsmOperand { uint8_t reg; uint8_t type; char flow; - char x87mask; + unsigned char x87mask; bool isused; int regmask; int predicate; @@ -216,10 +216,10 @@ void gen_addr(Node *); void gen_asm(Asm *); void gen_expr(Node *); void pop(char *); -void popreg(char *); +void popreg(const char *); void print_loc(int64_t, int64_t); void push(void); -void pushreg(char *); +void pushreg(const char *); // // fpclassify.c diff --git a/third_party/chibicc/codegen.c b/third_party/chibicc/codegen.c index 41571108d..778f96058 100644 --- a/third_party/chibicc/codegen.c +++ b/third_party/chibicc/codegen.c @@ -67,7 +67,6 @@ static void emitlin(char *nextline) { void println(char *fmt, ...) { va_list ap; - char *nextline; va_start(ap, fmt); emitlin(xvasprintf(fmt, ap)); va_end(ap); @@ -105,12 +104,12 @@ void pop2(char *a, char *b) { DCHECK_GE(depth, 0); } -void pushreg(char *arg) { +void pushreg(const char *arg) { println("\tpush\t%%%s", arg); depth++; } -void popreg(char *arg) { +void popreg(const char *arg) { println("\tpop\t%%%s", arg); depth--; DCHECK_GE(depth, 0); @@ -1777,15 +1776,13 @@ void gen_expr(Node *node) { gen_expr(node->lhs); pop("%rdi"); } - char *ax, *di, *dx; + char *ax, *di; if (node->lhs->ty->kind == TY_LONG || node->lhs->ty->base) { ax = "%rax"; di = "%rdi"; - dx = "%rdx"; } else { ax = "%eax"; di = "%edi"; - dx = "%edx"; } switch (node->kind) { case ND_PMOVMSKB: diff --git a/third_party/chibicc/dox1.c b/third_party/chibicc/dox1.c index 81b07e3b6..68c2b8881 100644 --- a/third_party/chibicc/dox1.c +++ b/third_party/chibicc/dox1.c @@ -42,7 +42,6 @@ struct DoxWriter { }; static void SerializeData(struct Buffer *buf, const void *p, unsigned long n) { - struct Slice *s; buf->p = realloc(buf->p, buf->n + n); memcpy(buf->p + buf->n, p, n); buf->n += n; diff --git a/third_party/chibicc/dox2.c b/third_party/chibicc/dox2.c index 40fc201c1..236505e6c 100644 --- a/third_party/chibicc/dox2.c +++ b/third_party/chibicc/dox2.c @@ -153,7 +153,6 @@ static char *DeserializeStr(struct Dox *dox) { static struct Javadown *DeserializeJavadown(struct Dox *dox) { int i; - bool present; struct Javadown *jd; if (DeserializeInt(dox)) { jd = FreeLater(dox, calloc(1, sizeof(struct Javadown))); @@ -273,7 +272,7 @@ static bool AddSet(struct Set *set, char *s) { static int CompareDoxIndexEntry(const void *p1, const void *p2, void *arg) { struct Dox *dox; const char *s1, *s2; - struct DoxIndexEntry *a, *b; + const struct DoxIndexEntry *a, *b; dox = arg, a = p1, b = p2; s1 = a->t == kObject ? dox->objects.p[a->i].name : dox->macros.p[a->i].name; s2 = b->t == kObject ? dox->objects.p[b->i].name : dox->macros.p[b->i].name; diff --git a/third_party/chibicc/parse.c b/third_party/chibicc/parse.c index 1117ade40..8c1c98e9a 100644 --- a/third_party/chibicc/parse.c +++ b/third_party/chibicc/parse.c @@ -2436,7 +2436,6 @@ static Node *logor(Token **rest, Token *tok) { // logand = binor ("&&" binor)* static Node *logand(Token **rest, Token *tok) { - Token *start = tok; Node *node = binor(&tok, tok); while (EQUAL(tok, "&&")) { Token *start = tok; diff --git a/third_party/compiler_rt/divtc3.c b/third_party/compiler_rt/divtc3.c index 85353651c..9ec00b7a0 100644 --- a/third_party/compiler_rt/divtc3.c +++ b/third_party/compiler_rt/divtc3.c @@ -15,6 +15,9 @@ #include "libc/math.h" #if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) +// todo: what m=opt +#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch" + __static_yoink("huge_compiler_rt_license"); #define QUAD_PRECISION diff --git a/third_party/compiler_rt/multc3.c b/third_party/compiler_rt/multc3.c index 187b7af1e..daa20fd11 100644 --- a/third_party/compiler_rt/multc3.c +++ b/third_party/compiler_rt/multc3.c @@ -20,6 +20,9 @@ __static_yoink("huge_compiler_rt_license"); /* Returns: the product of a + ib and c + id */ +// todo: what m=opt +#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch" + COMPILER_RT_ABI long double _Complex __multc3(long double a, long double b, long double c, long double d) { long double ac = a * c; diff --git a/third_party/ctags/flex.c b/third_party/ctags/flex.c index b98b035d6..3e31293b5 100644 --- a/third_party/ctags/flex.c +++ b/third_party/ctags/flex.c @@ -1475,6 +1475,7 @@ static boolean parseStatement (tokenInfo *const token) boolean is_global = FALSE; boolean is_prototype = FALSE; vString * fulltag; + (void)is_prototype; vStringClear(saveScope); vStringCopy (saveScope, token->scope); diff --git a/third_party/ctags/jscript.c b/third_party/ctags/jscript.c index b2becf75f..0e2ebd1d3 100644 --- a/third_party/ctags/jscript.c +++ b/third_party/ctags/jscript.c @@ -1106,6 +1106,8 @@ static boolean parseStatement (tokenInfo *const token, boolean is_inside_class) boolean has_methods = FALSE; vString * fulltag; + (void)is_prototype; + vStringClear(saveScope); /* * Functions can be named or unnamed. diff --git a/third_party/ctags/sql.c b/third_party/ctags/sql.c index 5f719b960..677f6c489 100644 --- a/third_party/ctags/sql.c +++ b/third_party/ctags/sql.c @@ -1242,6 +1242,7 @@ static void parseStatements (tokenInfo *const token, const boolean exit_on_endif { boolean isAnsi = TRUE; boolean stmtTerm = FALSE; + (void)isAnsi; do { diff --git a/third_party/dlmalloc/init.inc b/third_party/dlmalloc/init.inc index 6c2c26dd6..4c6114953 100644 --- a/third_party/dlmalloc/init.inc +++ b/third_party/dlmalloc/init.inc @@ -5,7 +5,7 @@ #if LOCK_AT_FORK static void dlmalloc_pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); } static void dlmalloc_post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); } -static void dlmalloc_post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); } +static void dlmalloc_post_fork_child(void) { (void)INITIAL_LOCK(&(gm)->mutex); } #endif /* LOCK_AT_FORK */ /* Initialize mparams */ diff --git a/third_party/double-conversion/wrapper.cc b/third_party/double-conversion/wrapper.cc index 73f07d13c..c29402003 100644 --- a/third_party/double-conversion/wrapper.cc +++ b/third_party/double-conversion/wrapper.cc @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/double-conversion/wrapper.h" #include "libc/intrin/bits.h" #include "libc/str/str.h" #include "third_party/double-conversion/double-conversion.h" #include "third_party/double-conversion/double-to-string.h" -#include "third_party/double-conversion/wrapper.h" namespace double_conversion { extern "C" { @@ -59,7 +59,7 @@ char* DoubleToLua(char buf[128], double x) { } double StringToDouble(const char* s, size_t n, int* out_processed) { - if (n == -1) n = strlen(s); + if (n == -1ull) n = strlen(s); int flags = StringToDoubleConverter::ALLOW_CASE_INSENSITIVITY | StringToDoubleConverter::ALLOW_LEADING_SPACES | StringToDoubleConverter::ALLOW_TRAILING_JUNK | diff --git a/third_party/gdtoa/gdtoa_fltrnds.inc b/third_party/gdtoa/gdtoa_fltrnds.inc index 919674f35..8023aa03d 100644 --- a/third_party/gdtoa/gdtoa_fltrnds.inc +++ b/third_party/gdtoa/gdtoa_fltrnds.inc @@ -1,7 +1,8 @@ /* clang-format off */ - FPI *fpi, fpi1; + FPI fpi1; int Rounding; + const FPI *fpi; Rounding = FLT_ROUNDS; fpi = &fpi0; if (Rounding != FPI_Round_near) { diff --git a/third_party/gdtoa/misc.c b/third_party/gdtoa/misc.c index ffcd7071f..33d7d08fa 100644 --- a/third_party/gdtoa/misc.c +++ b/third_party/gdtoa/misc.c @@ -128,7 +128,6 @@ __gdtoa_Balloc(int k, ThInfo **PTI) { int x; Bigint *rv; - unsigned int len; ThInfo *TI; if (!(TI = *PTI)) *PTI = TI = __gdtoa_get_TI(); diff --git a/third_party/gdtoa/strtord.c b/third_party/gdtoa/strtord.c index 9bc957c0b..e94afec6c 100644 --- a/third_party/gdtoa/strtord.c +++ b/third_party/gdtoa/strtord.c @@ -67,7 +67,8 @@ int strtord(const char *s, char **sp, int rounding, double *d) { static const FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI, 0 /*unused*/ }; - FPI *fpi, fpi1; + FPI fpi1; + const FPI *fpi; ULong bits[2]; Long exp; int k; diff --git a/third_party/gdtoa/strtordd.c b/third_party/gdtoa/strtordd.c index 4292a6972..e73d7668b 100644 --- a/third_party/gdtoa/strtordd.c +++ b/third_party/gdtoa/strtordd.c @@ -165,7 +165,8 @@ int strtordd(const char *s, char **sp, int rounding, double *dd) { static const FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0, 0 /*unused*/ }; - FPI *fpi, fpi1; + FPI fpi1; + const FPI *fpi; ULong bits[4]; Long exp; int k; diff --git a/third_party/gdtoa/strtorf.c b/third_party/gdtoa/strtorf.c index fb02d25ac..bcf5564d6 100644 --- a/third_party/gdtoa/strtorf.c +++ b/third_party/gdtoa/strtorf.c @@ -63,7 +63,8 @@ int strtorf(const char *s, char **sp, int rounding, float *f) { static const FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI, 0 /*unused*/ }; - FPI *fpi, fpi1; + FPI fpi1; + const FPI *fpi; ULong bits[1]; Long exp; int k; diff --git a/third_party/gdtoa/strtorx.c b/third_party/gdtoa/strtorx.c index debf10c31..15ed37edc 100644 --- a/third_party/gdtoa/strtorx.c +++ b/third_party/gdtoa/strtorx.c @@ -74,7 +74,8 @@ int strtorx(const char *s, char **sp, int rounding, void *L) { static const FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI, 0 /*unused*/ }; - FPI *fpi, fpi1; + FPI fpi1; + const FPI *fpi; ULong bits[2]; Long exp; int k; diff --git a/third_party/ggml/ggml.c b/third_party/ggml/ggml.c index a30474581..98d7c4841 100644 --- a/third_party/ggml/ggml.c +++ b/third_party/ggml/ggml.c @@ -4198,7 +4198,7 @@ const char * ggml_get_name(const struct ggml_tensor * tensor) { } void ggml_set_name(struct ggml_tensor * tensor, const char * name) { - strncpy(tensor->name, name, sizeof(tensor->name)); + strlcpy(tensor->name, name, sizeof(tensor->name)); tensor->name[sizeof(tensor->name) - 1] = '\0'; } @@ -15755,11 +15755,11 @@ size_t ggml_quantize_q8_0(const float * src, void * dst, int n, int k, int64_t * } static const quantize_chunk_f *const ggjt_v3_quantize_chunk[GGML_TYPE_COUNT] = { - [GGML_TYPE_Q4_0] = ggml_quantize_q4_0, - [GGML_TYPE_Q4_1] = ggml_quantize_q4_1, - [GGML_TYPE_Q5_0] = ggml_quantize_q5_0, - [GGML_TYPE_Q5_1] = ggml_quantize_q5_1, - [GGML_TYPE_Q8_0] = ggml_quantize_q8_0, + [GGML_TYPE_Q4_0] = (void *)ggml_quantize_q4_0, + [GGML_TYPE_Q4_1] = (void *)ggml_quantize_q4_1, + [GGML_TYPE_Q5_0] = (void *)ggml_quantize_q5_0, + [GGML_TYPE_Q5_1] = (void *)ggml_quantize_q5_1, + [GGML_TYPE_Q8_0] = (void *)ggml_quantize_q8_0, }; const quantize_chunk_f *const *GGML_QUANTIZE_CHUNK; static_assert(GGML_TYPE_COUNT == 13, "GGML_QUANTIZE_CHUNK is outdated"); diff --git a/third_party/ggml/llama.cc b/third_party/ggml/llama.cc index 4235571bc..a6cb47b5a 100644 --- a/third_party/ggml/llama.cc +++ b/third_party/ggml/llama.cc @@ -510,7 +510,7 @@ struct llama_file_loader { } vocab.token_to_id[word] = i; - vocab.longest_token = MAX(vocab.longest_token, word.size()); + vocab.longest_token = std::max(vocab.longest_token, (int)word.size()); auto & tok_score = vocab.id_to_token[i]; tok_score.tok = std::move(word); diff --git a/third_party/ggml/main.cc b/third_party/ggml/main.cc index f81cd70d0..969cdb559 100644 --- a/third_party/ggml/main.cc +++ b/third_party/ggml/main.cc @@ -389,7 +389,7 @@ int main(int argc, char ** argv) { } fprintf(stderr, "\"\n"); fprintf(stderr, "%s: second part of prompt: \"", __func__); - for (int i = n_keep; i < embd_inp.size(); i++) { + for (int i = n_keep; i < (int)embd_inp.size(); i++) { fprintf(stderr, "%'s", llama_token_to_str(ctx, embd_inp[i])); } fprintf(stderr, "\"\n"); @@ -607,7 +607,6 @@ int main(int argc, char ** argv) { if (just_finished_initializing_prompt && !params.prompt_path.empty()) { int fd = -1; int close_rc; - uint8_t buf[8]; size_t file_size; size_t state_size; std::string tmppath; diff --git a/third_party/libcxx/__config b/third_party/libcxx/__config index 7e41bed6e..7aa7c9a50 100644 --- a/third_party/libcxx/__config +++ b/third_party/libcxx/__config @@ -14,8 +14,9 @@ #define _LIBCPP_ABI_UNSTABLE #define _LIBCPP_NO_EXCEPTIONS #define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS #define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS #define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE #define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR @@ -889,7 +890,7 @@ typedef unsigned int char32_t; // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. #if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) # if __has_attribute(deprecated) -# define _LIBCPP_DEPRECATED __attribute__ ((deprecated)) +# define _LIBCPP_DEPRECATED __attribute__ ((__deprecated__)) # elif _LIBCPP_STD_VER > 11 # define _LIBCPP_DEPRECATED [[deprecated]] # else diff --git a/third_party/linenoise/linenoise.c b/third_party/linenoise/linenoise.c index c8afb3589..10951cadb 100644 --- a/third_party/linenoise/linenoise.c +++ b/third_party/linenoise/linenoise.c @@ -231,30 +231,30 @@ struct linenoiseRing { }; struct linenoiseState { - int state; /* state machine */ - int ifd; /* terminal stdin file descriptor */ - int ofd; /* terminal stdout file descriptor */ - struct winsize ws; /* rows and columns in terminal */ - char *buf; /* edited line buffer */ - const char *prompt; /* prompt to display */ - int hindex; /* history index */ - int rows; /* rows being used */ - int oldpos; /* previous refresh cursor position */ - unsigned debugrow; /* row for debug display */ - unsigned buflen; /* edited line buffer size */ - unsigned pos; /* current buffer index */ - unsigned len; /* current edited line length */ - unsigned mark; /* saved cursor position */ - unsigned yi, yj; /* boundaries of last yank */ - char seq[2][16]; /* keystroke history for yanking code */ - char final; /* set to true on last update */ - char dirty; /* if an update was squashed */ + int state; /* state machine */ + int ifd; /* terminal stdin file descriptor */ + int ofd; /* terminal stdout file descriptor */ + struct winsize ws; /* rows and columns in terminal */ + char *buf; /* edited line buffer */ + char *prompt; /* prompt to display */ + int hindex; /* history index */ + int rows; /* rows being used */ + int oldpos; /* previous refresh cursor position */ + unsigned debugrow; /* row for debug display */ + unsigned buflen; /* edited line buffer size */ + unsigned pos; /* current buffer index */ + unsigned len; /* current edited line length */ + unsigned mark; /* saved cursor position */ + unsigned yi, yj; /* boundaries of last yank */ + char seq[2][16]; /* keystroke history for yanking code */ + char final; /* set to true on last update */ + char dirty; /* if an update was squashed */ linenoiseCompletions lc; struct abuf ab; int i, j, perline, itemlen; // for reverse search int fail, matlen, oldindex, olderpos; - const char *oldprompt; + char *oldprompt; }; static const unsigned short kMirrorLeft[][2] = { @@ -296,8 +296,6 @@ static char iscapital; static int historylen; static signed char rawmode = -1; static struct linenoiseRing ring; -static struct sigaction orig_int; -static struct sigaction orig_quit; static struct sigaction orig_cont; static struct sigaction orig_winch; static struct termios orig_termios; @@ -386,7 +384,7 @@ static struct rune GetUtf8(const char *p, size_t n) { if ((r.n = r.c = 0) < n && (r.c = p[r.n++] & 255) >= 0300) { r.c = DecodeUtf8(r.c).c; while (r.n < n && (p[r.n] & 0300) == 0200) { - r.c = r.c << 6 | p[r.n++] & 077; + r.c = r.c << 6 | (p[r.n++] & 077); } } return r; @@ -738,7 +736,7 @@ static void linenoiseDebug(struct linenoiseState *l, const char *fmt, ...) { va_list va; char *msg = 0; char *ansi = 0; - int x, y, n, dy, xn; + int x, y, n, xn; va_start(va, fmt); (vappendf)(&msg, fmt, va); va_end(va); @@ -1105,9 +1103,9 @@ static void linenoiseRefreshLineImpl(struct linenoiseState *l, int force, struct abuf ab; struct rune rune; unsigned flip[2]; - const char *p, *buf; + const char *buf; struct winsize oldsize; - int i, x, y, t, xn, yn, cx, cy, tn, resized; + int i, x, t, xn, yn, cx, cy, tn, resized; int fd, plen, width, pwidth, rows, len, pos; /* @@ -1464,9 +1462,9 @@ static void linenoiseEditRuboutWord(struct linenoiseState *l) { static void linenoiseEditXlatWord(struct linenoiseState *l, wint_t xlat(wint_t)) { int c; + size_t i, j; struct rune r; struct abuf ab; - size_t i, j, p; abInit(&ab); i = Forwards(l, l->pos, iswseparator); for (j = i; j < l->len; j += r.n) { @@ -1569,7 +1567,6 @@ static void linenoiseEditTranspose(struct linenoiseState *l) { static void linenoiseEditTransposeWords(struct linenoiseState *l) { char *q, *p; - struct rune r; size_t pi, xi, xj, yi, yj; pi = EscapeWord(l); xj = Backwards(l, pi, iswseparator); @@ -1897,7 +1894,7 @@ ssize_t linenoiseEdit(struct linenoiseState *l, const char *prompt, char **obuf, // handle reverse history search if (seq[0] == CTRL('R')) { - int fail, added, oldpos; + int fail, added; if (historylen <= 1) continue; l->ab.len = 0; l->olderpos = l->pos; diff --git a/third_party/lua/cosmo.h b/third_party/lua/cosmo.h index 1d37a947f..a1d723488 100644 --- a/third_party/lua/cosmo.h +++ b/third_party/lua/cosmo.h @@ -29,7 +29,7 @@ int LuaEncodeJsonData(lua_State *, char **, int, struct EncoderConfig); int LuaEncodeLuaData(lua_State *, char **, int, struct EncoderConfig); int LuaEncodeUrl(lua_State *); int LuaParseUrl(lua_State *); -int LuaPushHeader(lua_State *, struct HttpMessage *, char *, int); +int LuaPushHeader(lua_State *, struct HttpMessage *, const char *, int); int LuaPushHeaders(lua_State *, struct HttpMessage *, const char *); void LuaPrintStack(lua_State *); void LuaPushLatin1(lua_State *, const char *, size_t); diff --git a/third_party/lua/lrepl.c b/third_party/lua/lrepl.c index 5f3defb50..3ec453164 100644 --- a/third_party/lua/lrepl.c +++ b/third_party/lua/lrepl.c @@ -73,7 +73,7 @@ linenoiseCompletionCallback *lua_repl_completions_callback; struct linenoiseState *lua_repl_linenoise; const char *lua_progname; static lua_State *globalL; -static const char *g_historypath; +static char *g_historypath; /* ** {================================================================== @@ -105,8 +105,9 @@ void lua_readline_completions (const char *p, linenoiseCompletions *c) { size_t n; bool found; lua_State *L; + const char *a; const char *name; - char *a, *b, *s, *component; + char *b, *s, *component; // start searching globals L = globalL; @@ -318,7 +319,6 @@ static void lstop (lua_State *L, lua_Debug *ar) { static int multiline (lua_State *L) { for (;;) { /* repeat until gets a complete statement */ size_t len; - ssize_t rc; const char *line = lua_tolstring(L, 1, &len); /* get what it has */ int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */ if (!incomplete(L, status) || pushline(L, 0) != 1) diff --git a/third_party/lua/lua.main.c b/third_party/lua/lua.main.c index 8a0f05434..c0f533542 100644 --- a/third_party/lua/lua.main.c +++ b/third_party/lua/lua.main.c @@ -70,9 +70,6 @@ STATIC_STACK_SIZE(0x80000); #define LUA_INITVARVERSION LUA_INIT_VAR LUA_VERSUFFIX -static lua_State *globalL = NULL; - - static bool lua_stdin_is_tty(void) { return isatty(0); } diff --git a/third_party/lua/luaencodejsondata.c b/third_party/lua/luaencodejsondata.c index 528f7d6d9..849f7341d 100644 --- a/third_party/lua/luaencodejsondata.c +++ b/third_party/lua/luaencodejsondata.c @@ -69,8 +69,8 @@ OnError: static int SerializeString(lua_State *L, char **buf, int idx, struct Serializer *z) { - char *s; size_t m; + const char *s; s = lua_tolstring(L, idx, &m); if (!(s = EscapeJsStringLiteral(&z->strbuf, &z->strbuflen, s, m, &m))) { goto OnError; diff --git a/third_party/lua/luaencodeluadata.c b/third_party/lua/luaencodeluadata.c index 72efc26b8..723f3535e 100644 --- a/third_party/lua/luaencodeluadata.c +++ b/third_party/lua/luaencodeluadata.c @@ -113,7 +113,7 @@ OnError: static int SerializeNumber(lua_State *L, char **buf, int idx) { int64_t x; - char ibuf[24]; + char ibuf[128]; if (lua_isinteger(L, idx)) { x = luaL_checkinteger(L, idx); if (x == -9223372036854775807 - 1) { @@ -252,7 +252,6 @@ OnError: static int SerializeArray(lua_State *L, char **buf, struct Serializer *z, int depth) { size_t i, n; - const char *s; RETURN_ON_ERROR(appendw(buf, '{')); n = lua_rawlen(L, -1); for (i = 1; i <= n; i++) { @@ -269,7 +268,6 @@ OnError: static int SerializeObject(lua_State *L, char **buf, struct Serializer *z, int depth, bool multi) { - int rc; size_t n; const char *s; bool comma = false; @@ -308,8 +306,8 @@ OnError: static int SerializeSorted(lua_State *L, char **buf, struct Serializer *z, int depth, bool multi) { + int i; size_t n; - int i, rc; const char *s; struct StrList sl = {0}; lua_pushnil(L); @@ -354,7 +352,6 @@ static int SerializeTable(lua_State *L, char **buf, int idx, struct Serializer *z, int depth) { int rc; bool multi; - intptr_t rsp, bot; if (UNLIKELY(!HaveStackMemory(getauxval(AT_PAGESZ)))) { z->reason = "out of stack"; return -1; diff --git a/third_party/lua/luaencodeurl.c b/third_party/lua/luaencodeurl.c index b9717968a..b4aa33683 100644 --- a/third_party/lua/luaencodeurl.c +++ b/third_party/lua/luaencodeurl.c @@ -25,23 +25,28 @@ #include "third_party/lua/lua.h" int LuaEncodeUrl(lua_State *L) { + char *data; size_t size; - struct Url h; int i, j, n; - const char *data; + struct Url h; if (!lua_isnil(L, 1)) { i = lua_gettop(L); bzero(&h, sizeof(h)); luaL_checktype(L, 1, LUA_TTABLE); if (lua_getfield(L, 1, "scheme")) - h.scheme.p = lua_tolstring(L, -1, &h.scheme.n); + h.scheme.p = (char *)lua_tolstring(L, -1, &h.scheme.n); if (lua_getfield(L, 1, "fragment")) - h.fragment.p = lua_tolstring(L, -1, &h.fragment.n); - if (lua_getfield(L, 1, "user")) h.user.p = lua_tolstring(L, -1, &h.user.n); - if (lua_getfield(L, 1, "pass")) h.pass.p = lua_tolstring(L, -1, &h.pass.n); - if (lua_getfield(L, 1, "host")) h.host.p = lua_tolstring(L, -1, &h.host.n); - if (lua_getfield(L, 1, "port")) h.port.p = lua_tolstring(L, -1, &h.port.n); - if (lua_getfield(L, 1, "path")) h.path.p = lua_tolstring(L, -1, &h.path.n); + h.fragment.p = (char *)lua_tolstring(L, -1, &h.fragment.n); + if (lua_getfield(L, 1, "user")) + h.user.p = (char *)lua_tolstring(L, -1, &h.user.n); + if (lua_getfield(L, 1, "pass")) + h.pass.p = (char *)lua_tolstring(L, -1, &h.pass.n); + if (lua_getfield(L, 1, "host")) + h.host.p = (char *)lua_tolstring(L, -1, &h.host.n); + if (lua_getfield(L, 1, "port")) + h.port.p = (char *)lua_tolstring(L, -1, &h.port.n); + if (lua_getfield(L, 1, "path")) + h.path.p = (char *)lua_tolstring(L, -1, &h.path.n); lua_settop(L, i); // restore stack position if (lua_getfield(L, 1, "params")) { luaL_checktype(L, -1, LUA_TTABLE); @@ -55,10 +60,10 @@ int LuaEncodeUrl(lua_State *L) { h.params.p = xrealloc(h.params.p, ++h.params.n * sizeof(*h.params.p)); h.params.p[h.params.n - 1].key.p = - lua_tolstring(L, -1, &h.params.p[h.params.n - 1].key.n); + (char *)lua_tolstring(L, -1, &h.params.p[h.params.n - 1].key.n); if (lua_geti(L, -2, 2)) { - h.params.p[h.params.n - 1].val.p = - lua_tolstring(L, -1, &h.params.p[h.params.n - 1].val.n); + h.params.p[h.params.n - 1].val.p = (char *)lua_tolstring( + L, -1, &h.params.p[h.params.n - 1].val.n); } else { h.params.p[h.params.n - 1].val.p = 0; h.params.p[h.params.n - 1].val.n = 0; diff --git a/third_party/lua/luapushheader.c b/third_party/lua/luapushheader.c index 58d1e02d0..e72e99307 100644 --- a/third_party/lua/luapushheader.c +++ b/third_party/lua/luapushheader.c @@ -22,7 +22,7 @@ #include "third_party/lua/lauxlib.h" #include "third_party/lua/lua.h" -int LuaPushHeader(lua_State *L, struct HttpMessage *m, char *b, int h) { +int LuaPushHeader(lua_State *L, struct HttpMessage *m, const char *b, int h) { char *val; size_t vallen; if (!kHttpRepeatable[h]) { diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index d2687fa3c..139325c08 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -203,8 +203,8 @@ static dontinline int ReturnString(lua_State *L, const char *x) { } int LuaUnixSysretErrno(lua_State *L, const char *call, int olderr) { + int unixerr, winerr; struct UnixErrno *ep; - int i, unixerr, winerr; unixerr = errno; winerr = IsWindows() ? GetLastError() : 0; if (!IsTiny() && !(0 < unixerr && unixerr < (!IsWindows() ? 4096 : 65536))) { @@ -591,7 +591,7 @@ static int LuaUnixExecve(lua_State *L) { return LuaUnixSysretErrno(L, "execve", olderr); } } else { - ezargs[0] = prog; + ezargs[0] = (char *)prog; ezargs[1] = 0; argv = ezargs; envp = environ; @@ -736,7 +736,7 @@ static int LuaUnixWait(lua_State *L) { // └─→ nil, unix.Errno static int LuaUnixFcntl(lua_State *L) { struct flock lock; - int rc, fd, cmd, olderr = errno; + int fd, cmd, olderr = errno; fd = luaL_checkinteger(L, 1); cmd = luaL_checkinteger(L, 2); if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) { @@ -920,7 +920,6 @@ static int LuaUnixSetresgid(lua_State *L) { // ├─→ 0 // └─→ nil, unix.Errno static int LuaUnixUtimensat(lua_State *L) { - struct timespec ts; int olderr = errno; return SysretInteger( L, "utimensat", olderr, @@ -937,7 +936,6 @@ static int LuaUnixUtimensat(lua_State *L) { // ├─→ 0 // └─→ nil, unix.Errno static int LuaUnixFutimens(lua_State *L) { - struct timespec ts; int olderr = errno; return SysretInteger( L, "futimens", olderr, @@ -953,7 +951,7 @@ static int LuaUnixFutimens(lua_State *L) { // └─→ nil, unix.Errno static int LuaUnixGettime(lua_State *L) { struct timespec ts; - int rc, olderr = errno; + int olderr = errno; if (!clock_gettime(luaL_optinteger(L, 1, CLOCK_REALTIME), &ts)) { lua_pushinteger(L, ts.tv_sec); lua_pushinteger(L, ts.tv_nsec); @@ -1178,14 +1176,14 @@ static bool IsSockoptBool(int l, int x) { x == SO_KEEPALIVE || // x == SO_ACCEPTCONN || // x == SO_DONTROUTE; // - } else if (l = SOL_TCP) { + } else if (l == SOL_TCP) { return x == TCP_NODELAY || // x == TCP_CORK || // x == TCP_QUICKACK || // x == TCP_SAVE_SYN || // x == TCP_FASTOPEN_CONNECT || // x == TCP_DEFER_ACCEPT; // - } else if (l = SOL_IP) { + } else if (l == SOL_IP) { return x == IP_HDRINCL; // } else { return false; @@ -1198,7 +1196,7 @@ static bool IsSockoptInt(int l, int x) { x == SO_RCVBUF || // x == SO_RCVLOWAT || // x == SO_SNDLOWAT; // - } else if (l = SOL_TCP) { + } else if (l == SOL_TCP) { return x == TCP_FASTOPEN || // x == TCP_KEEPCNT || // x == TCP_MAXSEG || // @@ -1207,7 +1205,7 @@ static bool IsSockoptInt(int l, int x) { x == TCP_WINDOW_CLAMP || // x == TCP_KEEPIDLE || // x == TCP_KEEPINTVL; // - } else if (l = SOL_IP) { + } else if (l == SOL_IP) { return x == IP_TOS || // x == IP_MTU || // x == IP_TTL; // @@ -1230,7 +1228,7 @@ static int LuaUnixSetsockopt(lua_State *L) { struct linger l; uint32_t optsize; struct timeval tv; - int rc, fd, level, optname, optint, olderr = errno; + int fd, level, optname, optint, olderr = errno; fd = luaL_checkinteger(L, 1); level = luaL_checkinteger(L, 2); optname = luaL_checkinteger(L, 3); @@ -1281,7 +1279,7 @@ static int LuaUnixGetsockopt(lua_State *L) { uint32_t size; struct linger l; struct timeval tv; - int rc, fd, level, optname, optval, olderr = errno; + int fd, level, optname, optval, olderr = errno; fd = luaL_checkinteger(L, 1); level = luaL_checkinteger(L, 2); optname = luaL_checkinteger(L, 3); @@ -1547,7 +1545,7 @@ static int LuaUnixPoll(lua_State *L) { struct sigset *mask; struct timespec ts, *tsp; struct pollfd *fds, *fds2; - int i, fd, events, olderr = errno; + int i, events, olderr = errno; luaL_checktype(L, 1, LUA_TTABLE); if (!lua_isnoneornil(L, 2)) { ts = timespec_frommillis(luaL_checkinteger(L, 2)); @@ -1633,7 +1631,7 @@ static int LuaUnixRecv(lua_State *L) { size_t got; ssize_t rc; lua_Integer bufsiz; - int fd, flags, pushed, olderr = errno; + int fd, flags, olderr = errno; fd = luaL_checkinteger(L, 1); bufsiz = luaL_optinteger(L, 2, 1500); bufsiz = MIN(bufsiz, 0x7ffff000); @@ -1655,9 +1653,8 @@ static int LuaUnixRecv(lua_State *L) { // ├─→ sent:int // └─→ nil, unix.Errno static int LuaUnixSend(lua_State *L) { - char *data; - ssize_t rc; - size_t sent, size; + size_t size; + const char *data; int fd, flags, olderr = errno; fd = luaL_checkinteger(L, 1); data = luaL_checklstring(L, 2, &size); @@ -1670,9 +1667,9 @@ static int LuaUnixSend(lua_State *L) { // ├─→ sent:int // └─→ nil, unix.Errno static int LuaUnixSendto(lua_State *L) { - char *data; size_t size; uint32_t salen; + const char *data; struct sockaddr_storage ss; int i, fd, flags, olderr = errno; fd = luaL_checkinteger(L, 1); @@ -1697,7 +1694,6 @@ static int LuaUnixShutdown(lua_State *L) { // ├─→ oldmask:unix.Sigset // └─→ nil, unix.Errno static int LuaUnixSigprocmask(lua_State *L) { - uint64_t imask; int olderr = errno; struct sigset oldmask; if (!sigprocmask(luaL_checkinteger(L, 1), @@ -2734,7 +2730,7 @@ static int LuaUnixMemoryWrite(lua_State *L) { if (lua_isnoneornil(L, b)) { // unix.Memory:write(data:str[, offset:int]) // writes binary data, plus a nul terminator - if (i < n < m->size) { + if (i < n && n < m->size) { // include lua string's implicit nul so this round trips with // unix.Memory:read(offset:int) even when we're overwriting a // larger string that was previously inserted @@ -2842,7 +2838,7 @@ static int LuaUnixMemoryXor(lua_State *L) { static int LuaUnixMemoryWait(lua_State *L) { lua_Integer expect; int rc, olderr = errno; - struct timespec ts, now, *deadline; + struct timespec ts, *deadline; expect = luaL_checkinteger(L, 3); if (!(INT32_MIN <= expect && expect <= INT32_MAX)) { luaL_argerror(L, 3, "must be an int32_t"); @@ -3351,7 +3347,8 @@ static const luaL_Reg kLuaUnix[] = { {0}, // }; -static void LoadMagnums(lua_State *L, struct MagnumStr *ms, const char *pfx) { +static void LoadMagnums(lua_State *L, const struct MagnumStr *ms, + const char *pfx) { int i; char b[64], *p; p = stpcpy(b, pfx); diff --git a/third_party/make/getopt.c b/third_party/make/getopt.c index 62d390b08..74838c83a 100644 --- a/third_party/make/getopt.c +++ b/third_party/make/getopt.c @@ -646,7 +646,7 @@ _getopt_internal (int argc, char *const *argv, const char *optstring, optarg = nameend + 1; else { - if (opterr) + if (opterr) { if (argv[optind - 1][1] == '-') /* --option */ fprintf (stderr, @@ -657,7 +657,7 @@ _getopt_internal (int argc, char *const *argv, const char *optstring, fprintf (stderr, _("%s: option '%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); - + } nextchar += strlen (nextchar); optopt = pfound->val; diff --git a/third_party/make/job.c b/third_party/make/job.c index be3a7a25b..f31c64078 100644 --- a/third_party/make/job.c +++ b/third_party/make/job.c @@ -410,18 +410,18 @@ get_target_variable (const char *name, return dflt; } -const char * +char * get_tmpdir (struct file *file) { - return get_target_variable (STRING_SIZE_TUPLE ("TMPDIR"), file, 0); + return strdup (get_target_variable (STRING_SIZE_TUPLE ("TMPDIR"), file, 0)); } char * new_tmpdir (const char *tmp, struct file *file) { + char *tmpdir; const char *s; int c, e, i, j; - char *dir, *tmpdir; char cwd[PATH_MAX]; char path[PATH_MAX]; @@ -1875,9 +1875,9 @@ child_execute_job (struct childbase *child, char outpathbuf[PATH_MAX]; int fdout = FD_STDOUT; int fderr = FD_STDERR; + const char *s; pid_t pid; int e, r; - char *s; /* Divert child output if we want to capture it. */ if (child->output.syncout) @@ -1931,11 +1931,11 @@ child_execute_job (struct childbase *child, if (sandboxed) { - promises = emptytonull (get_target_variable - (STRING_SIZE_TUPLE (".PLEDGE"), - c ? c->file : 0, 0)); - if (promises) - promises = xstrdup (promises); + const char *ps; + ps = emptytonull (get_target_variable + (STRING_SIZE_TUPLE (".PLEDGE"), + c ? c->file : 0, 0)); + promises = ps ? xstrdup (promises) : 0; if (ParsePromises (promises, &ipromises)) { OSS (error, NILF, "%s: invalid .PLEDGE string: %s", @@ -2128,7 +2128,7 @@ child_execute_job (struct childbase *child, DB (DB_JOBS, (_("Blocked Internet access with seccomp ptrace\n"))); else { - if (errno = EPERM) + if (errno == EPERM) { errno = e; DB (DB_JOBS, (_("Can't block Internet if already traced\n"))); @@ -2152,7 +2152,7 @@ child_execute_job (struct childbase *child, if (!strict || !sandboxed) { if ((s = commandv (argv[0], pathbuf, sizeof (pathbuf)))) - argv[0] = s; + argv[0] = (char *)s; else { OSS (error, NILF, "%s: command not found on $PATH: %s", @@ -2255,7 +2255,7 @@ child_execute_job (struct childbase *child, if (!c->file->phony && strlen(c->file->name) < PATH_MAX) { - int fd, rc, err; + int fd, err; if (c->file->last_mtime == NONEXISTENT_MTIME) { strcpy (outpathbuf, c->file->name); @@ -2306,7 +2306,7 @@ child_execute_job (struct childbase *child, RETURN_ON_ERROR (Unveil (d->file->name, "rx")); if (n > 4 && READ32LE(d->file->name + n - 4) == READ32LE(".com")) { - s = xstrcat (d->file->name, ".dbg"); + char *s = xstrcat (d->file->name, ".dbg"); RETURN_ON_ERROR (Unveil (s, "rx")); free (s); } diff --git a/third_party/make/main.c b/third_party/make/main.c index fdd265565..196940f36 100644 --- a/third_party/make/main.c +++ b/third_party/make/main.c @@ -1662,7 +1662,10 @@ main (int argc, char **argv, char **envp) p = quote_for_env (p, eval_strings->list[i]); *(p++) = ' '; } +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wstringop-overflow" /* wut */ p[-1] = '\0'; +#pragma GCC pop_options define_variable_cname ("-*-eval-flags-*-", value, o_automatic, 0); } diff --git a/third_party/make/read.c b/third_party/make/read.c index ba66571e7..b0cb6028c 100644 --- a/third_party/make/read.c +++ b/third_party/make/read.c @@ -431,6 +431,7 @@ eval_makefile (const char *filename, unsigned short flags) /* [jart] breaks gcc11 (also wat) */ void *volatile wat = alloca (0); + (void)wat; errno = 0; return deps; @@ -474,6 +475,7 @@ eval_buffer (char *buffer, const floc *flocp) /* [jart] breaks gcc11 (also wat) */ void *volatile wat = alloca (0); + (void)wat; } /* Check LINE to see if it's a variable assignment or undefine. @@ -1181,7 +1183,7 @@ eval (struct ebuffer *ebuf, int set_default) if (semip) { size_t l = p2 - variable_buffer; - *(--semip) = ';'; + *__veil("r", (--semip)) = ';'; collapse_continuations (semip); variable_buffer_output (p2 + strlen (p2), semip, strlen (semip)+1); diff --git a/third_party/make/remake.c b/third_party/make/remake.c index 026b947af..d8282aa44 100644 --- a/third_party/make/remake.c +++ b/third_party/make/remake.c @@ -324,6 +324,7 @@ update_file (struct file *file, unsigned int depth) /* Clean up any alloca() used during the update. */ void *volatile wat = alloca (0); + (void)wat; /* If we got an error, don't bother with double_colon etc. */ if (new && !keep_going_flag) diff --git a/third_party/mbedtls/aesni.c b/third_party/mbedtls/aesni.c index d7242773b..9695477a1 100644 --- a/third_party/mbedtls/aesni.c +++ b/third_party/mbedtls/aesni.c @@ -130,7 +130,6 @@ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, */ void mbedtls_aesni_gcm_mult( unsigned char a[16], const uint64_t b[2] ) { - size_t i; uint64_t aa _Vector_size(16) forcealign(16); uint64_t bb _Vector_size(16) forcealign(16); diff --git a/third_party/mbedtls/base64.c b/third_party/mbedtls/base64.c index 32255954a..85f7a43f1 100644 --- a/third_party/mbedtls/base64.c +++ b/third_party/mbedtls/base64.c @@ -15,8 +15,8 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/str/str.h" #include "third_party/mbedtls/base64.h" +#include "libc/str/str.h" #include "third_party/mbedtls/common.h" #include "third_party/mbedtls/platform.h" @@ -127,8 +127,8 @@ static inline unsigned char mbedtls_base64_table_lookup( const unsigned char * c int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen ) { + size_t n; unsigned w; - size_t i, n; unsigned char *q; const unsigned char *p, *pe; if( !slen ) { diff --git a/third_party/mbedtls/bigmul.c b/third_party/mbedtls/bigmul.c index 5ce485c8c..56710ecbb 100644 --- a/third_party/mbedtls/bigmul.c +++ b/third_party/mbedtls/bigmul.c @@ -26,7 +26,7 @@ #include "third_party/mbedtls/profile.h" /* clang-format off */ -void Mul(uint64_t *c, uint64_t *A, unsigned n, uint64_t *B, unsigned m) +void Mul(uint64_t *c, const uint64_t *A, unsigned n, const uint64_t *B, unsigned m) { if (!m--) return; mbedtls_platform_zeroize(c, m * ciL); @@ -41,8 +41,8 @@ void Mul(uint64_t *c, uint64_t *A, unsigned n, uint64_t *B, unsigned m) void mbedtls_mpi_mul_hlp1(size_t n, const uint64_t *s, uint64_t *d, uint64_t b) { size_t i; + uint64_t c; uint128_t x; - uint64_t c, t, t1, t2; i = c = 0; #if defined(__x86_64__) && !defined(__STRICT_ANSI__) if( X86_HAVE(BMI2) ) @@ -113,7 +113,7 @@ void mbedtls_mpi_mul_hlp1(size_t n, const uint64_t *s, uint64_t *d, uint64_t b) /** * Computes inner loop of multiplication algorithm. */ -void mbedtls_mpi_mul_hlp(size_t n, uint64_t *s, uint64_t *d, uint64_t b) +void mbedtls_mpi_mul_hlp(size_t n, const uint64_t *s, uint64_t *d, uint64_t b) { size_t i; uint128_t x; @@ -241,9 +241,10 @@ int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) { - int i, j, t, k, ret; + int i, j, t, ret; + mbedtls_mpi TA, TB; mbedtls_mpi_uint *K; - mbedtls_mpi TA, TB, *T; + const mbedtls_mpi *T; MPI_VALIDATE_RET(X); MPI_VALIDATE_RET(A); MPI_VALIDATE_RET(B); diff --git a/third_party/mbedtls/bignum.c b/third_party/mbedtls/bignum.c index 45a37b81f..301b1041c 100644 --- a/third_party/mbedtls/bignum.c +++ b/third_party/mbedtls/bignum.c @@ -438,7 +438,7 @@ cleanup: */ size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ) { - size_t i, j, count = 0; + size_t i, count = 0; MBEDTLS_INTERNAL_VALIDATE_RET(X, 0); for( i = 0; i < X->n; i++ ) { @@ -1279,6 +1279,8 @@ forceinline mbedtls_mpi_uint mpi_sub_hlp(mbedtls_mpi_uint *d, size_t i; unsigned char cf; mbedtls_mpi_uint c, x; + (void)x; + (void)cf; cf = c = i = 0; #if defined(__x86_64__) && !defined(__STRICT_ANSI__) if (!n) return 0; @@ -1679,7 +1681,7 @@ int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B) { int ret = MBEDTLS_ERR_THIS_CORRUPTION; - size_t i, n, t, k, Xn, Yn; + size_t i, n, t, k; mbedtls_mpi X, Y, Z, T1, T2; mbedtls_mpi_uint TP2[3]; MPI_VALIDATE_RET(A); diff --git a/third_party/mbedtls/bignum_internal.h b/third_party/mbedtls/bignum_internal.h index 72f6ee6ac..9c64dc77b 100644 --- a/third_party/mbedtls/bignum_internal.h +++ b/third_party/mbedtls/bignum_internal.h @@ -9,8 +9,8 @@ COSMOPOLITAN_C_START_ #define MPI_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) #define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ -#define biL (ciL << 3) /* bits in limb */ -#define biH (ciL << 2) /* half limb size */ +#define biL (ciL << 3) /* bits in limb */ +#define biH (ciL << 2) /* half limb size */ #define MPI_SIZE_T_MAX ((size_t)-1) /* SIZE_T_MAX is not standard */ @@ -30,9 +30,9 @@ void Mul4x4Adx(uint64_t[8], const uint64_t[4], const uint64_t[4]); void Mul6x6Adx(uint64_t[12], const uint64_t[6], const uint64_t[6]); void Mul8x8Adx(uint64_t[16], const uint64_t[8], const uint64_t[8]); void Mul4x4Pure(uint64_t[16], const uint64_t[8], const uint64_t[8]); -void Mul(uint64_t *, uint64_t *, unsigned, uint64_t *, unsigned); +void Mul(uint64_t *, const uint64_t *, unsigned, const uint64_t *, unsigned); void Karatsuba(uint64_t *, uint64_t *, uint64_t *, size_t, uint64_t *); -void mbedtls_mpi_mul_hlp(size_t, uint64_t *, uint64_t *, uint64_t); +void mbedtls_mpi_mul_hlp(size_t, const uint64_t *, uint64_t *, uint64_t); void mbedtls_mpi_mul_hlp1(size_t, const uint64_t *, uint64_t *, uint64_t); COSMOPOLITAN_C_END_ diff --git a/third_party/mbedtls/bigshift.c b/third_party/mbedtls/bigshift.c index ae7d34fc2..265d93767 100644 --- a/third_party/mbedtls/bigshift.c +++ b/third_party/mbedtls/bigshift.c @@ -70,14 +70,13 @@ static inline void shld(mbedtls_mpi_uint *p, size_t n, size_t m, char k) int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t k) { int r; - size_t b, n, m, l, z; + size_t b, n, m, l; MPI_VALIDATE_RET(X); l = mbedtls_mpi_bitlen(X); b = l + k; n = BITS_TO_LIMBS(b); m = k / biL; k = k % biL; - z = X->n; if (n > X->n && (r = mbedtls_mpi_grow(X, n))) return r; if (k) @@ -102,7 +101,6 @@ void ShiftRightPure(mbedtls_mpi_uint *p, size_t n, unsigned char k) { int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t k) { size_t n; - mbedtls_mpi_uint x, y; MPI_VALIDATE_RET(X); k = MIN(k, X->n * biL); n = k / biL; diff --git a/third_party/mbedtls/ecdh_everest.c b/third_party/mbedtls/ecdh_everest.c index ea270eb34..04b9c1042 100644 --- a/third_party/mbedtls/ecdh_everest.c +++ b/third_party/mbedtls/ecdh_everest.c @@ -15,8 +15,8 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/str/str.h" #include "third_party/mbedtls/ecdh_everest.h" +#include "libc/str/str.h" #include "third_party/mbedtls/everest.h" #if defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) #define KEYSIZE 32 @@ -156,7 +156,6 @@ int mbedtls_everest_get_params(mbedtls_ecdh_context_everest *ctx, mbedtls_everest_ecdh_side side) { size_t olen = 0; - mbedtls_everest_ecdh_side s; switch (side) { case MBEDTLS_EVEREST_ECDH_THEIRS: diff --git a/third_party/mbedtls/ecp.c b/third_party/mbedtls/ecp.c index 4a6f234aa..53aedd803 100644 --- a/third_party/mbedtls/ecp.c +++ b/third_party/mbedtls/ecp.c @@ -15,6 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/mbedtls/ecp.h" #include "libc/intrin/strace.internal.h" #include "libc/log/check.h" #include "libc/log/log.h" @@ -26,7 +27,6 @@ #include "third_party/mbedtls/common.h" #include "third_party/mbedtls/config.h" #include "third_party/mbedtls/ctr_drbg.h" -#include "third_party/mbedtls/ecp.h" #include "third_party/mbedtls/ecp_internal.h" #include "third_party/mbedtls/error.h" #include "third_party/mbedtls/hmac_drbg.h" @@ -1737,9 +1737,9 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, /* * Trivial cases: P == 0 or Q == 0 (case 1) */ - if( mbedtls_ecp_is_zero( P ) ) + if( mbedtls_ecp_is_zero( (void *)P ) ) return( mbedtls_ecp_copy( R, Q ) ); - if( Q->Z.p && mbedtls_ecp_is_zero( Q ) ) + if( Q->Z.p && mbedtls_ecp_is_zero( (void *)Q ) ) return( mbedtls_ecp_copy( R, P ) ); /* * Make sure Q coordinates are normalized diff --git a/third_party/mbedtls/ecp256.c b/third_party/mbedtls/ecp256.c index f26047134..0fc8dc8be 100644 --- a/third_party/mbedtls/ecp256.c +++ b/third_party/mbedtls/ecp256.c @@ -38,7 +38,7 @@ static bool mbedtls_p256_gte( uint64_t p[5] ) { return( (((int64_t)p[4] > 0) | - (!p[4] & + ((!p[4]) & ((p[3] > 0xffffffff00000001) | ((p[3] == 0xffffffff00000001) & ((p[2] > 0x0000000000000000) | diff --git a/third_party/mbedtls/ecp384.c b/third_party/mbedtls/ecp384.c index fe103408e..b9002fd5a 100644 --- a/third_party/mbedtls/ecp384.c +++ b/third_party/mbedtls/ecp384.c @@ -39,7 +39,7 @@ static bool mbedtls_p384_gte( uint64_t p[7] ) { return( (((int64_t)p[6] > 0) | - (!p[6] & + ((!p[6]) & ((p[5] > 0xffffffffffffffff) | ((p[5] == 0xffffffffffffffff) & ((p[4] > 0xffffffffffffffff) | @@ -189,13 +189,11 @@ mbedtls_p384_mul( uint64_t X[12], void *f = 0; if( A == X ) { - A = memcpy( malloc( 6 * 8 ), A, 6 * 8 ); - f = A; + A = f = memcpy( malloc( 6 * 8 ), A, 6 * 8 ); } else if( B == X ) { - B = memcpy( malloc( 6 * 8 ), B, 6 * 8 ); - f = B; + B = f = memcpy( malloc( 6 * 8 ), B, 6 * 8 ); } Mul( X, A, n, B, m ); mbedtls_platform_zeroize( X + n + m, (12 - n - m) * 8 ); @@ -417,7 +415,7 @@ int mbedtls_p384_double_jac( const mbedtls_ecp_group *G, if( IsAsan() ) __asan_verify( P, sizeof( *P ) ); if( IsAsan() ) __asan_verify( R, sizeof( *R ) ); if( ( ret = mbedtls_p384_dim( R ) ) ) return( ret ); - if( ( ret = mbedtls_p384_dim( P ) ) ) return( ret ); + if( ( ret = mbedtls_p384_dim( (void *)P ) ) ) return( ret ); mbedtls_platform_zeroize( T, sizeof( T ) ); mbedtls_p384_mul( T[1], P->Z.p, 6, P->Z.p, 6 ); mbedtls_p384_add( T[2], P->X.p, T[1] ); diff --git a/third_party/mbedtls/ecpshl.c b/third_party/mbedtls/ecpshl.c index 6f0d5fb17..b84a1cd40 100644 --- a/third_party/mbedtls/ecpshl.c +++ b/third_party/mbedtls/ecpshl.c @@ -33,10 +33,10 @@ static void mbedtls_mpi_shift_l_mod_p256( const mbedtls_ecp_group *G, X->p[0] = X->p[0] << 1; if( (X->p[4] || X->p[3] > G->P.p[3] || - (X->p[3] == G->P.p[3] && - X->p[2] > G->P.p[2] || - (X->p[2] == G->P.p[2] && - X->p[0] > G->P.p[0] || + ((X->p[3] == G->P.p[3] && + X->p[2] > G->P.p[2]) || + ((X->p[2] == G->P.p[2] && + X->p[0] > G->P.p[0]) || (X->p[0] == G->P.p[0])))) ) { SBB(X->p[0], X->p[0], G->P.p[0], 0, c); @@ -63,14 +63,14 @@ static void mbedtls_mpi_shift_l_mod_p384( const mbedtls_ecp_group *G, X->p[0] = X->p[0] << 1; if( (X->p[6] || X->p[5] > G->P.p[5] || - (X->p[5] == G->P.p[5] && - X->p[4] > G->P.p[4] || - (X->p[4] == G->P.p[4] && - X->p[3] > G->P.p[3] || - (X->p[3] == G->P.p[3] && - X->p[2] > G->P.p[2] || - (X->p[2] == G->P.p[2] && - X->p[0] > G->P.p[0] || + ((X->p[5] == G->P.p[5] && + X->p[4] > G->P.p[4]) || + ((X->p[4] == G->P.p[4] && + X->p[3] > G->P.p[3]) || + ((X->p[3] == G->P.p[3] && + X->p[2] > G->P.p[2]) || + ((X->p[2] == G->P.p[2] && + X->p[0] > G->P.p[0]) || (X->p[0] == G->P.p[0])))))) ) { SBB(X->p[0], X->p[0], G->P.p[0], 0, c); diff --git a/third_party/mbedtls/everest.c b/third_party/mbedtls/everest.c index 764681b31..17bb15e03 100644 --- a/third_party/mbedtls/everest.c +++ b/third_party/mbedtls/everest.c @@ -171,7 +171,7 @@ static void HaclEcPointSwap(uint64_t a[2][5], uint64_t b[2][5], uint64_t m) { } } -static void HaclEcFormatFexpand(uint64_t o[5], uint8_t p[32]) { +static void HaclEcFormatFexpand(uint64_t o[5], const uint8_t p[32]) { o[0] = READ64LE(p + 000) >> 00 & 0x7ffffffffffff; o[1] = READ64LE(p + 006) >> 03 & 0x7ffffffffffff; o[2] = READ64LE(p + 014) >> 06 & 0x7ffffffffffff; diff --git a/third_party/mbedtls/gcm.c b/third_party/mbedtls/gcm.c index b16aeb153..243ac6cd3 100644 --- a/third_party/mbedtls/gcm.c +++ b/third_party/mbedtls/gcm.c @@ -15,6 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/mbedtls/gcm.h" #include "libc/intrin/bits.h" #include "libc/intrin/likely.h" #include "libc/log/log.h" @@ -27,7 +28,6 @@ #include "third_party/mbedtls/common.h" #include "third_party/mbedtls/endian.h" #include "third_party/mbedtls/error.h" -#include "third_party/mbedtls/gcm.h" #include "third_party/mbedtls/platform.h" asm(".ident\t\"\\n\\n\ @@ -102,7 +102,6 @@ void mbedtls_gcm_init( mbedtls_gcm_context *ctx ) static int gcm_gen_table( mbedtls_gcm_context *ctx ) { int ret, i, j; - uint64_t hi, lo; uint64_t vl, vh; unsigned char h[16]; size_t olen = 0; diff --git a/third_party/mbedtls/karatsuba.c b/third_party/mbedtls/karatsuba.c index ae4bfd85a..7b6e00a56 100644 --- a/third_party/mbedtls/karatsuba.c +++ b/third_party/mbedtls/karatsuba.c @@ -24,7 +24,6 @@ #include "third_party/mbedtls/platform.h" forceinline int Cmp(uint64_t *a, uint64_t *b, size_t n) { - size_t i; uint64_t x, y; while (n--) { x = a[n]; @@ -38,8 +37,9 @@ forceinline int Cmp(uint64_t *a, uint64_t *b, size_t n) { forceinline bool Sub(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { bool cf; - uint64_t c, i; + uint64_t i; #ifdef __x86_64__ + uint64_t c; asm volatile("xor\t%1,%1\n\t" ".align\t16\n1:\t" "mov\t(%5,%3,8),%1\n\t" @@ -52,7 +52,7 @@ forceinline bool Sub(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { : "r"(C), "r"(A), "r"(B), "3"(0) : "cc", "memory"); #else - for (cf = false, c = i = 0; i < n; ++i) { + for (cf = false, i = 0; i < n; ++i) { SBB(C[i], A[i], B[i], cf, cf); } #endif @@ -61,8 +61,9 @@ forceinline bool Sub(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { forceinline bool Add(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { bool cf; - uint64_t c, i; + uint64_t i; #ifdef __x86_64__ + uint64_t c; asm volatile("xor\t%1,%1\n\t" ".align\t16\n1:\t" "mov\t(%5,%3,8),%1\n\t" @@ -75,7 +76,7 @@ forceinline bool Add(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { : "r"(C), "r"(A), "r"(B), "3"(0) : "cc", "memory"); #else - for (cf = false, c = i = 0; i < n; ++i) { + for (cf = false, i = 0; i < n; ++i) { ADC(C[i], A[i], B[i], cf, cf); } #endif @@ -89,10 +90,8 @@ forceinline bool Add(uint64_t *C, uint64_t *A, uint64_t *B, size_t n) { * For 16384 bit numbers it's thrice as fast. */ void Karatsuba(uint64_t *C, uint64_t *A, uint64_t *B, size_t n, uint64_t *K) { - int q, r; size_t i; uint64_t c, t; - uint64_t *x, *y; if (n == 8) { #ifdef __x86_64__ if (X86_HAVE(BMI2) && X86_HAVE(ADX)) { diff --git a/third_party/mbedtls/san.c b/third_party/mbedtls/san.c index 11b8dc0e9..e5530498e 100644 --- a/third_party/mbedtls/san.c +++ b/third_party/mbedtls/san.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/mbedtls/san.h" #include "libc/intrin/bits.h" #include "libc/sock/sock.h" #include "libc/sysv/consts/af.h" @@ -23,7 +24,6 @@ #include "third_party/mbedtls/asn1write.h" #include "third_party/mbedtls/oid.h" #include "third_party/mbedtls/platform.h" -#include "third_party/mbedtls/san.h" #include "third_party/mbedtls/x509_crt.h" /** @@ -33,9 +33,10 @@ */ int mbedtls_x509write_crt_set_subject_alternative_name( mbedtls_x509write_cert *ctx, const struct mbedtls_san *san, size_t sanlen) { - int ret, a, b, c; + int ret; + const unsigned char *item; size_t i, len, cap, itemlen; - unsigned char *pc, *buf, *item, ip4[4]; + unsigned char *pc, *buf, ip4[4]; if (!sanlen) return 0; cap = sanlen * (253 + 5 + 1) + 5 + 1; if (!(buf = mbedtls_calloc(1, cap))) return MBEDTLS_ERR_ASN1_ALLOC_FAILED; diff --git a/third_party/mbedtls/secp256r1.c b/third_party/mbedtls/secp256r1.c index 7df7f9ac8..0b020308b 100644 --- a/third_party/mbedtls/secp256r1.c +++ b/third_party/mbedtls/secp256r1.c @@ -43,16 +43,18 @@ * @see FIPS 186-3 §D.2.3 */ void secp256r1(uint64_t p[8]) { - int r; char o; signed char E; - uint64_t A, B, C, D, a, b, c, d, e; + uint64_t A, B, C, D, b, c, d; A = Q(0); B = Q(2); C = Q(4); D = Q(6); E = 0; #if !defined(__x86_64__) || defined(__STRICT_ANSI__) + (void)b; + (void)c; + (void)d; ADC(B, B, H(Q(10)) << 1, 0, o); ADC(C, C, Q(12) << 1 | Q(10) >> 63, o, o); ADC(D, D, Q(14) << 1 | Q(12) >> 63, o, o); @@ -92,6 +94,7 @@ void secp256r1(uint64_t p[8]) { SBB(D, D, H(Q(12)), o, o); E -= o; #else + (void)o; asm volatile(/* x += 2 × ( A₁₅ ‖ A₁₄ ‖ A₁₃ ‖ A₁₂ ‖ A₁₁ ‖ 0 ‖ 0 ‖ 0 ) */ "mov\t11*4(%8),%k5\n\t" "mov\t12*4(%8),%6\n\t" diff --git a/third_party/mbedtls/secp384r1.c b/third_party/mbedtls/secp384r1.c index c1418eb0d..da2728e0b 100644 --- a/third_party/mbedtls/secp384r1.c +++ b/third_party/mbedtls/secp384r1.c @@ -112,6 +112,7 @@ void secp384r1(uint64_t p[12]) { SBB(F, F, 0, o, o); G -= o; #else + (void)o; asm volatile(/* S₁ = (0 ‖0 ‖0 ‖0 ‖0 ‖A₂₃‖A₂₂‖A₂₁‖0 ‖0 ‖0 ‖0 ) */ "mov\t21*4(%9),%7\n\t" "mov\t23*4(%9),%k8\n\t" diff --git a/third_party/mbedtls/sha1.c b/third_party/mbedtls/sha1.c index aaeb23bac..5a18b6dc2 100644 --- a/third_party/mbedtls/sha1.c +++ b/third_party/mbedtls/sha1.c @@ -380,8 +380,8 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, size_t ilen ) { int ret = MBEDTLS_ERR_THIS_CORRUPTION; + size_t fill; uint32_t left; - size_t n, fill; SHA1_VALIDATE_RET( ctx != NULL ); SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); diff --git a/third_party/mbedtls/shiftright-avx.c b/third_party/mbedtls/shiftright-avx.c index 03adb2c62..cca8f49fd 100644 --- a/third_party/mbedtls/shiftright-avx.c +++ b/third_party/mbedtls/shiftright-avx.c @@ -25,9 +25,9 @@ typedef uint64_t xmm_t __attribute__((__vector_size__(16), __aligned__(1))); void ShiftRightAvx(uint64_t *p, size_t n, unsigned char k) { uint64_t p1; + xmm_t o0, o1; + xmm_t i0, i1; xmm_t cv = {0}; - xmm_t i0, i1, i2, i3; - xmm_t o0, o1, o2, o3; MBEDTLS_ASSERT(!(k & ~63)); p1 = n > 1 ? p[1] : 0; while (n >= 4) { diff --git a/third_party/mbedtls/ssl_msg.c b/third_party/mbedtls/ssl_msg.c index 6aaa1e991..c4fd86575 100644 --- a/third_party/mbedtls/ssl_msg.c +++ b/third_party/mbedtls/ssl_msg.c @@ -1253,8 +1253,6 @@ MBEDTLS_STATIC_TESTABLE int mbedtls_ssl_cf_hmac( const unsigned char * const okey = ikey + block_size; const size_t hash_size = mbedtls_md_get_size( ctx->md_info ); - unsigned char aux_out[MBEDTLS_MD_MAX_SIZE]; - size_t offset; int ret = MBEDTLS_ERR_THIS_CORRUPTION; #define MD_CHK( func_call ) \ diff --git a/third_party/mbedtls/ssl_tls.c b/third_party/mbedtls/ssl_tls.c index 038ff43cd..20c615fc6 100644 --- a/third_party/mbedtls/ssl_tls.c +++ b/third_party/mbedtls/ssl_tls.c @@ -2808,7 +2808,7 @@ static void ssl_calc_finished_tls_sha384( { int len = 12; const char *sender; - unsigned char padbuf[48]; + unsigned char padbuf[64]; mbedtls_sha512_context sha512; mbedtls_ssl_session *session = ssl->session_negotiate; if( !session ) diff --git a/third_party/mbedtls/test/lib.c b/third_party/mbedtls/test/lib.c index fcaeaa6ed..205aa7cbc 100644 --- a/third_party/mbedtls/test/lib.c +++ b/third_party/mbedtls/test/lib.c @@ -78,7 +78,6 @@ int option_verbose = 1; mbedtls_test_info_t mbedtls_test_info; int mbedtls_test_platform_setup(void) { - char *p; int ret = 0; static char mybuf[2][BUFSIZ]; ShowCrashReports(); @@ -132,8 +131,7 @@ int mbedtls_hardware_poll(void *wut, unsigned char *p, size_t n, size_t *olen) { } int mbedtls_test_write(const char *fmt, ...) { - int i, n; - char *p; + int n; va_list va; va_start(va, fmt); if (option_verbose) { diff --git a/third_party/mbedtls/test/secp384r1_test.c b/third_party/mbedtls/test/secp384r1_test.c index 6981959e4..e3090a00e 100644 --- a/third_party/mbedtls/test/secp384r1_test.c +++ b/third_party/mbedtls/test/secp384r1_test.c @@ -59,14 +59,6 @@ TEST(secp384r1, testIsTheSame) { TEST(secp384r1, needsDownwardCorrection) { int i; - uint64_t P[6] = { - 0x00000000ffffffff, // - 0xffffffff00000000, // - 0xfffffffffffffffe, // - 0xffffffffffffffff, // - 0xffffffffffffffff, // - 0xffffffffffffffff, // - }; uint64_t X[12] = { 0xffffffffffffffff, // 0xffffffffffffffff, // diff --git a/third_party/mbedtls/test/test_suite_aes.cbc.c b/third_party/mbedtls/test/test_suite_aes.cbc.c index f1c5b3bb5..495687c4f 100644 --- a/third_party/mbedtls/test/test_suite_aes.cbc.c +++ b/third_party/mbedtls/test/test_suite_aes.cbc.c @@ -512,6 +512,8 @@ void test_aes_check_params( ) const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + (void)size; + TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); diff --git a/third_party/mbedtls/test/test_suite_aes.cfb.c b/third_party/mbedtls/test/test_suite_aes.cfb.c index 05ee461cb..ddb652486 100644 --- a/third_party/mbedtls/test/test_suite_aes.cfb.c +++ b/third_party/mbedtls/test/test_suite_aes.cfb.c @@ -502,6 +502,8 @@ void test_aes_check_params( ) const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + (void)size; + TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); diff --git a/third_party/mbedtls/test/test_suite_aes.ecb.c b/third_party/mbedtls/test/test_suite_aes.ecb.c index 616a6aa51..169ff45cb 100644 --- a/third_party/mbedtls/test/test_suite_aes.ecb.c +++ b/third_party/mbedtls/test/test_suite_aes.ecb.c @@ -501,6 +501,8 @@ void test_aes_check_params( ) size_t size; const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + + (void)size; TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) diff --git a/third_party/mbedtls/test/test_suite_aes.ofb.c b/third_party/mbedtls/test/test_suite_aes.ofb.c index 73c138f93..dc4f20708 100644 --- a/third_party/mbedtls/test/test_suite_aes.ofb.c +++ b/third_party/mbedtls/test/test_suite_aes.ofb.c @@ -502,6 +502,8 @@ void test_aes_check_params( ) const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + (void)size; + TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); diff --git a/third_party/mbedtls/test/test_suite_aes.rest.c b/third_party/mbedtls/test/test_suite_aes.rest.c index f1b745644..efd90b72a 100644 --- a/third_party/mbedtls/test/test_suite_aes.rest.c +++ b/third_party/mbedtls/test/test_suite_aes.rest.c @@ -502,6 +502,8 @@ void test_aes_check_params( ) const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + (void)size; + TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); diff --git a/third_party/mbedtls/test/test_suite_aes.xts.c b/third_party/mbedtls/test/test_suite_aes.xts.c index 646b25138..537e1578a 100644 --- a/third_party/mbedtls/test/test_suite_aes.xts.c +++ b/third_party/mbedtls/test/test_suite_aes.xts.c @@ -502,6 +502,8 @@ void test_aes_check_params( ) const int valid_mode = MBEDTLS_AES_ENCRYPT; const int invalid_mode = 42; + (void)size; + TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) ); #if defined(MBEDTLS_CIPHER_MODE_XTS) TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) ); diff --git a/third_party/musl/glob.c b/third_party/musl/glob.c index eaf30665c..ffec4678e 100644 --- a/third_party/musl/glob.c +++ b/third_party/musl/glob.c @@ -25,17 +25,17 @@ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/alg.h" +#include "third_party/musl/glob.h" #include "libc/calls/calls.h" #include "libc/calls/struct/dirent.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" +#include "libc/mem/alg.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "libc/sysv/consts/dt.h" #include "libc/sysv/consts/s.h" #include "third_party/musl/fnmatch.h" -#include "third_party/musl/glob.h" #define MAXPATH 1024 @@ -186,7 +186,7 @@ static int PerformGlob(char *buf, size_t pos, int type, char *pat, int flags, /* With GLOB_PERIOD don't allow matching . or .. unless fnmatch() * would match them with FNM_PERIOD rules in effect. */ if (p2 && (flags & GLOB_PERIOD) && de->d_name[0] == '.' && - (!de->d_name[1] || de->d_name[1] == '.' && !de->d_name[2]) && + (!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2])) && fnmatch(pat, de->d_name, fnm_flags | FNM_PERIOD)) { continue; } @@ -247,7 +247,7 @@ int glob(const char *pat, int flags, int errfunc(const char *path, int err), glob_t *g) { int error = 0; size_t cnt, i; - char *p, **pathv, buf[MAXPATH]; + char **pathv, buf[MAXPATH]; struct GlobList head = {.next = NULL}, *tail = &head; size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; if (!errfunc) errfunc = IgnoreGlobError; diff --git a/third_party/musl/rand48.c b/third_party/musl/rand48.c index b7dfa3aa3..61250d36f 100644 --- a/third_party/musl/rand48.c +++ b/third_party/musl/rand48.c @@ -39,8 +39,8 @@ static unsigned short __seed48[7] = { 0, 0, 0, 0xe66d, 0xdeec, 0x5, 0xb }; static uint64_t __rand48_step(unsigned short *xi, unsigned short *lc) { uint64_t a, x; - x = xi[0] | xi[1]+0U<<16 | xi[2]+0ULL<<32; - a = lc[0] | lc[1]+0U<<16 | lc[2]+0ULL<<32; + x = xi[0] | (xi[1]+0U)<<16 | (xi[2]+0ULL)<<32; + a = lc[0] | (lc[1]+0U)<<16 | (lc[2]+0ULL)<<32; x = a*x + lc[3]; xi[0] = x; xi[1] = x>>16; diff --git a/third_party/musl/tempnam.c b/third_party/musl/tempnam.c index 122cc34be..c2f95c9b7 100644 --- a/third_party/musl/tempnam.c +++ b/third_party/musl/tempnam.c @@ -25,6 +25,7 @@ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/musl/tempnam.h" #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/calls/struct/timespec.h" @@ -35,7 +36,6 @@ #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/clock.h" #include "libc/time/time.h" -#include "third_party/musl/tempnam.h" #define MAXTRIES 100 @@ -52,7 +52,7 @@ __randname(char *template) struct timespec ts; unsigned long r; clock_gettime(CLOCK_REALTIME, &ts); - r = ts.tv_nsec * 65537 ^ (uintptr_t)&ts / 16 + (uintptr_t) template; + r = ts.tv_nsec * 65537 ^ ((uintptr_t)&ts / 16 + (uintptr_t) template); for (i = 0; i < 6; i++, r >>= 5) template[i] = 'A' + (r & 15) + (r & 16) * 2; return template; } diff --git a/third_party/nsync/futex.c b/third_party/nsync/futex.c index ac0b2da9a..797bb3a5c 100644 --- a/third_party/nsync/futex.c +++ b/third_party/nsync/futex.c @@ -163,9 +163,8 @@ static int nsync_futex_polyfill_ (atomic_int *w, int expect, struct timespec *ab return -ETIMEDOUT; } -static int nsync_futex_wait_win32_ (atomic_int *w, int expect, char pshare, struct timespec *timeout) { +static int nsync_futex_wait_win32_ (atomic_int *w, int expect, char pshare, const struct timespec *timeout) { int rc; - uint32_t ms; struct timespec deadline, interval, remain, wait, now; if (timeout) { @@ -211,8 +210,8 @@ static struct timespec *nsync_futex_timeout_ (struct timespec *memory, } } -int nsync_futex_wait_ (atomic_int *w, int expect, char pshare, struct timespec *abstime) { - int e, rc, op, fop; +int nsync_futex_wait_ (atomic_int *w, int expect, char pshare, const struct timespec *abstime) { + int e, rc, op; struct PosixThread *pt = 0; struct timespec tsmem, *timeout; @@ -298,7 +297,7 @@ Finished: } int nsync_futex_wake_ (atomic_int *w, int count, char pshare) { - int e, rc, op, fop; + int rc, op, fop; ASSERT (count == 1 || count == INT_MAX); diff --git a/third_party/nsync/futex.internal.h b/third_party/nsync/futex.internal.h index ead218947..9ae2ad9da 100644 --- a/third_party/nsync/futex.internal.h +++ b/third_party/nsync/futex.internal.h @@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_ int nsync_futex_wake_(_Atomic(int) *, int, char); -int nsync_futex_wait_(_Atomic(int) *, int, char, struct timespec *); +int nsync_futex_wait_(_Atomic(int) *, int, char, const struct timespec *); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/third_party/nsync/mu_semaphore_futex.c b/third_party/nsync/mu_semaphore_futex.c index eb219291e..ef8017c47 100644 --- a/third_party/nsync/mu_semaphore_futex.c +++ b/third_party/nsync/mu_semaphore_futex.c @@ -52,7 +52,7 @@ void nsync_mu_semaphore_init_futex (nsync_semaphore *s) { /* Wait until the count of *s exceeds 0, and decrement it. */ errno_t nsync_mu_semaphore_p_futex (nsync_semaphore *s) { struct futex *f = (struct futex *) s; - int e, i; + int i; errno_t result = 0; do { i = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i); @@ -79,7 +79,7 @@ errno_t nsync_mu_semaphore_p_futex (nsync_semaphore *s) { or abs_deadline expires, in which case return ETIMEDOUT. */ errno_t nsync_mu_semaphore_p_with_deadline_futex (nsync_semaphore *s, nsync_time abs_deadline) { struct futex *f = (struct futex *)s; - int e, i; + int i; int result = 0; do { i = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i); diff --git a/third_party/nsync/mu_semaphore_gcd.c b/third_party/nsync/mu_semaphore_gcd.c index 364b0682d..5781a5e10 100644 --- a/third_party/nsync/mu_semaphore_gcd.c +++ b/third_party/nsync/mu_semaphore_gcd.c @@ -50,6 +50,7 @@ static long dispatch_semaphore_wait (dispatch_semaphore_t ds, static long dispatch_semaphore_signal (dispatch_semaphore_t ds) { long rc = __syslib->dispatch_semaphore_signal (ds); + (void)rc; STRACE ("dispatch_semaphore_signal(%#lx) → %ld", ds, rc); return (ds); } diff --git a/third_party/python/Include/datetime.h b/third_party/python/Include/datetime.h index d1f11b34a..58bcc73dc 100644 --- a/third_party/python/Include/datetime.h +++ b/third_party/python/Include/datetime.h @@ -4,6 +4,7 @@ #include "third_party/python/Include/object.h" COSMOPOLITAN_C_START_ /* clang-format off */ +#pragma GCC diagnostic ignored "-Wunused-variable" /* Fields are packed into successive bytes, each viewed as unsigned and * big-endian, unless otherwise noted: diff --git a/third_party/python/Modules/_decimal/docstrings.h b/third_party/python/Modules/_decimal/docstrings.h index a035db6a5..ace5902c0 100644 --- a/third_party/python/Modules/_decimal/docstrings.h +++ b/third_party/python/Modules/_decimal/docstrings.h @@ -4,6 +4,8 @@ #include "third_party/python/Include/pymacro.h" +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wunused-variable" /******************************************************************************/ /* Module */ @@ -871,6 +873,7 @@ PyDoc_STRVAR(doc_ctx_to_sci_string, Convert a number to a string using scientific notation.\n\ \n"); +#pragma GCC pop_options #endif /* DOCSTRINGS_H */ diff --git a/third_party/python/Modules/_hashmbedtls.c b/third_party/python/Modules/_hashmbedtls.c index 913b38da6..c30a67eab 100644 --- a/third_party/python/Modules/_hashmbedtls.c +++ b/third_party/python/Modules/_hashmbedtls.c @@ -54,10 +54,10 @@ PYTHON_PROVIDE("_hashlib.mbedtls_sha512"); struct Hasher { PyObject_HEAD - PyObject *name; + const PyObject *name; mbedtls_md_context_t ctx; #ifdef WITH_THREAD - PyThread_type_lock lock; + PyThread_type_lock lock; #endif }; @@ -81,7 +81,7 @@ SetMbedtlsError(PyObject *exc, int rc) } static struct Hasher * -hasher_new(PyObject *name) +hasher_new(const PyObject *name) { struct Hasher *self; if ((self = PyObject_New(struct Hasher, &hasher_type))) { @@ -304,7 +304,7 @@ static PyTypeObject hasher_type = { }; static PyObject * -NewHasher(PyObject *name_obj, +NewHasher(const PyObject *name_obj, const mbedtls_md_info_t *digest, void *p, Py_ssize_t n) { @@ -482,7 +482,7 @@ GenerateHashNameList(void) { int i; char *s; - uint8_t *p; + const uint8_t *p; PyObject *set, *name; if ((set = PyFrozenSet_New(0))) { for (p = mbedtls_md_list(); *p != MBEDTLS_MD_NONE; ++p) { diff --git a/third_party/python/Modules/_testcapimodule.c b/third_party/python/Modules/_testcapimodule.c index d83bf9feb..1e14beb61 100644 --- a/third_party/python/Modules/_testcapimodule.c +++ b/third_party/python/Modules/_testcapimodule.c @@ -4305,6 +4305,7 @@ tracemalloc_track(PyObject *self, PyObject *args) Py_ssize_t size; int release_gil = 0; int res; + (void)ptr; if (!PyArg_ParseTuple(args, "IOn|i", &domain, &ptr_obj, &size, &release_gil)) return NULL; @@ -4336,6 +4337,7 @@ tracemalloc_untrack(PyObject *self, PyObject *args) PyObject *ptr_obj; void *ptr; int res; + (void)ptr; if (!PyArg_ParseTuple(args, "IO", &domain, &ptr_obj)) return NULL; @@ -4358,6 +4360,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args) unsigned int domain; PyObject *ptr_obj; void *ptr; + (void)ptr; if (!PyArg_ParseTuple(args, "IO", &domain, &ptr_obj)) return NULL; diff --git a/third_party/python/Modules/cjkcodecs/cjkcodecs.h b/third_party/python/Modules/cjkcodecs/cjkcodecs.h index fd2322ac5..d0a3f6ae3 100644 --- a/third_party/python/Modules/cjkcodecs/cjkcodecs.h +++ b/third_party/python/Modules/cjkcodecs/cjkcodecs.h @@ -244,10 +244,13 @@ getcodec(PyObject *self, PyObject *encoding) return r; } +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wunused-variable" static struct PyMethodDef __methods[] = { {"getcodec", (PyCFunction)getcodec, METH_O, ""}, {0}, }; +#pragma GCC pop_options #ifdef USING_BINARY_PAIR_SEARCH static DBCHAR diff --git a/third_party/python/Modules/main.c b/third_party/python/Modules/main.c index 85a3a80c3..2ed2a3091 100644 --- a/third_party/python/Modules/main.c +++ b/third_party/python/Modules/main.c @@ -405,6 +405,8 @@ Py_Main(int argc, wchar_t **argv) PyObject *warning_option = NULL; PyObject *warning_options = NULL; + (void)opt; + cf.cf_flags = 0; orig_argc = argc; /* For Py_GetArgcArgv() */ diff --git a/third_party/python/Modules/socketmodule.c b/third_party/python/Modules/socketmodule.c index 4f153f0d4..e83ab15ef 100644 --- a/third_party/python/Modules/socketmodule.c +++ b/third_party/python/Modules/socketmodule.c @@ -687,7 +687,6 @@ internal_setblocking(PySocketSockObject *s, int block) #endif #if !defined(MS_WINDOWS) \ && !((defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO))) - int delay_flag, new_delay_flag; #endif #ifdef SOCK_NONBLOCK if (block) @@ -5655,7 +5654,7 @@ socket_inet_aton(PyObject *self, PyObject *args) #ifdef HAVE_INET_ATON #ifdef USE_INET_ATON_WEAKLINK - if (inet_aton != NULL) { + if (__veil("r", inet_aton) != NULL) { #endif if (inet_aton(ip_addr, &buf)) return PyBytes_FromStringAndSize((char *)(&buf), diff --git a/third_party/python/Modules/timemodule.c b/third_party/python/Modules/timemodule.c index 13b00b15c..dc139310d 100644 --- a/third_party/python/Modules/timemodule.c +++ b/third_party/python/Modules/timemodule.c @@ -1520,7 +1520,6 @@ pysleep(_PyTime_t secs) { _PyTime_t deadline, monotonic; #ifndef MS_WINDOWS - struct timeval timeout; struct timespec timeout2; int err = 0; #else diff --git a/third_party/python/Modules/tlsmodule.c b/third_party/python/Modules/tlsmodule.c index 33717f3fe..81a9fe935 100644 --- a/third_party/python/Modules/tlsmodule.c +++ b/third_party/python/Modules/tlsmodule.c @@ -285,7 +285,6 @@ tls_recv_into(struct Tls *self, PyObject *args) { LOG("TLS.recv_into\n"); int rc; - Py_ssize_t n; PyObject *res; Py_buffer buf; if (!PyArg_ParseTuple(args, "w*:recv_into", &buf)) return 0; @@ -458,7 +457,7 @@ Creates TLS client."); static PyObject * newclient(PyObject *self, PyObject *args) { - int rc, fd; + int fd; PyObject *todo; struct Tls *tls; const char *host; @@ -483,7 +482,7 @@ static struct PyModuleDef mbedtls_module = { PyMODINIT_FUNC PyInit_tls(void) { - PyObject *m, *mbedtls_md_meth_names; + PyObject *m; Py_TYPE(&tls_type) = &PyType_Type; if (PyType_Ready(&tls_type) < 0) return 0; if (!(m = PyModule_Create(&mbedtls_module))) return 0; diff --git a/third_party/python/Modules/unicodedata_getcode.c b/third_party/python/Modules/unicodedata_getcode.c index d5ab2c74d..187de8ee7 100644 --- a/third_party/python/Modules/unicodedata_getcode.c +++ b/third_party/python/Modules/unicodedata_getcode.c @@ -270,7 +270,7 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen, /* copy word string from lexicon. the last character in the word has bit 7 set. the last word in a string ends with 0x80 */ - w = (_PyUnicode_Lexicon + + w = (void *)(_PyUnicode_Lexicon + BitFieldExtract(_PyUnicode_LexiconOffset, word, _PyUnicode_LexiconOffsetBits)); while (*w < 128) { diff --git a/third_party/python/Objects/descrobject.c b/third_party/python/Objects/descrobject.c index 64c386d2f..2edbb6664 100644 --- a/third_party/python/Objects/descrobject.c +++ b/third_party/python/Objects/descrobject.c @@ -4,10 +4,10 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/ceval.h" -#include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -297,7 +297,8 @@ _PyMethodDescr_FastCallKeywords(PyObject *descrobj, } result = _PyMethodDef_RawFastCallKeywords(descr->d_method, self, - args+1, nargs-1, kwnames); + (void *)(args+1), nargs-1, + kwnames); result = _Py_CheckFunctionResult((PyObject *)descr, result, NULL); return result; } diff --git a/third_party/python/Objects/object.c b/third_party/python/Objects/object.c index 78c025688..e89fcf21e 100644 --- a/third_party/python/Objects/object.c +++ b/third_party/python/Objects/object.c @@ -464,6 +464,7 @@ int _PyObject_IsFreed(PyObject *op) { uintptr_t ptr = (uintptr_t)op; + (void)ptr; if (_PyMem_IsFreed(&ptr, sizeof(ptr))) { return 1; } diff --git a/third_party/python/Objects/structseq.c b/third_party/python/Objects/structseq.c index eb69f2454..a6691877f 100644 --- a/third_party/python/Objects/structseq.c +++ b/third_party/python/Objects/structseq.c @@ -4,13 +4,13 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Include/structseq.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/structmember.h" -#include "third_party/python/Include/structseq.h" /* clang-format off */ /* Implementation helper: a struct that looks like a tuple. See timemodule @@ -188,6 +188,7 @@ structseq_repr(PyStructSequence *obj) /* "typename(", limited to TYPE_MAXSIZE */ len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE : strlen(typ->tp_name); +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(pbuf, typ->tp_name, len); pbuf += len; *pbuf++ = '('; diff --git a/third_party/python/Python/ceval.c b/third_party/python/Python/ceval.c index 12769a4a7..2f69dd4af 100644 --- a/third_party/python/Python/ceval.c +++ b/third_party/python/Python/ceval.c @@ -5353,6 +5353,9 @@ dtrace_function_entry(PyFrameObject *f) char* filename; char* funcname; int lineno; + (void)filename; + (void)funcname; + (void)lineno; filename = PyUnicode_AsUTF8(f->f_code->co_filename); funcname = PyUnicode_AsUTF8(f->f_code->co_name); lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); @@ -5365,6 +5368,9 @@ dtrace_function_return(PyFrameObject *f) char* filename; char* funcname; int lineno; + (void)filename; + (void)funcname; + (void)lineno; filename = PyUnicode_AsUTF8(f->f_code->co_filename); funcname = PyUnicode_AsUTF8(f->f_code->co_name); lineno = PyCode_Addr2Line(f->f_code, f->f_lasti); diff --git a/third_party/python/Python/cosmomodule.c b/third_party/python/Python/cosmomodule.c index 7953014e4..50c29f947 100644 --- a/third_party/python/Python/cosmomodule.c +++ b/third_party/python/Python/cosmomodule.c @@ -100,13 +100,13 @@ cosmo_rdtsc(PyObject *self, PyObject *noargs) return PyLong_FromUnsignedLong(rdtsc()); } +#ifdef __x86_64__ + PyDoc_STRVAR(getcpucore_doc, "getcpucore($module)\n\ --\n\n\ Returns 0-indexed CPU core on which process is currently scheduled."); -#ifdef __x86_64__ - static PyObject * cosmo_getcpucore(PyObject *self, PyObject *noargs) { @@ -137,7 +137,6 @@ Similar to zlib.crc32()."); static PyObject * cosmo_crc32c(PyObject *self, PyObject *args) { - Py_ssize_t n; Py_buffer data; unsigned crc, init = 0; if (!PyArg_ParseTuple(args, "y*|I:crc32c", &data, &init)) return 0; @@ -283,8 +282,6 @@ cosmo_exit1(PyObject *self, PyObject *args) _Exit(1); } -static bool ftrace_installed = 0; - typedef struct { PyObject_HEAD } FtracerObject; @@ -327,6 +324,7 @@ static PyTypeObject FtracerType = { .tp_methods = FtracerObject_methods, }; +#ifdef FTRACE PyDoc_STRVAR(ftrace_doc, "ftrace($module)\n\ --\n\n\ @@ -337,6 +335,7 @@ Enables logging of C function calls to stderr, e.g.\n\ \n\ Please be warned this prints massive amount of text. In order for it\n\ to work, the concomitant .com.dbg binary needs to be present."); +#endif static PyObject * cosmo_ftrace(PyObject *self, PyObject *noargs) diff --git a/third_party/python/Python/fatality.c b/third_party/python/Python/fatality.c index 823218987..85d687865 100644 --- a/third_party/python/Python/fatality.c +++ b/third_party/python/Python/fatality.c @@ -17,7 +17,6 @@ /* clang-format off */ _Py_IDENTIFIER(flush); -_Py_IDENTIFIER(stdout); _Py_IDENTIFIER(stderr); /* Import the site module (not into __main__ though) */ diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index 868c6d100..db38a72fb 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -865,7 +865,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, { struct stat stinfo; PyObject *m = NULL; - PyObject *nameobj, *pathobj = NULL, *cpathobj = NULL, *external= NULL; + PyObject *nameobj, *pathobj = NULL, *cpathobj = NULL; nameobj = PyUnicode_FromString(name); if (nameobj == NULL) @@ -1183,7 +1183,7 @@ _imp_create_builtin(PyObject *module, PyObject *spec) res = bsearch(&key, Builtins_Lookup.entries, Builtins_Lookup.n, sizeof(initentry), cmp_initentry); if (res != NULL) { - p = res->tab; + p = (void *)res->tab; PyModuleDef *def; if (p->initfunc == NULL) { /* Cannot re-init internal module ("sys" or "builtins") */ @@ -2491,7 +2491,6 @@ static PyObject *SFLObject_get_code(SourcelessFileLoader *self, PyObject *arg) { FILE *fp = NULL; PyObject *res = NULL; char *rawbuf = NULL; - size_t rawlen = 0; if (!PyArg_Parse(arg, "z:get_code", &name)) return 0; if (!name) name = self->name; diff --git a/third_party/python/Python/initimport.c b/third_party/python/Python/initimport.c index f28332fd7..23cc1f019 100644 --- a/third_party/python/Python/initimport.c +++ b/third_party/python/Python/initimport.c @@ -30,7 +30,6 @@ _Py_InitImport(PyInterpreterState *interp, PyObject *sysmod) { PyObject *importlib; PyObject *impmod; - PyObject *cosmomod; PyObject *sys_modules; PyObject *value; diff --git a/third_party/python/Python/pylifecycle.c b/third_party/python/Python/pylifecycle.c index 69c8140f3..067e7de38 100644 --- a/third_party/python/Python/pylifecycle.c +++ b/third_party/python/Python/pylifecycle.c @@ -4,6 +4,7 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Include/pylifecycle.h" #include "libc/assert.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" @@ -13,8 +14,8 @@ #include "libc/log/log.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" -#include "libc/sysv/consts/sig.h" #include "libc/str/locale.h" +#include "libc/sysv/consts/sig.h" #include "third_party/python/Include/Python-ast.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/ast.h" @@ -37,7 +38,6 @@ #include "third_party/python/Include/parsetok.h" #include "third_party/python/Include/pydebug.h" #include "third_party/python/Include/pyerrors.h" -#include "third_party/python/Include/pylifecycle.h" #include "third_party/python/Include/pymem.h" #include "third_party/python/Include/pystrcmp.h" #include "third_party/python/Include/pytime.h" @@ -53,9 +53,6 @@ /* Python interpreter top-level routines, including init/exit */ -_Py_IDENTIFIER(name); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(stdout); _Py_IDENTIFIER(stderr); /* Forward */ diff --git a/third_party/python/Python/random.c b/third_party/python/Python/random.c index 1de52b6a1..7aac024e1 100644 --- a/third_party/python/Python/random.c +++ b/third_party/python/Python/random.c @@ -11,8 +11,8 @@ #include "libc/fmt/conv.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/rdtsc.h" -#include "libc/stdio/rand.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/grnd.h" @@ -392,7 +392,6 @@ void _PyRandom_Init(void) { char *env; - const unsigned char *auxrng; unsigned char *secret = (unsigned char *)&_Py_HashSecret.uc; Py_ssize_t secret_size = sizeof(_Py_HashSecret_t); Py_BUILD_ASSERT(sizeof(_Py_HashSecret_t) == sizeof(_Py_HashSecret.uc)); @@ -431,7 +430,7 @@ _PyRandom_Init(void) } else { uint64_t x; - int res, i, j; + int i, j; /* _PyRandom_Init() is called very early in the Python initialization and so exceptions cannot be used (use raise=0). _PyRandom_Init() must not block Python initialization: call diff --git a/third_party/python/Python/sysmodule.c b/third_party/python/Python/sysmodule.c index a0af6cf76..855df1efc 100644 --- a/third_party/python/Python/sysmodule.c +++ b/third_party/python/Python/sysmodule.c @@ -1026,11 +1026,6 @@ sys_getwindowsversion(PyObject *self) int pos = 0; PyObject *version; struct NtOsVersionInfo ver; - uint32_t realMajor, realMinor, realBuild; - int64_t hKernel32; - wchar_t kernel32_path[PATH_MAX]; - void *verblock; - uint32_t verblock_size; if (!IsWindows()) { PyErr_SetString(PyExc_SystemError, "this is not windows"); @@ -1055,36 +1050,6 @@ sys_getwindowsversion(PyObject *self) PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask)); PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType)); - realMajor = ver.dwMajorVersion; - realMinor = ver.dwMinorVersion; - realBuild = ver.dwBuildNumber; - -#if 0 // todo(jart): port me - // GetVersion will lie if we are running in a compatibility mode. - // We need to read the version info from a system file resource - // to accurately identify the OS version. If we fail for any reason, - // just return whatever GetVersion said. - hKernel32 = GetModuleHandle("kernel32.dll"); - if (hKernel32 && GetModuleFileNameW(hKernel32, kernel32_path, MAX_PATH) && - (verblock_size = GetFileVersionInfoSizeW(kernel32_path, NULL)) && - (verblock = PyMem_RawMalloc(verblock_size))) { - VS_FIXEDFILEINFO *ffi; - UINT ffi_len; - if (GetFileVersionInfoW(kernel32_path, 0, verblock_size, verblock) && - VerQueryValueW(verblock, L"", (LPVOID)&ffi, &ffi_len)) { - realMajor = HIWORD(ffi->dwProductVersionMS); - realMinor = LOWORD(ffi->dwProductVersionMS); - realBuild = HIWORD(ffi->dwProductVersionLS); - } - PyMem_RawFree(verblock); - } - PyStructSequence_SET_ITEM(version, pos++, Py_BuildValue("(kkk)", - realMajor, - realMinor, - realBuild - )); -#endif - if (PyErr_Occurred()) { Py_DECREF(version); return NULL; diff --git a/third_party/python/launch.c b/third_party/python/launch.c index fc6d8a9bc..89c4a6e60 100644 --- a/third_party/python/launch.c +++ b/third_party/python/launch.c @@ -51,7 +51,7 @@ PYTHON_YOINK("launchpy"); extern char kLaunchPythonModuleName[]; /* generated by pyobj.com */ const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; -struct _inittab *PyImport_Inittab = _PyImport_Inittab; +struct _inittab *PyImport_Inittab = (void *)_PyImport_Inittab; int LaunchPythonModule(const char *name) diff --git a/third_party/python/pycomp.c b/third_party/python/pycomp.c index ce96b9e4d..3aaf2e043 100644 --- a/third_party/python/pycomp.c +++ b/third_party/python/pycomp.c @@ -77,7 +77,6 @@ void GetOpts(int argc, char *argv[]) { int opt; - char *outdir; while ((opt = getopt(argc, argv, "hnO:o:")) != -1) { switch (opt) { case 'O': @@ -114,7 +113,7 @@ main(int argc, char *argv[]) ssize_t rc; size_t i, n; struct stat st; - char *s, *p, m[12]; + char *p, m[12]; PyObject *code, *marshalled; ShowCrashReports(); GetOpts(argc, argv); diff --git a/third_party/python/pyobj.c b/third_party/python/pyobj.c index bb6ed67eb..75c37d088 100644 --- a/third_party/python/pyobj.c +++ b/third_party/python/pyobj.c @@ -215,9 +215,6 @@ const char *const kIgnoredModules[] = /* sorted */ { /* "xml.dom", */ }; -_Py_IDENTIFIER(stdout); -_Py_IDENTIFIER(stderr); - struct Yoinks { size_t n; char **p; @@ -469,13 +466,13 @@ Analyze(const char *modname, PyObject *code, struct Interner *globals) int rc; bool istry; unsigned a; - size_t i, j, n; + size_t i, n; char *p, *mod, *imp; int x, y, op, arg, rel; PyObject *co_code, *co_names, *co_consts, *name, *iter, *item; rc = 0; mod = 0; - istry = rel = 0; + istry = (rel = 0); assert(PyCode_Check(code)); co_code = ((PyCodeObject *)code)->co_code; co_names = ((PyCodeObject *)code)->co_names; diff --git a/third_party/python/runpythonmodule.c b/third_party/python/runpythonmodule.c index 1010283ae..db1c99790 100644 --- a/third_party/python/runpythonmodule.c +++ b/third_party/python/runpythonmodule.c @@ -66,7 +66,7 @@ PYTHON_YOINK("encodings.utf_8"); extern char kLaunchPythonModuleName[]; /* optionally generated by pyobj.com */ const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; -struct _inittab *PyImport_Inittab = _PyImport_Inittab; +struct _inittab *PyImport_Inittab = (void *)_PyImport_Inittab; static int g_gotint; static void @@ -168,8 +168,9 @@ CompleteDir(const char *b, const char *q, const char *p, static void Complete(const char *p, linenoiseCompletions *c) { - PyObject *o, *t, *i; - const char *q, *s, *b; + char *s; + PyObject *o, *t; + const char *q, *b; if (startswith(p, "import ")) { for (q = p + 7; *q; ++q) { if (!isalnum(*q) && *q != '_') { @@ -208,7 +209,7 @@ Complete(const char *p, linenoiseCompletions *c) break; } } - free(s); + free((void *)s); } } @@ -243,7 +244,7 @@ ReinterpretCommand(const char *line) if (n && line[n - 1] == '?') { return xstrcat("help(", gc(strndup(gc(line), n - 1)), ')'); } else { - return line; + return xstrdup(line); } } diff --git a/third_party/quickjs/bigint.c b/third_party/quickjs/bigint.c index bea95955e..55de313c7 100644 --- a/third_party/quickjs/bigint.c +++ b/third_party/quickjs/bigint.c @@ -58,6 +58,7 @@ static JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val, return JS_NewInt64(ctx, v); } else if (a->expn == BF_EXP_ZERO && a->sign) { JSBigFloat *p = JS_VALUE_GET_PTR(val); + (void)p; assert(p->header.ref_count == 1); a->sign = 0; } diff --git a/third_party/quickjs/map.c b/third_party/quickjs/map.c index 1119d09f1..2fe80fb43 100644 --- a/third_party/quickjs/map.c +++ b/third_party/quickjs/map.c @@ -318,6 +318,7 @@ void reset_weak_ref(JSRuntime *rt, JSObject *p) { JSMapRecord *mr, *mr_next; JSMapState *s; + (void)s; /* first pass to remove the records from the WeakMap/WeakSet lists */ for(mr = p->first_weak_ref; mr != NULL; mr = mr->next_weak_ref) { diff --git a/third_party/quickjs/quickjs.c b/third_party/quickjs/quickjs.c index 93d54aee9..97e26f409 100644 --- a/third_party/quickjs/quickjs.c +++ b/third_party/quickjs/quickjs.c @@ -146,7 +146,7 @@ void JS_SetUncatchableError(JSContext *ctx, JSValueConst val, BOOL flag); static const JSClassExoticMethods js_arguments_exotic_methods; static const JSClassExoticMethods js_string_exotic_methods; -static const JSClassExoticMethods js_proxy_exotic_methods; +/* static */ const JSClassExoticMethods js_proxy_exotic_methods; static const JSClassExoticMethods js_module_ns_exotic_methods; static JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT; @@ -914,6 +914,7 @@ void JS_SetContextOpaque(JSContext *ctx, void *opaque) void JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj) { JSRuntime *rt = ctx->rt; + (void)rt; assert(class_id < rt->class_count); set_value(ctx, &ctx->class_proto[class_id], obj); } @@ -921,6 +922,7 @@ void JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj) JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id) { JSRuntime *rt = ctx->rt; + (void)rt; assert(class_id < rt->class_count); return JS_DupValue(ctx, ctx->class_proto[class_id]); } @@ -3016,7 +3018,7 @@ static int num_keys_cmp(const void *p1, const void *p2, void *opaque) BOOL atom1_is_integer, atom2_is_integer; atom1_is_integer = JS_AtomIsArrayIndex(ctx, &v1, atom1); atom2_is_integer = JS_AtomIsArrayIndex(ctx, &v2, atom2); - assert(atom1_is_integer && atom2_is_integer); + unassert(atom1_is_integer && atom2_is_integer); if (v1 < v2) return -1; else if (v1 == v2) @@ -13268,8 +13270,8 @@ JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj, { int eval_type = eval_flags & JS_EVAL_TYPE_MASK; JSValue ret; - assert(eval_type == JS_EVAL_TYPE_GLOBAL || - eval_type == JS_EVAL_TYPE_MODULE); + unassert(eval_type == JS_EVAL_TYPE_GLOBAL || + eval_type == JS_EVAL_TYPE_MODULE); ret = JS_EvalInternal(ctx, this_obj, input, input_len, filename, eval_flags, -1); return ret; diff --git a/third_party/quickjs/str.c b/third_party/quickjs/str.c index 7391b3189..d658d4eb1 100644 --- a/third_party/quickjs/str.c +++ b/third_party/quickjs/str.c @@ -22,11 +22,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include "libc/str/str.h" #include "libc/assert.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/runtime/fenv.h" -#include "libc/str/str.h" #include "third_party/gdtoa/gdtoa.h" #include "third_party/quickjs/internal.h" #include "third_party/quickjs/libregexp.h" @@ -859,12 +859,6 @@ static int js_string_delete_property(JSContext *ctx, return TRUE; } -static const JSClassExoticMethods js_string_exotic_methods = { - .get_own_property = js_string_get_own_property, - .define_own_property = js_string_define_own_property, - .delete_property = js_string_delete_property, -}; - JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv) { diff --git a/third_party/radpajama/main-redpajama-chat.cc b/third_party/radpajama/main-redpajama-chat.cc index b56a183bb..754421020 100644 --- a/third_party/radpajama/main-redpajama-chat.cc +++ b/third_party/radpajama/main-redpajama-chat.cc @@ -160,11 +160,6 @@ int main(int argc, char ** argv) { set_console_color(con_st, CONSOLE_COLOR_PROMPT); - const int32_t top_k = params.top_k; - const float top_p = params.top_p; - const float temp = params.temp; - const float repeat_penalty = params.repeat_penalty; - while (true) { is_interacting = true; int n_past = 0; @@ -223,7 +218,7 @@ int main(int argc, char ** argv) { embd_inp.push_back(gptneox_str_to_token(ctx, ">:")); // How many tokens to generate - check if theres space in context for atleast one token (or batch size tokens?) - auto inp_size = embd_inp.size(); + int inp_size = embd_inp.size(); auto space = params.n_ctx - inp_size; if(space <= 0) { fprintf(stderr, "%s : input too long\n", __func__); @@ -325,7 +320,7 @@ int main(int argc, char ** argv) { space -= 1; // Repeat tokens update last_n_tokens.push_back(id); - if (last_n_tokens.size() > params.repeat_last_n) { + if ((int)last_n_tokens.size() > params.repeat_last_n) { last_n_tokens.erase(last_n_tokens.begin()); } // Redpajama: check if the interactive is done. diff --git a/third_party/sqlite3/sqlite3session.c b/third_party/sqlite3/sqlite3session.c index a463e81c8..0cc02ddae 100644 --- a/third_party/sqlite3/sqlite3session.c +++ b/third_party/sqlite3/sqlite3session.c @@ -866,6 +866,7 @@ static int sessionPreupdateEqual( sqlite3_value *pVal; /* Value returned by preupdate_new/old */ int rc; /* Error code from preupdate_new/old */ int eType = *a++; /* Type of value from change record */ + (void)rc; /* The following calls to preupdate_new() and preupdate_old() can not ** fail. This is because they cache their return values, and by the diff --git a/third_party/stb/stb_image_write_png.c b/third_party/stb/stb_image_write_png.c index b327d1583..9ee926f58 100644 --- a/third_party/stb/stb_image_write_png.c +++ b/third_party/stb/stb_image_write_png.c @@ -170,12 +170,13 @@ forceinline unsigned char stbiw__paeth(int a, int b, int c) { } // @OPTIMIZE: provide an option that always forces left-predict or paeth predict -static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, - int width, int height, int y, int n, - int filter_type, signed char *line_buffer) { - const int mapping[] = {0, 1, 2, 3, 4}; - const int firstmap[] = {0, 1, 0, 5, 6}; - unsigned char *z; +static void stbiw__encode_png_line(const unsigned char *pixels, + int stride_bytes, int width, int height, + int y, int n, int filter_type, + signed char *line_buffer) { + int mapping[] = {0, 1, 2, 3, 4}; + int firstmap[] = {0, 1, 0, 5, 6}; + const unsigned char *z; int *mymap, i, type, signed_stride; mymap = (y != 0) ? mapping : firstmap; diff --git a/third_party/tidy/language.c b/third_party/tidy/language.c index 18072abfd..d27b9b6b3 100644 --- a/third_party/tidy/language.c +++ b/third_party/tidy/language.c @@ -408,7 +408,7 @@ Bool TY_(tidySetLanguage)( ctmbstr languageCode ) if ( strlen( wantCode ) > 2 ) { - strncpy(lang, wantCode, 2); + strncpy(__veil("r", lang), __veil("r", wantCode), __veil("r", 2)); lang[2] = '\0'; dict2 = TY_(tidyTestLanguage( lang ) ); /* BACKUP language? */ } diff --git a/third_party/tidy/parser.c b/third_party/tidy/parser.c index d3f886724..331883edb 100644 --- a/third_party/tidy/parser.c +++ b/third_party/tidy/parser.c @@ -2796,6 +2796,7 @@ Node* TY_(ParseHTML)( TidyDocImpl *doc, Node *html, GetTokenMode mode ) Node *frameset = NULL; Node *noframes = NULL; DEBUG_LOG_COUNTERS; + (void)head; enum parserState { STATE_INITIAL, /* This is the initial state for every parser. */ diff --git a/third_party/tidy/tmbstr.c b/third_party/tidy/tmbstr.c index 0a338b91b..bc5565c67 100644 --- a/third_party/tidy/tmbstr.c +++ b/third_party/tidy/tmbstr.c @@ -266,7 +266,7 @@ void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep) } else { - strncpy(buf,buffer,strlen(buffer) - strlen(p)); + strncpy(__veil("r", buf),__veil("r", buffer),__veil("r", strlen(buffer) - strlen(p))); strcat(buf,rep); strcat(buf,p+strlen(str)); } diff --git a/third_party/unzip/fileio.c b/third_party/unzip/fileio.c index bb70ed80c..6a447eaf1 100644 --- a/third_party/unzip/fileio.c +++ b/third_party/unzip/fileio.c @@ -183,8 +183,6 @@ static ZCONST char Far ExtraFieldTooLong[] = #else static ZCONST char Far DiskFullQuery[] = "%s: write error (disk full?). Continue? (y/n/^C) "; - static ZCONST char Far ZipfileCorrupt[] = - "error: zipfile probably corrupt (%s)\n"; # ifdef SYMLINKS static ZCONST char Far FileIsSymLink[] = "%s exists and is a symbolic link%s.\n"; diff --git a/third_party/unzip/unix.c b/third_party/unzip/unix.c index d83f54977..9bd101b4d 100644 --- a/third_party/unzip/unix.c +++ b/third_party/unzip/unix.c @@ -1268,6 +1268,7 @@ int set_symlnk_attribs(__G__ slnk_entry) slinkentry *slnk_entry; { ulg z_uidgid[2]; + (void)z_uidgid; if (slnk_entry->attriblen > 0) { # if (!defined(NO_LCHOWN)) diff --git a/third_party/unzip/unzip.c b/third_party/unzip/unzip.c index 4808976d0..d9dfd8218 100644 --- a/third_party/unzip/unzip.c +++ b/third_party/unzip/unzip.c @@ -3626,7 +3626,7 @@ static ZCONST char Far long_op_ambig_err[] = static ZCONST char Far long_op_not_sup_err[] = "long option '%s' not supported\n"; -static ZCONST char Far no_arg_files_err[] = "argument files not enabled\n"; +/* static ZCONST char Far no_arg_files_err[] = "argument files not enabled\n"; */ /* below removed as only used for processing argument files */ diff --git a/third_party/unzip/unzip.mk b/third_party/unzip/unzip.mk index 0c75743d8..37049d7ab 100644 --- a/third_party/unzip/unzip.mk +++ b/third_party/unzip/unzip.mk @@ -50,6 +50,7 @@ o/$(MODE)/third_party/unzip/unzip.com.dbg: \ $(THIRD_PARTY_UNZIP_A_OBJS): private \ CPPFLAGS += \ + -w \ -DUSE_BZIP2 \ -DUNICODE_SUPPORT \ -DHAVE_UNLINK \ diff --git a/third_party/xed/x86ild.greg.c b/third_party/xed/x86ild.greg.c index 9e99664ed..e2c7d4bdc 100644 --- a/third_party/xed/x86ild.greg.c +++ b/third_party/xed/x86ild.greg.c @@ -901,7 +901,6 @@ privileged static uint64_t xed_read_number(uint8_t *p, size_t n, bool s) { } privileged static void xed_evex_imm_scanner(struct XedDecodedInst *d) { - uint64_t uimm0; uint8_t *itext, *imm_ptr; xed_bits_t length, imm_bytes, imm1_bytes, max_bytes; imm_ptr = 0; @@ -1162,7 +1161,7 @@ privileged static void XED_LF_DISP_BUCKET_0_l1(struct XedDecodedInst *x) { } privileged static void xed_disp_scanner(struct XedDecodedInst *d) { - xed_bits_t length, disp_width, disp_bytes, max_bytes; + xed_bits_t length, disp_bytes, max_bytes; length = d->length; if (d->op.map < XED_ILD_MAP2) { switch (xed_disp_bits_2d[d->op.map][d->op.opcode]) { diff --git a/third_party/zip/fileio.c b/third_party/zip/fileio.c index e350503c1..cd24e8645 100644 --- a/third_party/zip/fileio.c +++ b/third_party/zip/fileio.c @@ -2941,7 +2941,7 @@ local int ucs4_string_to_utf8(ucs4, utf8buf, buflen) if (mbl < c) c = mbl; if (utf8buf && count < buflen) - strncpy(utf8buf + count, mb, c); + strlcpy(utf8buf + count, mb, c); if (mbl == 1 && !mb[0]) return count; /* terminating nul */ count += mbl; @@ -3204,7 +3204,6 @@ char *wide_to_local_string(wide_string) int i; wchar_t wc; int b; - int state_dependent; int wsize = 0; int max_bytes = MB_CUR_MAX; char buf[9]; @@ -3225,10 +3224,6 @@ char *wide_to_local_string(wide_string) /* set initial state if state-dependent encoding */ wc = (wchar_t)'a'; b = wctomb(NULL, wc); - if (b == 0) - state_dependent = 0; - else - state_dependent = 1; for (i = 0; i < wsize; i++) { if (sizeof(wchar_t) < 4 && wide_string[i] > 0xFFFF) { /* wchar_t probably 2 bytes */ diff --git a/third_party/zip/zip.mk b/third_party/zip/zip.mk index 048d4c28c..761563b6f 100644 --- a/third_party/zip/zip.mk +++ b/third_party/zip/zip.mk @@ -152,6 +152,7 @@ o/$(MODE)/third_party/zip/zipnote.o \ o/$(MODE)/third_party/zip/zipsplit.o \ o/$(MODE)/third_party/zip/zipup.o: private \ CPPFLAGS += \ + -w \ -DUNIX \ -DMMAP \ -DUNICODE_SUPPORT \ diff --git a/third_party/zip/zipup.c b/third_party/zip/zipup.c index 9450063f1..9863faab5 100644 --- a/third_party/zip/zipup.c +++ b/third_party/zip/zipup.c @@ -418,7 +418,7 @@ struct zlist far *z; /* zip entry to compress */ int l = 0; /* true if this file is a symbolic link */ int m; /* method for this entry */ - zoff_t o = 0, p; /* offsets in zip file */ + zoff_t o = 0; /* offsets in zip file */ zoff_t q = (zoff_t) -3; /* size returned by filetime */ uzoff_t uq; /* unsigned q */ zoff_t s = 0; /* size of compressed data */ @@ -952,7 +952,6 @@ struct zlist far *z; /* zip entry to compress */ #endif /*MMAP */ tempzn += s; - p = tempzn; /* save for future fseek() */ #if (!defined(MSDOS) || defined(OS2)) #if !defined(VMS) && !defined(CMS_MVS) && !defined(__mpexl) @@ -1689,9 +1688,6 @@ int pack_level; { int err = BZ_OK; int zp_err = ZE_OK; - const char *bzlibVer; - - bzlibVer = BZ2_bzlibVersion(); /* $TODO - Check BZIP2 LIB version? */ diff --git a/third_party/zlib/zutil.c b/third_party/zlib/zutil.c index 98150040a..68ac61c83 100644 --- a/third_party/zlib/zutil.c +++ b/third_party/zlib/zutil.c @@ -12,6 +12,8 @@ #include "third_party/zlib/zutil.internal.h" // clang-format off +#pragma GCC diagnostic ignored "-Wimplicit-int" + /* @(#) $Id$ */ z_const char * const z_errmsg[10] = { diff --git a/tool/args/args.c b/tool/args/args.c index f5020e612..b9d10593a 100644 --- a/tool/args/args.c +++ b/tool/args/args.c @@ -55,7 +55,7 @@ void FreeZipArgs(void) { } int LoadZipArgsImpl(int *argc, char ***argv, char *data) { - int i, n, fd; + int i, n; bool founddots; char *arg, **args, *state, *start; assert(!g_zipargs.loaded); diff --git a/tool/build/apelink.c b/tool/build/apelink.c index ff1b22e00..a03d6d418 100644 --- a/tool/build/apelink.c +++ b/tool/build/apelink.c @@ -861,8 +861,6 @@ void FixupPeImage(char *map, size_t size, // Elf64_Sxword off_skew) { assert(!(rva_skew & 65535)); - Elf64_Sxword skew = rva_skew; - // fixup pe header if (ckd_sub(&pe->OptionalHeader.ImageBase, // pe->OptionalHeader.ImageBase, rva_skew)) @@ -972,7 +970,6 @@ static void AddLoader(const char *path) { } static void GetOpts(int argc, char *argv[]) { - char *endptr; int opt, bits; bool got_support_vector = false; while ((opt = getopt(argc, argv, "hvgsGBo:l:S:M:V:")) != -1) { @@ -1282,7 +1279,7 @@ static char *GenerateMachoSegment(char *p, struct Input *in, Elf64_Phdr *phdr) { load = (struct MachoLoadSegment *)p; load->command = MAC_LC_SEGMENT_64; load->size = sizeof(*load); - FormatInt32(stpcpy(load->name, "__APE"), macholoadcount); + FormatInt32(__veil("r", stpcpy(load->name, "__APE")), macholoadcount); ++macholoadcount; load->vaddr = phdr->p_vaddr; load->memsz = phdr->p_memsz; @@ -1482,9 +1479,7 @@ static char *SecondPass2(char *p, struct Input *in) { // focusing on embedding the executable files passed via the flags. static Elf64_Off ThirdPass(Elf64_Off offset, struct Input *in) { int i; - char *data; Elf64_Addr vaddr; - Elf64_Phdr *phdr; Elf64_Xword image_align; // determine microprocessor page size @@ -1814,9 +1809,8 @@ static void CopyZips(Elf64_Off offset) { int main(int argc, char *argv[]) { char *p; - int i, j, opt; + int i, j; Elf64_Off offset; - char empty[64] = {0}; Elf64_Xword prologue_bytes; #ifndef NDEBUG ShowCrashReports(); diff --git a/tool/build/ar.c b/tool/build/ar.c index 4d6da88f3..e006fe655 100644 --- a/tool/build/ar.c +++ b/tool/build/ar.c @@ -318,7 +318,7 @@ int main(int argc, char *argv[]) { if (argc < 3) { ShowUsage(1, 2); } - const char *flags = argv[1]; + char *flags = argv[1]; const char *outpath = argv[2]; // we only support one mode of operation, which is creating a new diff --git a/tool/build/assimilate.c b/tool/build/assimilate.c index 1c5c8ab88..ba153d9a5 100644 --- a/tool/build/assimilate.c +++ b/tool/build/assimilate.c @@ -22,6 +22,7 @@ #include "libc/dce.h" #include "libc/elf/def.h" #include "libc/elf/struct/ehdr.h" +#include "libc/errno.h" #include "libc/fmt/conv.h" #include "libc/intrin/bits.h" #include "libc/limits.h" @@ -36,7 +37,6 @@ #include "libc/sysv/consts/o.h" #include "libc/sysv/consts/prot.h" #include "third_party/getopt/getopt.internal.h" -#include "libc/errno.h" #include "third_party/regex/regex.h" #define VERSION \ @@ -194,7 +194,7 @@ static int GetElfArch(void) { static void GetElfHeader(Elf64_Ehdr *ehdr, const char *image, size_t n) { int c, i; - char *p, *e; + const char *p, *e; for (p = image, e = p + MIN(n, 8192); p < e; ++p) { TryAgain: if (READ64LE(p) != READ64LE("printf '")) continue; @@ -383,7 +383,7 @@ static int GetMode(int fd) { } static void CopyFile(int infd, const char *map, size_t size, // - void *hdr, size_t hdrsize) { + const void *hdr, size_t hdrsize) { int outfd; if (!outpath) return; if ((outfd = creat(outpath, GetMode(infd))) == -1) DieSys(outpath); @@ -393,7 +393,7 @@ static void CopyFile(int infd, const char *map, size_t size, // } static void WriteOutput(int infd, const char *map, size_t size, // - void *hdr, size_t hdrsize) { + const void *hdr, size_t hdrsize) { int outfd, oflags, omode; if (outpath) { CopyFile(infd, map, size, hdr, hdrsize); diff --git a/tool/build/bigmul.c b/tool/build/bigmul.c index cff0343eb..0cbde2670 100644 --- a/tool/build/bigmul.c +++ b/tool/build/bigmul.c @@ -31,10 +31,8 @@ void PrintMultiplyKernel(int n, int m) { bool cf, of; - uint128_t x; bool *Rs, *Ra; int j, i, k1, k2, g; - uint64_t *R, *H; printf("\ /**\n\ * Computes %d-bit product of %d-bit and %d-bit numbers.\n\ @@ -67,7 +65,7 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) { (printf)("\ asm(\"xorl\\t%%k0,%%k0\" : \"=r\"(z), \"+m\"(cf), \"+m\"(of));\n", j); - for (cf = of = i = 0; i < n; ++i) { + for (cf = of = false, i = 0; i < n; ++i) { if (!i) { if (!Rs[i + j] && !Rs[i + j + 1]) { assert(!cf); diff --git a/tool/build/chmod.c b/tool/build/chmod.c index 8c0562ab7..df576f76a 100644 --- a/tool/build/chmod.c +++ b/tool/build/chmod.c @@ -58,7 +58,7 @@ static void GetOpts(int argc, char *argv[]) { int main(int argc, char *argv[]) { int i, mode; - char buf[PATH_MAX], *endptr; + char *endptr; prog = argv[0]; if (!prog) prog = "chmod"; GetOpts(argc, argv); diff --git a/tool/build/compile.c b/tool/build/compile.c index f4e86e531..f7908d8a9 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -313,7 +313,6 @@ void PrintReset(void) { } void PrintMakeCommand(void) { - const char *s; appends(&output, "make MODE="); appends(&output, mode); appends(&output, " -j"); @@ -476,14 +475,15 @@ void AddArg(char *actual) { } appends(&command, s); if (!args.n) { - appends(&shortened, StripPrefix(basename(s), "x86_64-linux-musl-")); + appends(&shortened, + StripPrefix(basename(gc(strdup(s))), "x86_64-linux-musl-")); } else if (*s != '-') { appendw(&shortened, ' '); if ((isar || isbfd || ispkg) && (strcmp(args.p[args.n - 1], "-o") && (endswith(s, ".o") || endswith(s, ".pkg") || (endswith(s, ".a") && !isar)))) { - appends(&shortened, basename(s)); + appends(&shortened, basename(gc(strdup(s)))); } else { appends(&shortened, s); } @@ -511,11 +511,11 @@ static int GetBaseCpuFreqMhz(void) { } void SetCpuLimit(int secs) { - int mhz, lim; - struct rlimit rlim; if (secs <= 0) return; if (IsWindows()) return; #ifdef __x86_64__ + int mhz, lim; + struct rlimit rlim; if (!(mhz = GetBaseCpuFreqMhz())) return; lim = ceil(3100. / mhz * secs); rlim.rlim_cur = lim; @@ -851,13 +851,12 @@ char *MakeTmpOut(const char *path) { } int main(int argc, char *argv[]) { - int columns; uint64_t us; bool isineditor; size_t i, j, n, m; bool isproblematic; + char *s, *q, **envp; int ws, opt, exitcode; - char *s, *p, *q, **envp; #ifndef NDEBUG ShowCrashReports(); @@ -1070,7 +1069,7 @@ int main(int argc, char *argv[]) { #ifdef __x86_64__ } else if (!strcmp(argv[i], "-march=native")) { - struct X86ProcessorModel *model; + const struct X86ProcessorModel *model; if (X86_HAVE(XOP)) AddArg("-mxop"); if (X86_HAVE(SSE4A)) AddArg("-msse4a"); if (X86_HAVE(SSE3)) AddArg("-msse3"); diff --git a/tool/build/dso/sandbox.c b/tool/build/dso/sandbox.c index 10cdf4be3..57b98d168 100644 --- a/tool/build/dso/sandbox.c +++ b/tool/build/dso/sandbox.c @@ -35,7 +35,7 @@ __attribute__((__constructor__)) void init(void) { for (i = j = 0; i < 2; ++i) { while ((c = s[j] & 255)) { ++j; - if ('0' <= c & c <= '9') { + if ('0' <= c && c <= '9') { arg[i] *= 10; arg[i] += c - '0'; } else { diff --git a/tool/build/elf2pe.c b/tool/build/elf2pe.c index 4b17aa416..ae4aa95f1 100644 --- a/tool/build/elf2pe.c +++ b/tool/build/elf2pe.c @@ -49,6 +49,8 @@ // see tool/hello/hello-pe.c for an example program this can link // make -j8 m=tiny o/tiny/tool/hello/hello-pe.com +#pragma GCC diagnostic ignored "-Wstringop-overflow" + #define VERSION \ "elf2pe v0.1\n" \ "copyright 2023 justine tunney\n" \ @@ -273,7 +275,6 @@ static void RelocateRela(struct Elf *elf, struct Segment *segment, RelocateVaddrWithinSegment(elf, rela->r_offset, segment); Elf64_Addr symbol_vaddr = elf->symtab[ELF64_R_SYM(rela->r_info)].st_value; char *place_ptr = segment->ptr_new + (place_vaddr - segment->vaddr_new_min); - Elf64_Sxword addend = rela->r_addend; switch (ELF64_R_TYPE(rela->r_info)) { case R_X86_64_NONE: // do nothing case R_X86_64_COPY: // do nothing @@ -1032,7 +1033,6 @@ static struct ImagePointer GeneratePe(struct Elf *elf, char *fp, int64_t vp) { static void GetOpts(int argc, char *argv[]) { int opt; - char *endptr; while ((opt = getopt(argc, argv, "ho:D:")) != -1) { switch (opt) { case 'o': diff --git a/tool/build/fastdiff.c b/tool/build/fastdiff.c index 77e9c3644..404d420ef 100644 --- a/tool/build/fastdiff.c +++ b/tool/build/fastdiff.c @@ -35,7 +35,6 @@ int main(int argc, char *argv[]) { int line; char *l1, *l2; FILE *f1, *f2; - int differences; if (argc < 3) { fprintf(stderr, "usage: %s FILE1 FILE2\n", argv[0]); exit(1); @@ -48,7 +47,7 @@ int main(int argc, char *argv[]) { perror(argv[2]); exit(1); } - for (differences = 0, line = 1;; ++line) { + for (line = 1;; ++line) { l1 = fgets(line1, sizeof(line1), f1); l2 = fgets(line2, sizeof(line2), f2); if (!l1 && !l2) { diff --git a/tool/build/fixupobj.c b/tool/build/fixupobj.c index 722fdafe8..f0439b05b 100644 --- a/tool/build/fixupobj.c +++ b/tool/build/fixupobj.c @@ -51,7 +51,7 @@ #define MRS_TPIDR_EL0 0xd53bd040u #define MOV_REG(DST, SRC) (0xaa0003e0u | (SRC) << 16 | (DST)) -static const unsigned char kFatNops[8][8] = { +const unsigned char kFatNops[8][8] = { {}, // {0x90}, // nop {0x66, 0x90}, // xchg %ax,%ax @@ -68,9 +68,9 @@ static char *symstrs; static char *secstrs; static ssize_t esize; static Elf64_Sym *syms; +static Elf64_Ehdr *elf; static const char *epath; static Elf64_Xword symcount; -static const Elf64_Ehdr *elf; static wontreturn void Die(const char *reason) { tinyprint(2, epath, ": ", reason, "\n", NULL); @@ -139,11 +139,10 @@ static void GetOpts(int argc, char *argv[]) { } static void CheckPrivilegedCrossReferences(void) { - long i; unsigned long x; - Elf64_Shdr *shdr; const char *secname; - Elf64_Rela *rela, *erela; + const Elf64_Shdr *shdr; + const Elf64_Rela *rela, *erela; shdr = FindElfSectionByName(elf, esize, secstrs, ".rela.privileged"); if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr))) return; erela = rela + shdr->sh_size / sizeof(*rela); @@ -170,7 +169,7 @@ static void CheckPrivilegedCrossReferences(void) { // Modify ARM64 code to use x28 for TLS rather than tpidr_el0. static void RewriteTlsCode(void) { - int i, dest; + int i; Elf64_Shdr *shdr; uint32_t *p, *pe; for (i = 0; i < elf->e_shnum; ++i) { @@ -205,7 +204,6 @@ static void RewriteTlsCode(void) { static void OptimizePatchableFunctionEntries(void) { #ifdef __x86_64__ long i, n; - int nopcount; Elf64_Shdr *shdr; unsigned char *p, *pe; for (i = 0; i < symcount; ++i) { @@ -365,7 +363,7 @@ static void FixupObject(void) { } int main(int argc, char *argv[]) { - int i, opt; + int i; if (!IsOptimized()) { ShowCrashReports(); } diff --git a/tool/build/gzip.c b/tool/build/gzip.c index 19dc69a05..386f61c72 100644 --- a/tool/build/gzip.c +++ b/tool/build/gzip.c @@ -135,7 +135,7 @@ void GetOpts(int argc, char *argv[]) { void Compress(const char *inpath) { FILE *input; gzFile output; - int rc, n, errnum; + int rc, errnum; const char *outpath; char *p, openflags[5]; if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) { diff --git a/tool/build/lib/asmdown.c b/tool/build/lib/asmdown.c index 52a086df9..154810831 100644 --- a/tool/build/lib/asmdown.c +++ b/tool/build/lib/asmdown.c @@ -33,7 +33,6 @@ static bool IsSymbolChar2(char c) { } static bool IsSymbolString(const char *s) { - int i; if (!IsSymbolChar1(*s++)) return false; while (*s) { if (!IsSymbolChar2(*s++)) return false; @@ -54,7 +53,8 @@ static bool IsSymbolString(const char *s) { */ struct Asmdown *ParseAsmdown(const char *code, size_t size) { struct Asmdown *ad; - char *p1, *p2, *p3, *symbol, *alias; + const char *p1; + char *p2, *p3, *symbol, *alias; enum { BOL, COM, SYM, OTHER } state; int i, j, line, start_line, start_docstring, end_docstring, start_symbol; ad = calloc(1, sizeof(struct Asmdown)); diff --git a/tool/build/lib/buffer.c b/tool/build/lib/buffer.c index 8305d3533..41322d1d2 100644 --- a/tool/build/lib/buffer.c +++ b/tool/build/lib/buffer.c @@ -27,7 +27,7 @@ /* TODO(jart): replace with new append*() library */ -void AppendData(struct Buffer *b, char *data, unsigned len) { +void AppendData(struct Buffer *b, const char *data, size_t len) { char *p; unsigned n; if (b->i + len + 1 > b->n) { @@ -63,7 +63,6 @@ void AppendWide(struct Buffer *b, wint_t wc) { int AppendFmt(struct Buffer *b, const char *fmt, ...) { int n; - char *p; va_list va, vb; va_start(va, fmt); va_copy(vb, va); diff --git a/tool/build/lib/buffer.h b/tool/build/lib/buffer.h index a4f616f77..134c4a0ef 100644 --- a/tool/build/lib/buffer.h +++ b/tool/build/lib/buffer.h @@ -9,7 +9,7 @@ struct Buffer { }; void AppendChar(struct Buffer *, char); -void AppendData(struct Buffer *, char *, unsigned); +void AppendData(struct Buffer *, const char *, size_t); void AppendStr(struct Buffer *, const char *); void AppendWide(struct Buffer *, wint_t); int AppendFmt(struct Buffer *, const char *, ...); diff --git a/tool/build/lib/demangle.c b/tool/build/lib/demangle.c index 86c775c70..edfadff73 100644 --- a/tool/build/lib/demangle.c +++ b/tool/build/lib/demangle.c @@ -47,7 +47,7 @@ void SpawnCxxFilt(void) { if (!(g_cxxfilt.pid = vfork())) { dup2(pipefds[1][0], 0); dup2(pipefds[0][1], 1); - execv(path, (char *const[]){cxxfilt, NULL}); + execv(path, (char *const[]){(char *)cxxfilt, 0}); abort(); } g_cxxfilt.reader = pipefds[0][0]; @@ -87,7 +87,7 @@ char *DemangleCxxFilt(char *p, size_t pn, const char *s, size_t sn) { if (!g_cxxfilt.pid) SpawnCxxFilt(); if (g_cxxfilt.pid == -1) return NULL; buf[0] = '\n'; - iov[0].iov_base = s; + iov[0].iov_base = (void *)s; iov[0].iov_len = sn; iov[1].iov_base = buf; iov[1].iov_len = 1; diff --git a/tool/build/lib/eztls.c b/tool/build/lib/eztls.c index 5b5de4800..278d2fee4 100644 --- a/tool/build/lib/eztls.c +++ b/tool/build/lib/eztls.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/build/lib/eztls.h" #include "libc/calls/calls.h" #include "libc/calls/struct/iovec.h" #include "libc/errno.h" @@ -27,7 +28,6 @@ #include "net/https/https.h" #include "third_party/mbedtls/net_sockets.h" #include "third_party/mbedtls/ssl.h" -#include "tool/build/lib/eztls.h" struct EzTlsBio ezbio; mbedtls_ssl_config ezconf; @@ -72,7 +72,7 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) { if (len || bio->c > 0) { v[0].iov_base = bio->u; v[0].iov_len = MAX(0, bio->c); - v[1].iov_base = buf; + v[1].iov_base = (void *)buf; v[1].iov_len = len; if (EzWritevAll(bio->fd, v, 2) != -1) { if (bio->c > 0) bio->c = 0; @@ -90,7 +90,6 @@ int EzTlsFlush(struct EzTlsBio *bio, const unsigned char *buf, size_t len) { static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) { int rc; - struct iovec v[2]; struct EzTlsBio *bio = ctx; if (bio->c >= 0 && bio->c + len <= sizeof(bio->u)) { memcpy(bio->u + bio->c, buf, len); @@ -103,7 +102,6 @@ static int EzTlsSend(void *ctx, const unsigned char *buf, size_t len) { static int EzTlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { int r; - ssize_t s; struct iovec v[2]; struct EzTlsBio *bio = ctx; if ((r = EzTlsFlush(bio, 0, 0)) < 0) return r; diff --git a/tool/build/lib/getargs.c b/tool/build/lib/getargs.c index 49b3d0bf6..6f44c2e9c 100644 --- a/tool/build/lib/getargs.c +++ b/tool/build/lib/getargs.c @@ -117,7 +117,6 @@ const char *getargs_next(struct GetArgs *ga) { int fd; char *p; size_t k; - unsigned m; ssize_t size; for (;;) { if (ga->map) { @@ -128,6 +127,7 @@ const char *getargs_next(struct GetArgs *ga) { } k = 0; #if defined(__SSE2__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) + unsigned m; typedef unsigned char xmm_t __attribute__((__vector_size__(16), __aligned__(1))); for (; ga->j + k + 16 <= ga->mapsize; k += 16) { diff --git a/tool/build/lib/interner.c b/tool/build/lib/interner.c index eba37ee8c..f8061535a 100644 --- a/tool/build/lib/interner.c +++ b/tool/build/lib/interner.c @@ -94,8 +94,8 @@ size_t interncount(const struct Interner *t) { size_t internobj(struct Interner *t, const void *data, size_t size) { char *p2; size_t n2; - char *item; unsigned hash; + const char *item; struct InternerObject *it; size_t i, off, step, need, bytes; step = 0; diff --git a/tool/build/lib/javadown.c b/tool/build/lib/javadown.c index b270becdf..b777b5aef 100644 --- a/tool/build/lib/javadown.c +++ b/tool/build/lib/javadown.c @@ -120,7 +120,6 @@ static void SplitLines(struct Lines *lines, char *p) { } static bool ConsumeFileOverview(struct Lines *lines) { - int i; if (lines->n && lines->p[0].n >= strlen(FILEOVERVIEW) && startswith(lines->p[0].p, FILEOVERVIEW)) { lines->p[0].p += strlen(FILEOVERVIEW); @@ -192,10 +191,9 @@ static int ExtractText(struct Javadown *jd, struct Lines *lines, int i) { } static void ExtractTags(struct Javadown *jd, struct Lines *lines, int i) { - size_t n; - char *p, *tag, *text, *p2; + char *tag, *text, *p2; unsigned taglen, textlen, n2; - for (p = NULL, n = 0; i < lines->n; ++i) { + for (; i < lines->n; ++i) { if (!lines->p[i].n) continue; if (lines->p[i].p[0] != '@') continue; tag = lines->p[i].p + 1; diff --git a/tool/build/lib/panel.c b/tool/build/lib/panel.c index 1d9c7c6de..adf50f8de 100644 --- a/tool/build/lib/panel.c +++ b/tool/build/lib/panel.c @@ -65,7 +65,6 @@ static int tpdecode(const char *s, wint_t *out) { ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) { wint_t wc; ssize_t rc; - size_t wrote; struct Buffer b, *l; int x, y, i, j, width; enum { kUtf8, kAnsi, kAnsiCsi } state; diff --git a/tool/build/lz4toasm.c b/tool/build/lz4toasm.c index 7e65b3a9d..da32ec4bf 100644 --- a/tool/build/lz4toasm.c +++ b/tool/build/lz4toasm.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { const char *lz4path = "/dev/stdin"; const char *outpath = "/dev/stdout"; const char *initprio = "400,_init_"; - const unsigned char *lz4data; + unsigned char *lz4data; int opt; FILE *fin, *fout; @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) { fprintf(fout, "\n"); fprintf(fout, "\t.init.start %s%s\n", initprio, symbol); fprintf(fout, "\tpush\t%%rsi\n"); - fprintf(fout, "\tmov\t$%u,%%edx\n", size); + fprintf(fout, "\tmov\t$%zu,%%edx\n", size); fprintf(fout, "\tcall\tlz4cpy\n"); if (misalign) { fprintf(fout, "\tlea\t%zu(%%rax),%%rdi\n", misalign); @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) { fprintf(fout, "\tmov\t%%rax,%%rdi\n"); } fprintf(fout, "\tpop\t%%rsi\n"); - fprintf(fout, "\tadd\t$%u,%%rsi\n", ROUNDUP(size, 8)); + fprintf(fout, "\tadd\t$%zu,%%rsi\n", ROUNDUP(size, 8)); fprintf(fout, "\t.init.end %s%s\n", initprio, symbol); fprintf(fout, "\n"); diff --git a/tool/build/march-native.c b/tool/build/march-native.c index 36fc3f5c9..5328e4d44 100644 --- a/tool/build/march-native.c +++ b/tool/build/march-native.c @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) { if (X86_HAVE(BMI2)) Puts("-mbmi2"); if (X86_HAVE(ADX)) Puts("-madx"); if (X86_HAVE(FXSR)) Puts("-mfxsr"); - if ((model = getx86processormodel(kX86ProcessorModelKey))) { + if ((model = (void *)getx86processormodel(kX86ProcessorModelKey))) { switch (model->march) { case X86_MARCH_CORE2: Puts("-march=core2"); diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index 5f1c9067c..a844d4ade 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -206,8 +206,8 @@ static void Crunch(void) { free(sources.p); sources.p = 0; sources.i = j; - if (radix_sort_int64((const long *)sauces, sources.i) == -1 || - radix_sort_int64((const long *)edges.p, edges.i) == -1) { + if (radix_sort_int64((long *)sauces, sources.i) == -1 || + radix_sort_int64((long *)edges.p, edges.i) == -1) { DieOom(); } } @@ -266,7 +266,7 @@ static void LoadRelationships(int argc, char *argv[]) { char *map; ssize_t rc; struct GetArgs ga; - size_t i, n, size, inclen; + size_t n, size, inclen; unsigned srcid, dependency; const char *p, *pe, *src, *path, *pathend; getargs_init(&ga, argv + optind); @@ -368,7 +368,6 @@ static bool IsObjectSource(const char *name) { } __funline bool Bts(uint32_t *p, size_t i) { - bool r; uint32_t k; k = 1u << (i & 31); if (p[i >> 5] & k) return true; diff --git a/tool/build/mv.c b/tool/build/mv.c index d4cab6be1..1ad28a952 100644 --- a/tool/build/mv.c +++ b/tool/build/mv.c @@ -158,7 +158,7 @@ char *Join(const char *a, const char *b) { void Mv(char *src, char *dst) { ssize_t rc; - const char *s, *d; + const char *d; if (strlen(src) + 1 > PATH_MAX) _Exit(2); if (strlen(dst) + 1 > PATH_MAX) _Exit(2); basename(src); diff --git a/tool/build/objbincopy.c b/tool/build/objbincopy.c index 46f054bcb..ccec6c62f 100644 --- a/tool/build/objbincopy.c +++ b/tool/build/objbincopy.c @@ -325,7 +325,6 @@ static void HandleElf(const char *inpath, Elf64_Ehdr *elf, size_t esize) { int i, loadcount; Elf64_Off maxoff; Elf64_Phdr *phdr; - char empty[64] = {0}; Elf64_Shdr *macho_shdr; struct MachoHeader *macho; struct MachoLoadCommand *loadcommand; @@ -416,7 +415,7 @@ static void HandleInput(const char *inpath) { } int main(int argc, char *argv[]) { - int i, opt; + int i; prog = argv[0]; if (!prog) prog = "objbincopy"; GetOpts(argc, argv); diff --git a/tool/build/package.c b/tool/build/package.c index 865f8e097..bdf36b19f 100644 --- a/tool/build/package.c +++ b/tool/build/package.c @@ -204,7 +204,7 @@ static void PrintObject(struct Package *pkg, struct Object *obj) { } static void PrintPackage(struct Package *pkg) { - int i, j, o; + int i; kprintf("- %s\n", pkg->strings.p + pkg->path); kprintf(" objects=%d\n", pkg->objects.i); for (i = 0; i < pkg->objects.i; ++i) { @@ -224,7 +224,7 @@ static void PrintPackages(struct Package *p, int n) { static struct Package *LoadPackage(const char *path) { int fd; - ssize_t i, size; + ssize_t size; struct Package *pkg; if ((fd = open(path, O_RDONLY)) == -1) { SysExit(path, "open"); @@ -339,7 +339,7 @@ FLAGS\n\ static void GetOpts(struct Package *pkg, struct Packages *deps, int argc, char *argv[]) { - long i, si, opt; + long opt; const char *arg; struct GetArgs ga; pkg->path = -1; @@ -381,10 +381,8 @@ static void GetOpts(struct Package *pkg, struct Packages *deps, int argc, static void IndexSections(struct Package *pkg, struct Object *obj) { int i; const char *name; - const uint8_t *code; struct Section sect; const Elf64_Shdr *shdr; - struct XedDecodedInst xedd; obj->section_offset = pkg->sections.i; for (i = 0; i < obj->elf->e_shnum; ++i) { bzero(§, sizeof(sect)); @@ -566,7 +564,7 @@ static struct Symbol *BisectSymbol(struct Package *pkg, const char *name) { static bool FindSymbol(const char *name, struct Package *pkg, struct Packages *directdeps, struct Package **out_pkg, struct Symbol **out_sym) { - size_t i, j; + size_t i; struct Symbol *sym; if ((sym = BisectSymbol(pkg, name))) { if (out_sym) *out_sym = sym; @@ -607,7 +605,7 @@ static void CheckStrictDeps(struct Package *pkg, struct Packages *deps) { } static void CheckYourPrivilege(struct Package *pkg, struct Packages *deps) { - int i, j, o, f; + int i, f; const char *name; struct Symbol *sym; struct Package *dep; @@ -634,7 +632,7 @@ static bool IsSymbolDirectlyReachable(struct Package *pkg, static void Package(int argc, char *argv[], struct Package *pkg, struct Packages *deps) { - size_t i, j; + size_t i; GetOpts(pkg, deps, argc, argv); LoadObjects(pkg); CheckStrictDeps(pkg, deps); diff --git a/tool/build/pledge.c b/tool/build/pledge.c index efebdc7ea..761fbf2cf 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -583,9 +583,7 @@ Finish: int main(int argc, char *argv[]) { const char *s; bool hasfunbits; - int fdin, fdout; char buf[PATH_MAX]; - int e, zipfd, memfd; int useruid, usergid; int owneruid, ownergid; int oldfsuid, oldfsgid; diff --git a/tool/build/rollup.c b/tool/build/rollup.c index cde1ce6fd..7a1e839c4 100644 --- a/tool/build/rollup.c +++ b/tool/build/rollup.c @@ -62,7 +62,7 @@ void Process(const char *p, const char *pe, const char *path, bool isheader) { int level; bool noformat; const char *p2, *dq, *name; - for (noformat = level = 0; p < pe; p = p2) { + for (noformat = false, level = 0; p < pe; p = p2) { p2 = memchr(p, '\n', pe - p); p2 = p2 ? p2 + 1 : pe; if (LOOKINGAT(p, pe, "#if")) { diff --git a/tool/build/runit.c b/tool/build/runit.c index 5db9ea6ae..ef695127d 100644 --- a/tool/build/runit.c +++ b/tool/build/runit.c @@ -230,15 +230,12 @@ bool Send(int tmpfd, const void *output, size_t outputsize) { bool SendRequest(int tmpfd) { int fd; char *p; - size_t i; bool okall; - ssize_t rc; uint32_t crc; struct stat st; const char *name; unsigned char *hdr, *q; size_t progsize, namesize, hdrsize; - unsigned have; CHECK_NE(-1, (fd = open(g_prog, O_RDONLY))); CHECK_NE(-1, fstat(fd, &st)); CHECK_NE(MAP_FAILED, (p = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0))); @@ -302,8 +299,7 @@ bool Recv(unsigned char *p, size_t n) { int ReadResponse(void) { int res; - ssize_t rc; - size_t n, m; + size_t n; uint32_t size; unsigned char b[512]; for (res = -1; res == -1;) { @@ -378,7 +374,7 @@ bool ShouldRunInParallel(void) { int SpawnSubprocesses(int argc, char *argv[]) { const char *tpath; sigset_t chldmask, savemask; - int i, rc, ws, pid, tmpfd, *pids, exitcode; + int i, ws, pid, tmpfd, *pids, exitcode; struct sigaction ignore, saveint, savequit; char *args[5] = {argv[0], argv[1], argv[2]}; diff --git a/tool/build/runitd.c b/tool/build/runitd.c index e8062e706..b46ed0982 100644 --- a/tool/build/runitd.c +++ b/tool/build/runitd.c @@ -275,8 +275,7 @@ void SendOutputFragmentMessage(enum RunitCommand kind, unsigned char *buf, } void Recv(void *output, size_t outputsize) { - int rc; - ssize_t tx, chunk, received, totalgot; + ssize_t chunk, received, totalgot; static bool once; static int zstatus; static char buf[32768]; @@ -294,7 +293,6 @@ void Recv(void *output, size_t outputsize) { totalgot = 0; for (;;) { if (rbuf.len >= outputsize) { - tx = MIN(outputsize, rbuf.len); memcpy(output, rbuf.data + rbuf.off, outputsize); rbuf.len -= outputsize; rbuf.off += outputsize; @@ -362,17 +360,15 @@ void Recv(void *output, size_t outputsize) { } void HandleClient(void) { - const size_t kMaxNameSize = 128; - const size_t kMaxFileSize = 10 * 1024 * 1024; + ssize_t got; uint32_t crc; sigset_t sigmask; - ssize_t got, wrote; struct sockaddr_in addr; struct timespec now, deadline; char *addrstr, *exename, *exe; unsigned char msg[4 + 1 + 4 + 4 + 4]; - uint32_t addrsize, namesize, filesize, remaining; - int rc, events, exitcode, wstatus, child, pipefds[2]; + uint32_t addrsize, namesize, filesize; + int events, exitcode, wstatus, child, pipefds[2]; /* read request to run program */ addrsize = sizeof(addr); @@ -436,7 +432,7 @@ void HandleClient(void) { exe = g_exepath; } else { exe = "ape-m1.com"; - args[i++] = exe; + args[i++] = (char *)exe; args[i++] = "-"; args[i++] = g_exepath; } diff --git a/tool/build/unbundle.c b/tool/build/unbundle.c index 1d5029459..9998530e0 100644 --- a/tool/build/unbundle.c +++ b/tool/build/unbundle.c @@ -60,7 +60,7 @@ void Execute(char *argv[]) { int Visit(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { if (tflag == FTW_F && endswith(fpath, ".gz")) { - Execute((char *[]){"build/bootstrap/gzip.com", "-d", fpath, 0}); + Execute((char *[]){"build/bootstrap/gzip.com", "-d", (char *)fpath, 0}); strcpy(binpath, fpath); binpath[strlen(binpath) - 3] = 0; chmod(binpath, 0755); diff --git a/tool/build/zipcopy.c b/tool/build/zipcopy.c index 8772dbf3a..a54b66a2c 100644 --- a/tool/build/zipcopy.c +++ b/tool/build/zipcopy.c @@ -114,7 +114,7 @@ static void CopyZip(void) { int rela, recs; Elf64_Ehdr *ehdr; unsigned long ldest, cdest, ltotal, ctotal, length; - unsigned char *szip, *ineof, *stop, *eocd, *cdir, *lfile, *cfile; + unsigned char *ineof, *stop, *eocd, *cdir, *lfile, *cfile; // find zip eocd header // @@ -211,7 +211,6 @@ static void CopyZip(void) { } int main(int argc, char *argv[]) { - int i, opt; #ifndef NDEBUG ShowCrashReports(); #endif diff --git a/tool/build/zipobj.c b/tool/build/zipobj.c index eb85e467b..b6f8a0907 100644 --- a/tool/build/zipobj.c +++ b/tool/build/zipobj.c @@ -138,7 +138,6 @@ void GetOpts(int *argc, char ***argv) { void ProcessFile(struct ElfWriter *elf, const char *path) { int fd; void *map; - size_t pathlen; struct stat st; const char *name; if (stat(path, &st)) { @@ -167,7 +166,7 @@ void ProcessFile(struct ElfWriter *elf, const char *path) { name = name_; } else { name = path; - if (basenamify_) name = basename(name); + if (basenamify_) name = basename(gc(xstrdup(name))); name = StripComponents(name, strip_components_); if (path_prefix_) name = gc(xjoinpaths(path_prefix_, name)); } diff --git a/tool/decode/ar.c b/tool/decode/ar.c index 6df0a60e2..3481d5a98 100644 --- a/tool/decode/ar.c +++ b/tool/decode/ar.c @@ -94,8 +94,8 @@ static void PrintHeader(uint8_t *p) { static void Print(void) { int arsize; + uint8_t *b, *p; uint64_t offset; - uint8_t *b, *p, *e; uint32_t i, n, o, table, entries, symbols, symbolslen; arsize = atoi((char *)(data + 8 + 48)); CHECK_LE(4, arsize); diff --git a/tool/decode/elf.c b/tool/decode/elf.c index 943d2cbe7..bb445bd06 100644 --- a/tool/decode/elf.c +++ b/tool/decode/elf.c @@ -31,6 +31,8 @@ #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -53,8 +55,8 @@ static struct stat st[1]; static Elf64_Ehdr *elf; static void startfile(void) { - showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf", basename(path), - NULL, &kModelineAsm); + showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/elf", + basename(gc(strdup(path))), NULL, &kModelineAsm); printf("#include \"libc/elf.h\"\n\n", path); } @@ -224,7 +226,6 @@ static void printelfgroups(void) { section->sh_name) : 0); } - shdr->sh_offset; } } } diff --git a/tool/decode/lib/flagger.c b/tool/decode/lib/flagger.c index fa61fff57..53c39ad12 100644 --- a/tool/decode/lib/flagger.c +++ b/tool/decode/lib/flagger.c @@ -16,11 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/arraylist2.internal.h" +#include "tool/decode/lib/flagger.h" #include "libc/fmt/fmt.h" +#include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" -#include "tool/decode/lib/flagger.h" /** * Formats numeric flags integer as symbolic code. @@ -46,7 +46,7 @@ dontdiscard char *RecreateFlags(const struct IdName *names, unsigned long id) { } else { first = false; } - CONCAT(&bufp, &bufi, &bufn, names->name, strlen(names->name)); + CONCAT(&bufp, &bufi, &bufn, (char *)names->name, strlen(names->name)); } } if (id) { diff --git a/tool/decode/macho.c b/tool/decode/macho.c index 109d71675..2464e8379 100644 --- a/tool/decode/macho.c +++ b/tool/decode/macho.c @@ -23,6 +23,8 @@ #include "libc/fmt/libgen.h" #include "libc/intrin/safemacros.internal.h" #include "libc/macho.internal.h" +#include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -56,7 +58,7 @@ static void showmachoheader(void) { exit(1); } #endif - showtitle(basename(path), "macho", "header", NULL, NULL); + showtitle(basename(gc(strdup(path))), "macho", "header", NULL, NULL); printf("\n"); showinthex(macho->magic); show(".long", @@ -171,7 +173,7 @@ static void showmacholoaduuid(struct MachoLoadUuid *lu) { #define COLS 8 static void showmacholoadgeneric(struct MachoLoadCommand *lc) { - int i, c, col = 0; + int c, col = 0; int need_newline = 0; char16_t glyphs[COLS + 1]; const unsigned char *p, *pe; diff --git a/tool/decode/pe2.c b/tool/decode/pe2.c index fb9d0b01e..5f8fa9526 100644 --- a/tool/decode/pe2.c +++ b/tool/decode/pe2.c @@ -23,6 +23,8 @@ #include "libc/intrin/bits.h" #include "libc/intrin/safemacros.internal.h" #include "libc/mem/gc.h" +#include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/nt/struct/imagedosheader.internal.h" #include "libc/nt/struct/imagentheaders.internal.h" #include "libc/nt/struct/imageoptionalheader.internal.h" @@ -99,7 +101,7 @@ static void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize, } static void showmzheader(void) { - showtitle(basename(path), "dos", "mz header", + showtitle(basename(gc(strdup(path))), "dos", "mz header", "\tMZ = Mark 'Zibo' Joseph Zbikowski\n" "\te_cblp: bytes on last page\n" "\te_cp: 512-byte pages in file\n" @@ -152,7 +154,8 @@ static void showdosstub(void) { static void showpeoptionalheader(struct NtImageOptionalHeader *opt) { int i; - showtitle(basename(path), "windows", "pe \"optional\" header", NULL, NULL); + showtitle(basename(gc(strdup(path))), "windows", "pe \"optional\" header", + NULL, NULL); printf("\n"); show(".short", firstnonnull(findnamebyid(kNtPeOptionalHeaderMagicNames, opt->Magic), @@ -248,7 +251,8 @@ static void ShowIlt(uint32_t rva) { static void ShowIdt(char *idt, size_t size) { char *p, *e; printf("\n"); - showtitle(basename(path), "windows", "import descriptor table (idt)", 0, 0); + showtitle(basename(gc(strdup(path))), "windows", + "import descriptor table (idt)", 0, 0); for (p = idt, e = idt + size; p + 20 <= e; p += 20) { printf("\n"); show(".long", format(b1, "%#x", READ32LE(p)), @@ -266,14 +270,16 @@ static void ShowIdt(char *idt, size_t size) { for (p = idt, e = idt + size; p + 20 <= e; p += 20) { if (READ32LE(p)) { printf("\n"); - showtitle(basename(path), "windows", "import lookup table (ilt)", 0, 0); + showtitle(basename(gc(strdup(path))), "windows", + "import lookup table (ilt)", 0, 0); ShowIlt(READ32LE(p)); } } for (p = idt, e = idt + size; p + 20 <= e; p += 20) { if (READ32LE(p)) { printf("\n"); - showtitle(basename(path), "windows", "import address table (iat)", 0, 0); + showtitle(basename(gc(strdup(path))), "windows", + "import address table (iat)", 0, 0); ShowIlt(READ32LE(p + 16)); } } @@ -316,14 +322,14 @@ static void ShowSections(struct NtImageSectionHeader *s, size_t n) { sections = s; section_count = n; printf("\n"); - showtitle(basename(path), "windows", "sections", 0, 0); + showtitle(basename(gc(strdup(path))), "windows", "sections", 0, 0); for (i = 0; i < n; ++i) { ShowSection(s + i); } } static void showpeheader(struct NtImageNtHeaders *pe) { - showtitle(basename(path), "windows", "pe header", NULL, NULL); + showtitle(basename(gc(strdup(path))), "windows", "pe header", NULL, NULL); printf("\n"); showorg(mz->e_lfanew); show(".ascii", format(b1, "%`'.*s", 4, (const char *)&pe->Signature), diff --git a/tool/decode/zip.c b/tool/decode/zip.c index 51fe87284..3d604e6a8 100644 --- a/tool/decode/zip.c +++ b/tool/decode/zip.c @@ -419,7 +419,7 @@ uint8_t *GetZipCdir64(const uint8_t *p, size_t n) { do { if (READ32LE(p + i) == kZipCdir64LocatorMagic && (j = ZIP_LOCATE64_OFFSET(p + i)) + kZipCdir64HdrMinSize <= n) { - return p + j; + return (uint8_t *)p + j; } } while (i--); } @@ -430,7 +430,7 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) { size_t pos; uint16_t i; static int records; - uint8_t *eocd32, *eocd64, *cdir, *cf, *lf, *q; + uint8_t *eocd32, *eocd64, *cdir, *cf, *lf; eocd32 = GetZipCdir32(p, n); eocd64 = GetZipCdir64(p, n); CHECK(eocd32 || eocd64); diff --git a/tool/lambda/bru2bin.c b/tool/lambda/bru2bin.c index ce6bcde67..7348c31ee 100644 --- a/tool/lambda/bru2bin.c +++ b/tool/lambda/bru2bin.c @@ -225,7 +225,7 @@ static int Need(void) { static struct Node *Parse1(void) { wint_t c; int i, oldsp; - struct Node *r, *p, *q, *s; + struct Node *r, *p, *q; do { if ((c = Greed()) == EOF) return 0; } while (iswspace(c)); @@ -288,9 +288,7 @@ static struct Node *Parse1(void) { } static struct Node *Parse(void) { - wint_t c; - int i, oldsp; - struct Node *r, *p, *q, *s; + struct Node *r, *p, *q; p = r = Parse1(); if (!p) Error(6, "empty expression"); while ((q = Parse1())) { diff --git a/tool/lambda/lam2bin.c b/tool/lambda/lam2bin.c index e5ac458ec..f80e7cb9b 100644 --- a/tool/lambda/lam2bin.c +++ b/tool/lambda/lam2bin.c @@ -218,7 +218,7 @@ static int Need(void) { static struct Node *Parse1(void) { wint_t c; int i, oldsp; - struct Node *r, *p, *q, *s; + struct Node *r, *p, *q; if ((c = Greed()) == EOF) return 0; if (c == L'λ' || c == '\\') { oldsp = sp; @@ -269,9 +269,7 @@ static struct Node *Parse1(void) { } static struct Node *Parse(void) { - wint_t c; - int i, oldsp; - struct Node *r, *p, *q, *s; + struct Node *r, *p, *q; p = r = Parse1(); if (!p) Error(6, "empty expression"); while ((q = Parse1())) { diff --git a/tool/lambda/lib/debug.c b/tool/lambda/lib/debug.c index 8dba7556b..65c3c0a8d 100644 --- a/tool/lambda/lib/debug.c +++ b/tool/lambda/lib/debug.c @@ -45,7 +45,7 @@ int GetDepth(struct Closure *env) { } void PrintClosure(struct Closure *c, const char *name, int indent, FILE *f) { - int i, j; + int j; char ibuf[21]; while (c && c != &root) { for (j = 0; j < indent; ++j) { @@ -71,7 +71,6 @@ void PrintMachineState(FILE *f) { int i; char buf[256]; static int op; - struct Closure *c; fputc('\n', f); for (i = 0; i < 80; ++i) fputwc(L'─', f); ksnprintf(buf, sizeof(buf), diff --git a/tool/net/fetch.inc b/tool/net/fetch.inc index f06d9b0a3..41dcb5f00 100644 --- a/tool/net/fetch.inc +++ b/tool/net/fetch.inc @@ -11,13 +11,13 @@ static int LuaFetch(lua_State *L) { #define ssl nope // TODO(jart): make this file less huge - char *p; ssize_t rc; bool usingssl; uint32_t ip; struct Url url; int t, ret, sock = -1, methodidx, hdridx; - char *host, *port, *request; + const char *host, *port; + char *request; struct TlsBio *bio; struct addrinfo *addr; struct Buffer inbuf; // shadowing intentional @@ -26,13 +26,13 @@ static int LuaFetch(lua_State *L) { const char *urlarg, *body, *method; char *conlenhdr = ""; char *headers = 0; - char *hosthdr = 0; - char *connhdr = 0; - char *agenthdr = brand; - char *key, *val, *hdr; + const char *hosthdr = 0; + const char *connhdr = 0; + const char *agenthdr = brand; + const char *key, *val, *hdr; size_t keylen, vallen; size_t urlarglen, requestlen, paylen, bodylen; - size_t i, g, n, hdrsize; + size_t i, g, hdrsize; int keepalive = kaNONE; int imethod, numredirects = 0, maxredirects = 5; bool followredirect = true; @@ -41,6 +41,9 @@ static int LuaFetch(lua_State *L) { .ai_protocol = IPPROTO_TCP, .ai_flags = AI_NUMERICSERV}; + (void)ret; + (void)usingssl; + /* * Get args: url [, body | {method = "PUT", body = "..."}] */ @@ -204,7 +207,7 @@ static int LuaFetch(lua_State *L) { url.host.p = 0, url.host.n = 0; url.port.p = 0, url.port.n = 0; if (!url.path.n || url.path.p[0] != '/') { - p = _gc(xmalloc(1 + url.path.n)); + void *p = _gc(xmalloc(1 + url.path.n)); mempcpy(mempcpy(p, "/", 1), url.path.p, url.path.n); url.path.p = p; ++url.path.n; @@ -258,6 +261,7 @@ static int LuaFetch(lua_State *L) { } } + (void)bio; #ifndef UNSECURE if (usingssl) { if (sslcliused) { diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index 5a57014ac..4470dc76f 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -358,7 +358,6 @@ int LuaBsf(lua_State *L) { } int LuaHighwayHash64(lua_State *L) { - long i; size_t n; uint64_t k[4]; const char *p; @@ -390,8 +389,8 @@ int LuaCrc32c(lua_State *L) { } int LuaIndentLines(lua_State *L) { - void *p; size_t n, j; + const void *p; if (!lua_isnoneornil(L, 1)) { p = luaL_checklstring(L, 1, &n); j = luaL_optinteger(L, 2, 1); @@ -399,9 +398,9 @@ int LuaIndentLines(lua_State *L) { luaL_argerror(L, 2, "not in range 0..65535"); __builtin_unreachable(); } - p = IndentLines(p, n, &n, j); - lua_pushlstring(L, p, n); - free(p); + char *q = IndentLines(p, n, &n, j); + lua_pushlstring(L, q, n); + free(q); return 1; } else { return lua_gettop(L); @@ -493,8 +492,8 @@ int LuaSlurp(lua_State *L) { // ├─→ true // └─→ nil, unix.Errno int LuaBarf(lua_State *L) { - char *data; ssize_t rc; + const char *data; lua_Number offset; size_t i, n, wrote; int fd, mode, flags, olderr; @@ -588,13 +587,14 @@ int LuaHasControlCodes(lua_State *L) { int LuaEncodeLatin1(lua_State *L) { int f; - char *p; + char *q; size_t n; + const char *p; p = luaL_checklstring(L, 1, &n); f = LuaCheckControlFlags(L, 2); - if ((p = EncodeLatin1(p, n, &n, f))) { - lua_pushlstring(L, p, n); - free(p); + if ((q = EncodeLatin1(p, n, &n, f))) { + lua_pushlstring(L, q, n); + free(q); return 1; } else { luaL_error(L, "out of memory"); @@ -659,11 +659,10 @@ int LuaGetHttpReason(lua_State *L) { int LuaGetCryptoHash(lua_State *L) { size_t hl, pl, kl; uint8_t d[64]; - mbedtls_md_context_t ctx; // get hash name, payload, and key - void *h = luaL_checklstring(L, 1, &hl); - void *p = luaL_checklstring(L, 2, &pl); - void *k = luaL_optlstring(L, 3, "", &kl); + const void *h = luaL_checklstring(L, 1, &hl); + const void *p = luaL_checklstring(L, 2, &pl); + const void *k = luaL_optlstring(L, 3, "", &kl); const mbedtls_md_info_t *digest = mbedtls_md_info_from_string(h); if (!digest) return luaL_argerror(L, 1, "unknown hash type"); if (kl == 0) { @@ -707,13 +706,14 @@ int LuaIsAcceptablePort(lua_State *L) { static dontinline int LuaCoderImpl(lua_State *L, char *C(const char *, size_t, size_t *)) { - void *p; + void *q; size_t n; + const void *p; if (!lua_isnoneornil(L, 1)) { p = luaL_checklstring(L, 1, &n); - if ((p = C(p, n, &n))) { - lua_pushlstring(L, p, n); - free(p); + if ((q = C(p, n, &n))) { + lua_pushlstring(L, q, n); + free(q); } else { luaL_error(L, "out of memory"); __builtin_unreachable(); @@ -782,12 +782,13 @@ int LuaEscapeFragment(lua_State *L) { } int LuaEscapeLiteral(lua_State *L) { - char *p, *q = 0; + const char *p; + char *z, *q = 0; size_t n, y = 0; p = luaL_checklstring(L, 1, &n); - if ((p = EscapeJsStringLiteral(&q, &y, p, n, &n))) { - lua_pushlstring(L, p, n); - free(q); + if ((z = EscapeJsStringLiteral(&q, &y, p, n, &n))) { + lua_pushlstring(L, z, n); + free(z); return 1; } else { luaL_error(L, "out of memory"); @@ -801,9 +802,9 @@ int LuaVisualizeControlCodes(lua_State *L) { static dontinline int LuaHasherImpl(lua_State *L, size_t k, int H(const void *, size_t, uint8_t *)) { - void *p; size_t n; uint8_t d[64]; + const void *p; if (!lua_isnoneornil(L, 1)) { p = luaL_checklstring(L, 1, &n); H(p, n, d); @@ -884,7 +885,7 @@ int LuaBenchmark(lua_State *L) { uint64_t t1, t2; int64_t interrupts; double avgticks, overhead; - int core, iter, count, tries, attempts, maxattempts; + int core, iter, count, attempts, maxattempts; luaL_checktype(L, 1, LUA_TFUNCTION); count = luaL_optinteger(L, 2, 100); maxattempts = luaL_optinteger(L, 3, 10); diff --git a/tool/net/lsqlite3.c b/tool/net/lsqlite3.c index d80bc0a24..e3d9bfda3 100644 --- a/tool/net/lsqlite3.c +++ b/tool/net/lsqlite3.c @@ -28,6 +28,7 @@ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/weirdtypes.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "third_party/lua/lauxlib.h" @@ -120,7 +121,6 @@ struct sdb { static const char *const sqlite_meta = ":sqlite3"; static const char *const sqlite_vm_meta = ":sqlite3:vm"; -static const char *const sqlite_bu_meta = ":sqlite3:bu"; static const char *const sqlite_ctx_meta = ":sqlite3:ctx"; static int sqlite_ctx_meta_ref; #ifdef SQLITE_ENABLE_SESSION @@ -1264,7 +1264,6 @@ static void db_update_hook_callback(void *user, int op, char const *dbname, char sdb *db = (sdb*)user; lua_State *L = db->L; int top = lua_gettop(L); - lua_Number n; /* setup lua callback call */ lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_cb); /* get callback */ @@ -1777,7 +1776,7 @@ static int db_deserialize(lua_State *L) { return 0; const char *sqlbuf = memcpy(sqlite3_malloc(size), buffer, size); - sqlite3_deserialize(db->db, "main", sqlbuf, size, size, + sqlite3_deserialize(db->db, "main", (void *)sqlbuf, size, size, SQLITE_DESERIALIZE_FREEONCLOSE + SQLITE_DESERIALIZE_RESIZEABLE); return 0; } @@ -1917,7 +1916,6 @@ static int liter_next(lua_State *L) { } static int liter_pk(lua_State *L) { - const char *zTab; int n, rc, nCol; unsigned char *abPK; liter *litr = lsqlite_checkiter(L, 1); @@ -2255,13 +2253,13 @@ static int db_create_session(lua_State *L) { static int db_iterate_changeset(lua_State *L) { sqlite3_changeset_iter *p; - sdb *db = lsqlite_checkdb(L, 1); + lsqlite_checkdb(L, 1); const char *cset = luaL_checkstring(L, 2); int nset = lua_rawlen(L, 2); int flags = luaL_optinteger(L, 3, 0); int rc; - if ((rc = sqlite3changeset_start_v2(&p, nset, cset, flags)) != SQLITE_OK) { + if ((rc = sqlite3changeset_start_v2(&p, nset, (void *)cset, flags)) != SQLITE_OK) { return pusherr(L, rc); } (void)lsqlite_makeiter(L, p, 1); @@ -2269,7 +2267,7 @@ static int db_iterate_changeset(lua_State *L) { } static int db_invert_changeset(lua_State *L) { - sdb *db = lsqlite_checkdb(L, 1); + lsqlite_checkdb(L, 1); const char *cset = luaL_checkstring(L, 2); int nset = lua_rawlen(L, 2); int rc; @@ -2285,7 +2283,7 @@ static int db_invert_changeset(lua_State *L) { } static int db_concat_changeset(lua_State *L) { - sdb *db = lsqlite_checkdb(L, 1); + lsqlite_checkdb(L, 1); int size, nset; void *buf, *cset; sqlite3_changegroup *pGrp; @@ -2295,7 +2293,7 @@ static int db_concat_changeset(lua_State *L) { int rc = sqlite3changegroup_new(&pGrp); for (int i = 1; rc == SQLITE_OK && i <= n; i++) { lua_rawgeti(L, 2, i); - cset = lua_tostring(L, -1); + cset = gc(strdup(lua_tostring(L, -1))); nset = lua_rawlen(L, -1); rc = sqlite3changegroup_add(pGrp, nset, cset); lua_pop(L, 1); // pop the string @@ -2311,7 +2309,7 @@ static int db_concat_changeset(lua_State *L) { static int db_apply_changeset(lua_State *L) { sdb *db = lsqlite_checkdb(L, 1); - const char *cset = luaL_checkstring(L, 2); + char *cset = gc(strdup(luaL_checkstring(L, 2))); int nset = lua_rawlen(L, 2); int top = lua_gettop(L); int rc; diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 89ae726e9..d216e7c76 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -51,6 +51,7 @@ #include "libc/math.h" #include "libc/mem/alloca.h" #include "libc/mem/gc.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/nt2sysv.h" @@ -139,6 +140,8 @@ #include "tool/net/luacheck.h" #include "tool/net/sandbox.h" +#pragma GCC diagnostic ignored "-Wunused-variable" + STATIC_STACK_SIZE(0x80000); __static_yoink("zipos"); @@ -440,7 +443,6 @@ static bool daemonize; static bool logrusage; static bool logbodies; static bool requiressl; -static bool isterminal; static bool sslcliused; static bool loglatency; static bool terminated; @@ -448,7 +450,6 @@ static bool uniprocess; static bool invalidated; static bool logmessages; static bool isinitialized; -static bool checkedmethod; static bool sslinitialized; static bool sslfetchverify; static bool selfmodifiable; @@ -465,7 +466,6 @@ static bool ishandlingrequest; static bool listeningonport443; static bool hasonprocesscreate; static bool hasonprocessdestroy; -static bool loggednetworkorigin; static bool ishandlingconnection; static bool hasonclientconnection; static bool evadedragnetsurveillance; @@ -486,6 +486,7 @@ static int sslticketlifetime; static uint32_t clientaddrsize; static atomic_int terminatemonitor; +static char *brand; static size_t zsize; static lua_State *GL; static lua_State *YL; @@ -493,25 +494,21 @@ static uint8_t *zmap; static uint8_t *zcdir; static size_t hdrsize; static size_t amtread; -static char *replstack; static reader_f reader; static writer_f writer; static char *extrahdrs; static const char *zpath; -static const char *brand; -static char *monitorstack; +static char *serverheader; static char gzip_footer[8]; static long maxpayloadsize; static const char *pidpath; static const char *logpath; static uint32_t *interfaces; -static const char *histpath; static struct pollfd *polls; static size_t payloadlength; static int64_t cacheseconds; -static const char *cachedirective; +static char *cachedirective; static const char *monitortty; -static const char *serverheader; static struct Strings stagedirs; static struct Strings hidepaths; static const char *launchbrowser; @@ -664,7 +661,7 @@ static char *MergePaths(const char *p, size_t n, const char *q, size_t m, } static long FindRedirect(const char *s, size_t n) { - int c, m, l, r, z; + int c, m, l, r; l = 0; r = redirects.n - 1; while (l <= r) { @@ -941,7 +938,6 @@ static bool IsTrustedIp(uint32_t ip) { static void DescribeAddress(char buf[40], uint32_t addr, uint16_t port) { char *p; - const char *s; p = buf; p = FormatUint32(p, (addr & 0xFF000000) >> 030), *p++ = '.'; p = FormatUint32(p, (addr & 0x00FF0000) >> 020), *p++ = '.'; @@ -965,7 +961,6 @@ static inline int GetClientAddr(uint32_t *ip, uint16_t *port) { } static inline int GetRemoteAddr(uint32_t *ip, uint16_t *port) { - char str[40]; GetClientAddr(ip, port); if (HasHeader(kHttpXForwardedFor)) { if (IsTrustedIp(*ip)) { @@ -1051,7 +1046,7 @@ static void ProgramTimeout(long ms) { static void ProgramCache(long x, const char *s) { cacheseconds = x; - if (s) cachedirective = s; + if (s) cachedirective = strdup(s); } static void SetDefaults(void) { @@ -1084,7 +1079,7 @@ static bool HasString(struct Strings *l, const char *s, size_t n) { return false; } -static const char *DEFAULTLUAPATH = "/zip/.lua/?.lua;/zip/.lua/?/init.lua"; +const char *DEFAULTLUAPATH = "/zip/.lua/?.lua;/zip/.lua/?/init.lua"; static void UpdateLuaPath(const char *s) { #ifndef STATIC @@ -1096,8 +1091,8 @@ static void UpdateLuaPath(const char *s) { lua_getglobal(L, "package"); if (lua_istable(L, -1)) { lua_getfield(L, -1, "path"); - curpath = luaL_optstring(L, -1, ""); - if (t = strstr(curpath, DEFAULTLUAPATH)) { + curpath = (void *)luaL_optstring(L, -1, ""); + if ((t = strstr(curpath, DEFAULTLUAPATH))) { // if the DEFAULT path is found, prepend the path in front of it respath = xasprintf("%.*s%s/.lua/?.lua;%s/.lua/?/init.lua;%s", t - curpath, curpath, s, s, t); @@ -1127,7 +1122,7 @@ static void ProgramDirectory(const char *path) { } static void ProgramHeader(const char *s) { - char *p, *v, *h; + char *p, *v; if ((p = strchr(s, ':')) && IsValidHttpToken(s, p - s) && (v = EncodeLatin1(p + 1, -1, 0, kControlC0 | kControlC1 | kControlWs))) { switch (GetHttpHeader(s, p - s)) { @@ -1202,7 +1197,7 @@ static void Daemonize(void) { umask(0); } -static void LogLuaError(char *hook, char *err) { +static void LogLuaError(const char *hook, const char *err) { ERRORF("(lua) failed to run %s: %s", hook, err); } @@ -1511,7 +1506,7 @@ static int TlsFlush(struct TlsBio *bio, const unsigned char *buf, size_t len) { if (len || bio->c > 0) { v[0].iov_base = bio->u; v[0].iov_len = MAX(0, bio->c); - v[1].iov_base = buf; + v[1].iov_base = (void *)buf; v[1].iov_len = len; if (WritevAll(bio->fd, v, 2) != -1) { if (bio->c > 0) bio->c = 0; @@ -1533,7 +1528,6 @@ static int TlsFlush(struct TlsBio *bio, const unsigned char *buf, size_t len) { static int TlsSend(void *ctx, const unsigned char *buf, size_t len) { int rc; - struct iovec v[2]; struct TlsBio *bio = ctx; if (bio->c >= 0 && bio->c + len <= sizeof(bio->u)) { memcpy(bio->u + bio->c, buf, len); @@ -1546,7 +1540,6 @@ static int TlsSend(void *ctx, const unsigned char *buf, size_t len) { static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { int r; - ssize_t s; struct iovec v[2]; struct TlsBio *bio = ctx; if ((r = TlsFlush(bio, 0, 0)) < 0) return r; @@ -1580,7 +1573,6 @@ static int TlsRecvImpl(void *ctx, unsigned char *p, size_t n, uint32_t o) { static int TlsRecv(void *ctx, unsigned char *buf, size_t len, uint32_t tmo) { int rc; - struct TlsBio *bio = ctx; if (oldin.n) { rc = MIN(oldin.n, len); memcpy(buf, oldin.p, rc); @@ -1711,7 +1703,6 @@ static void CertsDestroy(void) { } static void WipeServingKeys(void) { - size_t i; if (uniprocess) return; mbedtls_ssl_ticket_free(&ssltick); mbedtls_ssl_key_cert_free(conf.key_cert), conf.key_cert = 0; @@ -1906,9 +1897,8 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, const char *s; bool isduplicate; size_t i, j, k, nsan; - struct HostsTxt *htxt; struct mbedtls_san *san; - const mbedtls_x509_name *xname; + const struct HostsTxt *htxt; char *name, *subject, *issuer, notbefore[16], notafter[16], hbuf[256]; san = 0; nsan = 0; @@ -1922,7 +1912,7 @@ static void ConfigureCertificate(mbedtls_x509write_cert *cw, struct Cert *ca, if (ips.p[j] == READ32BE(htxt->entries.p[i].ip)) { isduplicate = false; s = htxt->strings.p + htxt->entries.p[i].name; - if (!name) name = s; + if (!name) name = (void *)s; for (k = 0; k < nsan; ++k) { if (san[k].tag == MBEDTLS_X509_SAN_DNS_NAME && !strcasecmp(s, san[k].val)) { @@ -2175,7 +2165,7 @@ static void IndexAssets(void) { hash = Hash(ZIP_CFILE_NAME(zmap + cf), ZIP_CFILE_NAMESIZE(zmap + cf)); step = 0; do { - i = (hash + (step * (step + 1)) >> 1) & (m - 1); + i = (hash + ((step * (step + 1)) >> 1)) & (m - 1); ++step; } while (p[i].hash); GetZipCfileTimestamps(zmap + cf, &lm, 0, 0, gmtoff); @@ -2193,8 +2183,8 @@ static void IndexAssets(void) { static bool OpenZip(bool force) { int fd; size_t n; + uint8_t *m, *d; struct stat st; - uint8_t *m, *d, *p; if (stat(zpath, &st) != -1) { if (force || st.st_ino != zst.st_ino || st.st_size > zst.st_size) { if (st.st_ino == zst.st_ino) { @@ -2241,7 +2231,7 @@ static struct Asset *GetAssetZip(const char *path, size_t pathlen) { if (pathlen > 1 && path[0] == '/') ++path, --pathlen; hash = Hash(path, pathlen); for (step = 0;; ++step) { - i = (hash + (step * (step + 1)) >> 1) & (assets.n - 1); + i = (hash + ((step * (step + 1)) >> 1)) & (assets.n - 1); if (!assets.p[i].hash) return NULL; if (hash == assets.p[i].hash && pathlen == ZIP_CFILE_NAMESIZE(zmap + assets.p[i].cf) && @@ -2275,7 +2265,6 @@ static struct Asset *GetAssetFile(const char *path, size_t pathlen) { } static struct Asset *GetAsset(const char *path, size_t pathlen) { - char *path2; struct Asset *a; if (!(a = GetAssetFile(path, pathlen))) { if (!(a = GetAssetZip(path, pathlen))) { @@ -2386,7 +2375,6 @@ static void *Deflate(const void *data, size_t size, size_t *out_size) { } static void *LoadAsset(struct Asset *a, size_t *out_size) { - int mode; size_t size; uint8_t *data; if (S_ISDIR(GetMode(a))) { @@ -2657,11 +2645,9 @@ static int LuaCallWithYield(lua_State *L) { static ssize_t DeflateGenerator(struct iovec v[3]) { int i, rc; size_t no; - void *res; - int level; i = 0; if (!dg.t) { - v[0].iov_base = kGzipHeader; + v[0].iov_base = (void *)kGzipHeader; v[0].iov_len = sizeof(kGzipHeader); ++dg.t; ++i; @@ -2713,7 +2699,6 @@ static ssize_t DeflateGenerator(struct iovec v[3]) { static char *ServeAssetCompressed(struct Asset *a) { char *p; - uint32_t crc; LockInc(&shared->c.deflates); LockInc(&shared->c.compressedresponses); DEBUGF("(srvr) ServeAssetCompressed()"); @@ -2739,7 +2724,6 @@ static char *ServeAssetCompressed(struct Asset *a) { static ssize_t InflateGenerator(struct iovec v[3]) { int i, rc; size_t no; - void *res; i = 0; if (!dg.t) { ++dg.t; @@ -2777,7 +2761,6 @@ static ssize_t InflateGenerator(struct iovec v[3]) { static char *ServeAssetDecompressed(struct Asset *a) { char *p; size_t size; - uint32_t crc; LockInc(&shared->c.inflates); LockInc(&shared->c.decompressedresponses); size = GetZipCfileUncompressedSize(zmap + a->cf); @@ -2853,12 +2836,13 @@ static char *ServeAssetRange(struct Asset *a) { } static char *GetAssetPath(uint8_t *zcf, size_t *out_size) { - char *p1, *p2; + char *p2; size_t n1, n2; + const char *p1; p1 = ZIP_CFILE_NAME(zcf); n1 = ZIP_CFILE_NAMESIZE(zcf); - p2 = xmalloc(1 + n1 + 1); n2 = 1 + n1 + 1; + p2 = xmalloc(n2); p2[0] = '/'; memcpy(p2 + 1, p1, n1); p2[1 + n1] = '\0'; @@ -2937,7 +2921,7 @@ static void LaunchBrowser(const char *path) { sigaction(SIGINT, &saveint, 0); sigaction(SIGQUIT, &savequit, 0); sigprocmask(SIG_SETMASK, &savemask, 0); - execv(prog, (char *const[]){prog, u, 0}); + execv(prog, (char *const[]){(char *)prog, (char *)u, 0}); _Exit(127); } while (wait4(pid, &ws, 0, 0) == -1) { @@ -2988,12 +2972,11 @@ static char *ServeListing(void) { int w[3]; uint8_t *zcf; struct tm tm; + char *p, *path; const char *and; - struct rusage ru; - char *p, *q, *path; struct timespec lastmod; + size_t n, pathlen, rn[6]; char rb[8], tb[20], *rp[6]; - size_t i, n, pathlen, rn[6]; LockInc(&shared->c.listingrequests); if (cpm.msg.method != kHttpGet && cpm.msg.method != kHttpHead) return BadMethod(); @@ -3272,7 +3255,7 @@ static char *ServeLua(struct Asset *a, const char *s, size_t n) { size_t codelen; lua_State *L = GL; LockInc(&shared->c.dynamicrequests); - effectivepath.p = s; + effectivepath.p = (void *)s; effectivepath.n = n; if ((code = FreeLater(LoadAsset(a, &codelen)))) { int status = @@ -3446,9 +3429,10 @@ static int LuaServeIndex(lua_State *L) { } static int LuaServeRedirect(lua_State *L) { - size_t loclen; - const char *location, *eval; int code; + char *eval; + size_t loclen; + const char *location; OnlyCallDuringRequest(L, "ServeRedirect"); code = luaL_checkinteger(L, 1); @@ -3639,16 +3623,15 @@ static void GetDosLocalTime(int64_t utcunixts, uint16_t *out_time, *out_date = DOS_DATE(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday + 1); } -static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen, - int mode) { +static void StoreAsset(const char *path, size_t pathlen, const char *data, + size_t datalen, int mode) { int64_t ft; - int i; uint32_t crc; char *comp, *p; struct timespec now; struct Asset *a; struct iovec v[13]; - uint8_t *cdir, era; + uint8_t era; const char *use; uint16_t gflags, iattrs, mtime, mdate, dosmode, method, disk; size_t oldcdirsize, oldcdiroffset, records, cdiroffset, cdirsize, complen, @@ -3722,10 +3705,10 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen, p = WRITE16LE(p, pathlen); p = WRITE16LE(p, v[2].iov_len); v[1].iov_len = pathlen; - v[1].iov_base = path; + v[1].iov_base = (void *)path; // file data v[3].iov_len = uselen; - v[3].iov_base = use; + v[3].iov_base = (void *)use; // old central directory entries oldcdirsize = GetZipCdirSize(zcdir); oldcdiroffset = GetZipCdirOffset(zcdir); @@ -3788,7 +3771,7 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen, p = WRITE16LE(p, mode); p = WRITE32LE(p, MIN(zsize, 0xffffffff)); v[7].iov_len = pathlen; - v[7].iov_base = path; + v[7].iov_base = (void *)path; // zip64 end of central directory cdiroffset = zsize + v[0].iov_len + v[1].iov_len + v[2].iov_len + v[3].iov_len; @@ -3817,7 +3800,7 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen, v[10].iov_base = 0; } // end of central directory - v[12].iov_base = GetZipCdirComment(zcdir); + v[12].iov_base = (void *)GetZipCdirComment(zcdir); v[12].iov_len = GetZipCdirCommentSize(zcdir); v[11].iov_base = p = alloca((v[11].iov_len = kZipCdirHdrMinSize)); p = WRITE32LE(p, kZipCdirHdrMagic); @@ -3836,11 +3819,11 @@ static void StoreAsset(char *path, size_t pathlen, char *data, size_t datalen, free(comp); } -static void StoreFile(char *path) { +static void StoreFile(const char *path) { char *p; - size_t plen, tlen; struct stat st; - char *target = path; + size_t plen, tlen; + const char *target = path; if (startswith(target, "./")) target += 2; tlen = strlen(target); if (!IsReasonablePath(target, tlen)) @@ -3857,8 +3840,9 @@ static void StorePath(const char *dirpath) { DIR *d; char *path; struct dirent *e; - if (!isdirectory(dirpath) && !endswith(dirpath, "/")) + if (!isdirectory(dirpath) && !endswith(dirpath, "/")) { return StoreFile(dirpath); + } if (!(d = opendir(dirpath))) FATALF("(cfg) error: can't open %`'s", dirpath); while ((e = readdir(d))) { if (strcmp(e->d_name, ".") == 0) continue; @@ -4137,10 +4121,9 @@ static int LuaGetUser(lua_State *L) { OnlyCallDuringRequest(L, "GetUser"); if (url.user.p) { LuaPushUrlView(L, &url.user); - } else if ((p = GetBasicAuthorization(&n))) { + } else if ((p = gc(GetBasicAuthorization(&n)))) { if (!(q = memchr(p, ':', n))) q = p + n; lua_pushlstring(L, p, q - p); - free(p); } else { lua_pushnil(L); } @@ -4153,13 +4136,12 @@ static int LuaGetPass(lua_State *L) { OnlyCallDuringRequest(L, "GetPass"); if (url.user.p) { LuaPushUrlView(L, &url.pass); - } else if ((p = GetBasicAuthorization(&n))) { + } else if ((p = gc(GetBasicAuthorization(&n)))) { if ((q = memchr(p, ':', n))) { lua_pushlstring(L, q + 1, p + n - (q + 1)); } else { lua_pushnil(L); } - free(p); } else { lua_pushnil(L); } @@ -4245,10 +4227,10 @@ static int LuaGetHeaders(lua_State *L) { static int LuaSetHeader(lua_State *L) { int h; - ssize_t rc; + char *eval; char *p, *q; - const char *key, *val, *eval; - size_t i, keylen, vallen, evallen; + const char *key, *val; + size_t keylen, vallen, evallen; OnlyCallDuringRequest(L, "SetHeader"); key = luaL_checklstring(L, 1, &keylen); val = luaL_optlstring(L, 2, 0, &vallen); @@ -4365,7 +4347,7 @@ static int LuaSetCookie(lua_State *L) { expires = FormatUnixHttpDateTime(FreeLater(xmalloc(30)), lua_tonumber(L, -1)); } else { - expires = lua_tostring(L, -1); + expires = (void *)lua_tostring(L, -1); if (!ParseHttpDateTime(expires, -1)) { luaL_argerror(L, 3, "invalid data format in Expires"); __builtin_unreachable(); @@ -4384,7 +4366,7 @@ static int LuaSetCookie(lua_State *L) { if (lua_getfield(L, 3, "samesite") == LUA_TSTRING || lua_getfield(L, 3, "SameSite") == LUA_TSTRING) { - samesite = lua_tostring(L, -1); // also used in the Secure check + samesite = (void *)lua_tostring(L, -1); // also used in the Secure check appends(&buf, "; SameSite="); appends(&buf, samesite); } @@ -4588,7 +4570,7 @@ static int LuaProgramBrand(lua_State *L) { static int LuaProgramDirectory(lua_State *L) { struct stat st; - char *path = luaL_checkstring(L, 1); + const char *path = luaL_checkstring(L, 1); // check to raise a Lua error, to allow it to be handled if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { return luaL_argerror(L, 1, "not a directory"); @@ -4637,7 +4619,7 @@ static int LuaProgramSslPresharedKey(lua_State *L) { } static int LuaProgramSslCiphersuite(lua_State *L) { - mbedtls_ssl_ciphersuite_t *suite; + const mbedtls_ssl_ciphersuite_t *suite; OnlyCallFromInitLua(L, "ProgramSslCiphersuite"); if (!(suite = GetCipherSuite(luaL_checkstring(L, 1)))) { luaL_argerror(L, 1, "unsupported or unknown ciphersuite"); @@ -4741,7 +4723,7 @@ static int LuaGetZipPaths(lua_State *L) { char *path; uint8_t *zcf; size_t i, n, pathlen, prefixlen; - char *prefix = luaL_optlstring(L, 1, "", &prefixlen); + const char *prefix = luaL_optlstring(L, 1, "", &prefixlen); lua_newtable(L); i = 0; n = GetZipCdirRecords(zcdir); @@ -4977,13 +4959,13 @@ static int LuaProgramTokenBucket(lua_State *L) { } static const char *GetContentTypeExt(const char *path, size_t n) { - char *r, *e; + const char *r, *e; int top; lua_State *L = GL; if ((r = FindContentType(path, n))) return r; // extract the last .; use the entire path if none is present - if (e = strrchr(path, '.')) path = e + 1; + if ((e = strrchr(path, '.'))) path = e + 1; top = lua_gettop(L); lua_pushlightuserdata(L, (void *)&ctIdx); // push address as unique key CHECK_EQ(lua_gettable(L, LUA_REGISTRYINDEX), LUA_TTABLE); @@ -5055,7 +5037,7 @@ static bool LuaRunAsset(const char *path, bool mandatory) { if ((a = GetAsset(path, pathlen))) { if ((code = FreeLater(LoadAsset(a, &codelen)))) { lua_State *L = GL; - effectivepath.p = path; + effectivepath.p = (void *)path; effectivepath.n = pathlen; DEBUGF("(lua) LuaRunAsset(%`'s)", path); status = luaL_loadbuffer( @@ -5420,7 +5402,6 @@ static void HandleCompletions(const char *p, linenoiseCompletions *c) { static void LuaPrint(lua_State *L) { int i, n; char *b = 0; - const char *s; n = lua_gettop(L); if (n > 0) { for (i = 1; i <= n; i++) { @@ -5529,6 +5510,7 @@ static void MemDestroy(void) { Free(&cpm.outbuf); FreeStrings(&stagedirs); FreeStrings(&hidepaths); + Free(&cachedirective); Free(&launchbrowser); Free(&serverheader); Free(&trustedips.p); @@ -5608,7 +5590,7 @@ static ssize_t SendString(const char *s) { ssize_t rc; struct iovec iov; n = strlen(s); - iov.iov_base = s; + iov.iov_base = (void *)s; iov.iov_len = n; if (logmessages) { LogMessage("sending", s, n); @@ -5776,7 +5758,6 @@ static void HandleReload(void) { static void HandleHeartbeat(void) { size_t i; - sigset_t mask; UpdateCurrentDate(timespec_real()); Reindex(); getrusage(RUSAGE_SELF, &shared->server); @@ -6062,7 +6043,6 @@ static char *Route(const char *host, size_t hostlen, const char *path, static char *RoutePath(const char *path, size_t pathlen) { int m; long r; - char *p; struct Asset *a; DEBUGF("(srvr) RoutePath(%`'.*s)", pathlen, path); if ((a = GetAsset(path, pathlen))) { @@ -6166,7 +6146,6 @@ static bool IsNotModified(struct Asset *a) { static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) { char *p; - uint32_t crc; const char *ct; ct = GetContentType(a, path, pathlen); if (IsNotModified(a)) { @@ -6274,7 +6253,7 @@ static bool TransmitResponse(char *p) { iovlen = 1; if (!MustNotIncludeMessageBody()) { if (cpm.gzipped) { - iov[iovlen].iov_base = kGzipHeader; + iov[iovlen].iov_base = (void *)kGzipHeader; iov[iovlen].iov_len = sizeof(kGzipHeader); ++iovlen; } @@ -6438,10 +6417,10 @@ static bool IsSsl(unsigned char c) { } static void HandleMessages(void) { - char *p; bool once; ssize_t rc; size_t got; + (void)once; for (once = false;;) { InitRequest(); startread = timespec_real(); @@ -6607,14 +6586,14 @@ static int MemoryMonitor(void *arg, int tid) { static struct termios oldterm; static int tty; sigset_t ss; - bool done, ok; + bool ok; size_t intervals; struct winsize ws; unsigned char rez; struct termios term; - char *b, *addr, title[128]; + char *b, *addr; struct MemoryInterval *mi, *mi2; - long i, j, k, n, x, y, pi, gen, pages; + long i, j, gen, pages; int rc, id, color, color2, workers; id = atomic_load_explicit(&shared->workers, memory_order_relaxed); DEBUGF("(memv) started for pid %d on tid %d", getpid(), gettid()); @@ -6689,7 +6668,7 @@ static int MemoryMonitor(void *arg, int tid) { appendr(&b, 0); appends(&b, "\e[H\e[1m"); - for (pi = k = x = y = i = 0; i < intervals; ++i) { + for (i = 0; i < intervals; ++i) { addr = (char *)((int64_t)((uint64_t)mi[i].x << 32) >> 16); color = 0; appendf(&b, "\e[0m%lx", addr); @@ -6934,8 +6913,6 @@ static int HandleConnection(size_t i) { static void MakeExecutableModifiable(void) { #ifdef __x86_64__ int ft; - size_t n; - extern char ape_rom_vaddr[] __attribute__((__weak__)); if (!(SUPPORT_VECTOR & (_HOSTMETAL | _HOSTWINDOWS | _HOSTXNU))) return; if (IsWindows()) return; // TODO if (IsOpenbsd()) return; // TODO @@ -7253,8 +7230,8 @@ static void TlsInit(void) { } mbedtls_ssl_set_bio(&ssl, &g_bio, TlsSend, 0, TlsRecv); conf.disable_compression = confcli.disable_compression = true; - DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&conf, kAlpn)); - DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&confcli, kAlpn)); + DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&conf, (void *)kAlpn)); + DCHECK_EQ(0, mbedtls_ssl_conf_alpn_protocols(&confcli, (void *)kAlpn)); DCHECK_EQ(0, mbedtls_ssl_setup(&ssl, &conf)); DCHECK_EQ(0, mbedtls_ssl_setup(&sslcli, &confcli)); #endif diff --git a/tool/net/wb.c b/tool/net/wb.c index 14a36004d..99f3114d4 100644 --- a/tool/net/wb.c +++ b/tool/net/wb.c @@ -170,17 +170,13 @@ static wontreturn void PrintUsage(FILE *f, int rc) { } int fetch(void) { - char *p; int status; ssize_t rc; - const char *body; int t, ret, sock; - struct TlsBio *bio; long messagesremaining; struct HttpMessage msg; struct HttpUnchunker u; - size_t urlarglen, requestlen; - size_t g, i, n, hdrsize, paylen; + size_t g, n, hdrsize, paylen; messagesremaining = messagesperconnection; @@ -188,7 +184,7 @@ int fetch(void) { * Setup crypto. */ if (usessl) { - -mbedtls_ssl_session_reset(&ssl); + mbedtls_ssl_session_reset(&ssl); CHECK_EQ(0, mbedtls_ssl_set_hostname(&ssl, host)); } diff --git a/tool/plinko/lib/bind.c b/tool/plinko/lib/bind.c index eef2f6d61..e388b7eae 100644 --- a/tool/plinko/lib/bind.c +++ b/tool/plinko/lib/bind.c @@ -20,7 +20,7 @@ #include "tool/plinko/lib/plinko.h" struct Binding Bind(int x, int y, int a, int u, dword p1, dword p2) { - int k, v, w; + int k, v; dword a1 = 0; while (x) { if (x < 0) { diff --git a/tool/plinko/lib/cons.c b/tool/plinko/lib/cons.c index 64cffce98..ce8a6763a 100644 --- a/tool/plinko/lib/cons.c +++ b/tool/plinko/lib/cons.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "tool/plinko/lib/char.h" #include "tool/plinko/lib/cons.h" +#include "tool/plinko/lib/char.h" int List(int x, int y) { return Cons(x, Cons(y, -0)); @@ -47,8 +47,7 @@ int GetCommonCons(int x, int y) { } int ShareCons(int x, int y) { - dword t; - int i, n; + int i; if ((i = GetCommonCons(x, y))) return i; #if 0 t = MAKE(x, y); diff --git a/tool/plinko/lib/dispatchycombine.c b/tool/plinko/lib/dispatchycombine.c index dfcd4012f..1943455dc 100644 --- a/tool/plinko/lib/dispatchycombine.c +++ b/tool/plinko/lib/dispatchycombine.c @@ -46,7 +46,7 @@ struct T DispatchRecur2(dword ea, dword tm, dword r, dword p1, dword p2, struct T DispatchYcombine(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { - int ycomb, z, u, t, p, b, name, lambda, closure; + int ycomb, p, name, lambda, closure; SetFrame(r, LO(ea)); r |= NEED_GC; ycomb = recurse(MAKE(Car(LO(ea)), HI(ea)), p1, p2); diff --git a/tool/plinko/lib/enclose.c b/tool/plinko/lib/enclose.c index 5c51f61c0..07cc2df6d 100644 --- a/tool/plinko/lib/enclose.c +++ b/tool/plinko/lib/enclose.c @@ -69,8 +69,6 @@ static void CheckClosure(int e, int a) { } int Enclose(int e, int a) { - int x; - dword w; CheckClosure(e, a); return Cons(kClosure, Cons(e, a)); } diff --git a/tool/plinko/lib/gc.c b/tool/plinko/lib/gc.c index a3d8df3fa..84f8efc97 100644 --- a/tool/plinko/lib/gc.c +++ b/tool/plinko/lib/gc.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/plinko/lib/gc.h" #include "libc/assert.h" #include "libc/intrin/bsf.h" #include "libc/intrin/popcnt.h" @@ -27,7 +28,6 @@ #include "libc/mem/mem.h" #include "libc/str/str.h" #include "tool/plinko/lib/cons.h" -#include "tool/plinko/lib/gc.h" #include "tool/plinko/lib/histo.h" #include "tool/plinko/lib/plinko.h" #include "tool/plinko/lib/print.h" @@ -66,7 +66,7 @@ void Marker(const dword M[], int A, int x) { do { i = ~(x - A); if (HasBit(M, i)) return; - SetBit(M, i); + SetBit((void *)M, i); if (HI(GetShadow(x)) < A) { Marker(M, A, HI(GetShadow(x))); } diff --git a/tool/plinko/lib/isdelegate.c b/tool/plinko/lib/isdelegate.c index b0ba017e3..7f3f3fc2b 100644 --- a/tool/plinko/lib/isdelegate.c +++ b/tool/plinko/lib/isdelegate.c @@ -44,7 +44,6 @@ int IsDelegate(int x_) { if (ddx_ >= 0) return 0; w_ = Get(ddx_); // ((F . V) . Q) int addx_ = LO(w_); - int dddx_ = HI(w_); if (addx_ >= 0) return 0; w_ = Get(addx_); // (F . V) int aaddx_ = LO(w_); diff --git a/tool/plinko/lib/isycombinator.c b/tool/plinko/lib/isycombinator.c index 9ddebec88..83ce076ab 100644 --- a/tool/plinko/lib/isycombinator.c +++ b/tool/plinko/lib/isycombinator.c @@ -42,7 +42,6 @@ bool IsYcombinator(int x_) { if (dx_ >= 0) return false; w_ = Get(dx_); // ((λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) . Q) int adx_ = LO(w_); - int ddx_ = HI(w_); if (adx_ >= 0) return false; w_ = Get(adx_); // (λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) int aadx_ = LO(w_); diff --git a/tool/plinko/lib/plan.c b/tool/plinko/lib/plan.c index da9816c57..588e12a01 100644 --- a/tool/plinko/lib/plan.c +++ b/tool/plinko/lib/plan.c @@ -96,7 +96,7 @@ static dword PlanLambda(int e, int a, int s) { } static dword PlanCond(int e, int a, int s) { - int x, b; + int x; if (!Cdr(e)) return DF(DispatchNil); // (ζ) ⟺ ⊥ for (x = e; (x = Cdr(x));) { if (x > 0) React(e, e, kCond); // (ζ . 𝑣) not allowed @@ -107,7 +107,6 @@ static dword PlanCond(int e, int a, int s) { } static dword PlanProgn(int e, int a, int s) { - int x; if (!Cdr(e)) return DF(DispatchNil); // (progn) ⟺ ⊥ if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kProgn); return MAKE(DF(DispatchProgn), Cdr(e)); @@ -216,7 +215,7 @@ static dword PlanClosure(int e, int a, int s) { } static dword PlanLet(int e, int a, int s) { - int p, n; + int n; if ((n = CountSimpleArguments(Cdr(e))) == -1) return DF(DispatchFuncall); if (CountSimpleArguments(Car(e)) < 3) React(e, e, kLambda); // need (λ 𝑥 𝑦) switch (CountSimpleParameters(Cadr(Car(e)))) { @@ -234,7 +233,6 @@ static dword PlanLet(int e, int a, int s) { } static dontinline dword PlanPrecious(int e, int a, int s, int f) { - int x; DCHECK_GT(f, 0); if (f == kCar) return PlanCar(e, a, s); if (f == kCdr) return PlanCdr(e, a, s); diff --git a/tool/plinko/lib/plinko.c b/tool/plinko/lib/plinko.c index dae84368e..dec9f75a1 100644 --- a/tool/plinko/lib/plinko.c +++ b/tool/plinko/lib/plinko.c @@ -168,7 +168,7 @@ static int QuoteList(int x) { } static int GetAtom(const char *s) { - int x, y, t, u; + int x, y; ax = y = TERM; x = *s++ & 255; if (*s) y = GetAtom(s); @@ -532,7 +532,7 @@ struct T DispatchIf(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { bool b; - int x, e, A; + int e; e = LO(ea); SetFrame(r, e); b = literally; @@ -545,7 +545,6 @@ struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2, struct T DispatchFlush(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { - int x, A; SetFrame(r, LO(ea)); Flush(1); return Ret(MAKE(kIgnore0, 0), tm, r); @@ -794,15 +793,11 @@ Delegate: struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { - int a, b, e, f, t, u, y, p, z; + int b, e, u, y, p; e = LO(ea); - a = HI(ea); DCHECK_LT(e, 0); SetFrame(r, e); - f = Car(e); - z = Cdr(e); y = HI(d); - t = Car(y); // (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏) y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏) u = Cdr(y); // 𝑏 @@ -816,15 +811,11 @@ struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2, struct T DispatchCall2(dword ea, dword tm, dword r, dword p1, dword p2, dword d) { - int a, b, e, f, t, u, y, p, z; + int b, e, u, y, p; e = LO(ea); - a = HI(ea); DCHECK_LT(e, 0); SetFrame(r, e); - f = Car(e); - z = Cdr(e); y = HI(d); - t = Car(y); // (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏) y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏) u = Cdr(y); // 𝑏 @@ -878,7 +869,7 @@ static void PrintStats(long usec) { -cHeap - -cFrost, usec, cGets, cSets, cAtoms, -cFrost); } -static wontreturn Exit(void) { +static wontreturn int Exit(void) { exit(0 <= fails && fails <= 255 ? fails : 255); } @@ -903,9 +894,8 @@ static wontreturn void PrintUsage(void) { } int Plinko(int argc, char *argv[]) { - long *p; + int S, x; bool trace; - int S, x, u, j; uint64_t t1, t2; tick = kStartTsc; #ifndef NDEBUG diff --git a/tool/plinko/lib/prettyprint.c b/tool/plinko/lib/prettyprint.c index 60fa738fa..eb985ed92 100644 --- a/tool/plinko/lib/prettyprint.c +++ b/tool/plinko/lib/prettyprint.c @@ -23,7 +23,7 @@ #include "tool/plinko/lib/tree.h" static void PrettyPrintList(int fd, int x, int n) { - int i, y, once, func, mode, argwidth, funcwidth, forcedot; + int y, once, func, mode, argwidth, funcwidth, forcedot; DCHECK_GE(n, 0); DCHECK_LE(x, 0); if (x < cx) { diff --git a/tool/plinko/lib/printf.c b/tool/plinko/lib/printf.c index 46175333a..8026b1309 100644 --- a/tool/plinko/lib/printf.c +++ b/tool/plinko/lib/printf.c @@ -32,7 +32,7 @@ static inline long GetVarInt(va_list va, signed char t) { } static int PrintStr(int fd, const char *s, int cols) { - int n, j, k = 0, i = 0; + int n, k = 0, i = 0; n = strlen(s); k += PrintIndent(fd, +cols - n); while (i < n) k += PrintChar(fd, s[i++]); @@ -77,7 +77,7 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) { const char *s; signed char type; char quot, ansi, gotr, pdot, zero; - int b, c, i, x, y, si, prec, cols, sign; + int b, c, x, y, si, prec, cols, sign; gotr = false; t = rdtsc(); ftrace_enabled(-1); diff --git a/tool/plinko/lib/read.c b/tool/plinko/lib/read.c index 468989a89..6cd6d2afd 100644 --- a/tool/plinko/lib/read.c +++ b/tool/plinko/lib/read.c @@ -98,8 +98,7 @@ dontinstrument int ReadChar(int fd) { } static int ReadListItem(int fd, int closer, int f(int)) { - int i, n, x, y; - dword t; + int x, y; if ((x = f(fd)) > 0) { if (Get(x) == MAKE(closer, TERM)) return -0; if (Get(x) == MAKE(L'.', TERM)) { @@ -123,7 +122,7 @@ static int ReadList(int fd, int closer) { static int TokenizeInteger(int fd, int b) { dword a; - int c, i, x, y; + int c, i; for (i = a = 0;; ++i) { if ((c = GetDiglet(ToUpper(dx))) != -1 && c < b) { a = (a * b) + c; @@ -146,7 +145,7 @@ static void ConsumeComment(int fd) { } static int ReadAtomRest(int fd, int x) { - int y, t, u; + int y; ax = y = TERM; if (x == L'\\') x = ReadChar(fd); if (!IsSpace(dx) && !IsParen(dx) && !IsMathAlnum(x) && !IsMathAlnum(dx)) { @@ -194,7 +193,7 @@ static int TokenizeComplicated(int fd) { } static int Read2(int fd) { - int r, f, t, l; + int r, l; while (IsSpace((l = dx))) ReadChar(fd); switch (dx) { case L'#': diff --git a/tool/plinko/lib/trace.c b/tool/plinko/lib/trace.c index 19d69c570..39d75fdb9 100644 --- a/tool/plinko/lib/trace.c +++ b/tool/plinko/lib/trace.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/plinko/lib/trace.h" #include "tool/plinko/lib/plinko.h" #include "tool/plinko/lib/printf.h" -#include "tool/plinko/lib/trace.h" void EnableTracing(void) { eval = EvalTrace; @@ -112,7 +112,7 @@ static relegated int Trace(int e, int a, EvalFn *f, bool p(int), const char *s, } relegated int RecurseTrace(dword ea, dword p1, dword p2) { - int r, d, S = sp; + int r; const char *s = "Recurse"; const unsigned short c[5] = u"╔═║╚═"; if (depth < ARRAYLEN(g_depths)) { @@ -143,7 +143,7 @@ relegated int RecurseTrace(dword ea, dword p1, dword p2) { } relegated int EvlisTrace(int e, int a, dword p1, dword p2) { - int r, d, S = sp; + int r, d; const char *s = "Evlis"; const unsigned short c[5] = u"╒─┆╘─"; DCHECK_GE(depth, -1); @@ -177,7 +177,7 @@ relegated int EvlisTrace(int e, int a, dword p1, dword p2) { relegated int Trace3(int x, int y, int a, PairFn *f, const char *s, const unsigned short c[5]) { - int r, d, S = sp; + int r; if (depth < ARRAYLEN(g_depths)) { if (loga) { Fprintf(2, "%I%c%c%s[x=%S; y=%S; a=%S] δ %'Rns%n", c[0], c[1], s, @@ -198,7 +198,6 @@ relegated int Trace3(int x, int y, int a, PairFn *f, const char *s, relegated struct Binding BindTrace(int x, int y, int a, int u, dword p1, dword p2) { - int d, S = sp; struct Binding r; if (depth < ARRAYLEN(g_depths)) { if (loga) { diff --git a/tool/plinko/lib/trace.h b/tool/plinko/lib/trace.h index 9f68a381a..f6f735bde 100644 --- a/tool/plinko/lib/trace.h +++ b/tool/plinko/lib/trace.h @@ -10,7 +10,6 @@ COSMOPOLITAN_C_START_ BindFn *bf; \ EvlisFn *ef; \ RecurseFn *rf; \ - unsigned char mo; \ TailFn *tails[8]; \ EvalFn *ev, *ex; \ memcpy(tails, kTail, sizeof(kTail)); \ diff --git a/tool/plinko/lib/tree.c b/tool/plinko/lib/tree.c index cc47482d8..249a3e3fd 100644 --- a/tool/plinko/lib/tree.c +++ b/tool/plinko/lib/tree.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/plinko/lib/tree.h" #include "libc/log/check.h" #include "tool/plinko/lib/index.h" -#include "tool/plinko/lib/tree.h" int Nod(int E, int L, int R, int C) { #ifndef NDEBUG @@ -30,7 +30,7 @@ int Nod(int E, int L, int R, int C) { } static void CheckTreeImpl(int N) { - int p, e, L, R; + int p, L, R; if (N >= 0) Error("N is atom: %S", N); if (Car(N) >= 0) Error("Car(N) is an atom: %S", N); if (Cdr(N) & ~1) Error("Cdr(N) is non-bool: %S", N); @@ -229,7 +229,7 @@ int PutTree(int E, int N, int KEEP) { * @return ((𝑒 𝑙 . 𝑟) . 𝑐) if found, otherwise 0 */ int GetTree(int k, int N) { - int p, e; + int p; while (N) { p = Cmp(k, Key(Ent(N))); if (p < 0) { @@ -244,7 +244,7 @@ int GetTree(int k, int N) { } int GetTreeCount(int k, int N, int *c) { - int p, e; + int p; while (N) { ++*c; p = Cmp(k, Key(Ent(N))); diff --git a/tool/viz/deathstar.c b/tool/viz/deathstar.c index ac496ec85..5c09971b0 100644 --- a/tool/viz/deathstar.c +++ b/tool/viz/deathstar.c @@ -121,7 +121,6 @@ static void DrawSphere(double k, double ambient) { int main() { double ang; - struct termios old; WRITE("\e[?25l"); if (!setjmp(jb_)) { signal(SIGINT, OnCtrlC); diff --git a/tool/viz/derasterize.c b/tool/viz/derasterize.c index f40c58669..4326117c5 100644 --- a/tool/viz/derasterize.c +++ b/tool/viz/derasterize.c @@ -497,8 +497,9 @@ static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn, CHECK_NE(-1, pipe2(pipefds, O_CLOEXEC)); if (!(pid = vfork())) { dup2(pipefds[1], 1); - execv(convert, (char *const[]){"convert", path, "-resize", dim, "-depth", - "8", "-colorspace", "sRGB", "rgb:-", NULL}); + execv(convert, + (char *const[]){"convert", (char *)path, "-resize", dim, "-depth", + "8", "-colorspace", "sRGB", "rgb:-", NULL}); abort(); } CHECK_NE(-1, close(pipefds[1])); @@ -510,8 +511,7 @@ static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn, static void LoadFile(const char *path, size_t yn, size_t xn, void *rgb) { struct stat st; - size_t data2size, data3size; - void *map, *data, *data2, *data3; + void *map, *data; int fd, gotx, goty, channels_in_file; CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path); CHECK_NE(-1, fstat(fd, &st)); @@ -585,7 +585,6 @@ int main(int argc, char *argv[]) { int i; void *rgb; size_t size; - char *option; unsigned yd, xd; ShowCrashReports(); GetOpts(argc, argv); diff --git a/tool/viz/fontspace.c b/tool/viz/fontspace.c index 42086072d..f43dcda14 100644 --- a/tool/viz/fontspace.c +++ b/tool/viz/fontspace.c @@ -63,12 +63,11 @@ int main(int argc, char *argv[]) { float scale; void *bitmap; size_t ttfsize; - const char *dir; unsigned char *ttf; stbtt_fontinfo font; unsigned char *present; unsigned char *intotal; - int w, h, i, j, c, arg, opt, errs, line, count, maxcode, s = 40 * 4, rc = 0; + int w, h, i, c, arg, opt, errs, line, s = 40 * 4, rc = 0; ShowCrashReports(); tcgetwinsize(0, &ws); while ((opt = getopt(argc, argv, "vs:e:")) != -1) { @@ -103,7 +102,7 @@ int main(int argc, char *argv[]) { continue; } bzero(present, m); - for (maxcode = errs = 0, c = start; c <= end; ++c) { + for (errs = 0, c = start; c <= end; ++c) { if (!(line = setjmp(stbtt_jmpbuf))) { if ((i = stbtt_FindGlyphIndex(&font, c)) > 0) { w = h = 0; @@ -111,7 +110,6 @@ int main(int argc, char *argv[]) { bitmap = stbtt_GetGlyphBitmap(&font, 0, scale, i, &w, &h, 0, 0); if (w && h) { intotal[c - start] = present[c - start] = 255; - maxcode = c; } free(bitmap); } diff --git a/tool/viz/getglyph.c b/tool/viz/getglyph.c index cde255886..d9c6d0f5d 100644 --- a/tool/viz/getglyph.c +++ b/tool/viz/getglyph.c @@ -104,7 +104,6 @@ int main(int argc, char *argv[]) { char **rasters; char **fasters; size_t ttfsize; - const char *dir; bool isdifferent; unsigned char **ttf; stbtt_fontinfo *font; diff --git a/tool/viz/lib/bilinearscale.c b/tool/viz/lib/bilinearscale.c index bbaefaf54..86c581538 100644 --- a/tool/viz/lib/bilinearscale.c +++ b/tool/viz/lib/bilinearscale.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/viz/lib/bilinearscale.h" #include "dsp/core/twixt8.h" #include "libc/intrin/bsr.h" #include "libc/log/check.h" @@ -29,7 +30,6 @@ #include "libc/testlib/testlib.h" #include "libc/tinymath/emod.h" #include "libc/x/x.h" -#include "tool/viz/lib/bilinearscale.h" static void ComputeScalingSolution(long dn, long sn, double r, double o, unsigned char pct[dn + 1], int idx[dn + 1]) { @@ -52,7 +52,7 @@ static void BilinearScaler(long dcw, long dyw, long dxw, int iy[dyn + 1], unsigned char py[dyn + 1], int ix[dxn + 1], unsigned char px[dxn + 1], unsigned char db[dxn], unsigned char sb[2][sxn]) { - long c, y, x, b; + long c, y, x; ComputeScalingSolution(dxn, sxn, rx, ox, px, ix); ComputeScalingSolution(dyn, syn, ry, oy, py, iy); for (c = c0; c < cn; ++c) { diff --git a/tool/viz/lib/dither.c b/tool/viz/lib/dither.c index afb7bd645..603dc3993 100644 --- a/tool/viz/lib/dither.c +++ b/tool/viz/lib/dither.c @@ -90,15 +90,14 @@ static void SerpentineDither(long yw, long xw, unsigned char rgb[3][yw][xw], long yn, long xn, long y, long x, long r, const struct Dither *d) { void *c; - long b, e, i, j, n, m; - e = 0; + long b, i, j, n, m; b = d->chunks[r].b; c = d->chunks[r].c; n = (yn - y) / b; m = (xn - x) / b; for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) { - e = SerpentineDitherSq2(yw, xw, rgb, y + i * b, x + j * b, b, c, 0); + SerpentineDitherSq2(yw, xw, rgb, y + i * b, x + j * b, b, c, 0); } } if (r) { diff --git a/tool/viz/lib/formatmatrix-double.c b/tool/viz/lib/formatmatrix-double.c index 65e839146..00170e0f1 100644 --- a/tool/viz/lib/formatmatrix-double.c +++ b/tool/viz/lib/formatmatrix-double.c @@ -20,8 +20,8 @@ #include "libc/fmt/conv.h" #include "libc/log/check.h" #include "libc/math.h" -#include "libc/mem/mem.h" #include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/x/x.h" #include "third_party/gdtoa/gdtoa.h" #include "tool/viz/lib/formatstringtable.h" @@ -30,14 +30,13 @@ void *ConvertMatrixToStringTable(long yn, long xn, char *T[yn][xn], const double M[yn][xn], double digs, double rounder(double)) { - double f; long y, x; assert(yn && xn && !T[0][0]); for (y = 0; y < yn; ++y) { for (x = 0; x < xn; ++x) { T[y][x] = xmalloc(40); T[y][x][0] = '\0'; - g_dfmt_p(T[y][x], &M[y][x], digs, 40, 0); + g_dfmt_p(T[y][x], (void *)&M[y][x], digs, 40, 0); } } return T; diff --git a/tool/viz/lib/ycbcr2rgb3.c b/tool/viz/lib/ycbcr2rgb3.c index 66e013139..37354299d 100644 --- a/tool/viz/lib/ycbcr2rgb3.c +++ b/tool/viz/lib/ycbcr2rgb3.c @@ -237,7 +237,7 @@ void YCbCr2Rgb(long yn, long xn, unsigned char RGB[restrict 3][yn][xn], const unsigned char Cr[restrict cys][cxs], const int K[8][4], const int L[6][4], const unsigned char T[256]) { long i, j; - short y, u, v, r, g, b, A, B, C; + short y, u, v, r, g, b; for (i = 0; i < yn; ++i) { for (j = 0; j < xn; ++j) { y = T[Y[i][j]]; @@ -280,8 +280,8 @@ void YCbCr2RgbScaler(struct YCbCr *me, long dyn, long dxn, long cyn, long cxn, double syn, double sxn, double pry, double prx) { long double ts; - long y, x, scyn, scxn; - double yry, yrx, cry, crx, yoy, yox, coy, cox, err, oy; + long scyn, scxn; + double yry, yrx, cry, crx, yoy, yox, coy, cox; scyn = syn * cyn / yyn; scxn = sxn * cxn / yxn; if (HALF(yxn) > dxn && HALF(scxn) > dxn) { diff --git a/tool/viz/life.c b/tool/viz/life.c index 03d874e34..ed998c0a1 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -572,7 +572,7 @@ static int GetChar(FILE *f) { static int LoadFile(const char *path) { FILE *f; - long c, y, x, i, j, n, yn, xn, yo, xo; + long c, y, x, i, n, yn, xn, yo, xo; line = 0; f = fopen(path, "r"); if (GetChar(f) != 'x') goto ReadError; @@ -1295,7 +1295,7 @@ static void OnWindowRbuttonup(int64_t hwnd, int64_t wParam, int64_t lParam) { } static void OnWindowMousemove(int64_t hwnd, int64_t wParam, int64_t lParam) { - int y, x, by, bx; + int y, x; y = (lParam & 0xFFFF0000) >> 020; x = (lParam & 0x0000FFFF) >> 000; if (wParam & kNtMkLbutton) { diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index f72da79a6..d2d2b4420 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -261,7 +261,6 @@ static void SetExtent(long lo, long hi) { } static void Open(void) { - int err; if ((fd = open(path, O_RDONLY)) == -1) { FailPath("open() failed", errno); } diff --git a/tool/viz/printansi.c b/tool/viz/printansi.c index ec82c3313..8e26c8885 100644 --- a/tool/viz/printansi.c +++ b/tool/viz/printansi.c @@ -320,7 +320,7 @@ static void ProcessImage(long yn, long xn, unsigned char RGB[3][yn][xn]) { void WithImageFile(const char *path, void fn(long yn, long xn, unsigned char RGB[3][yn][xn])) { struct stat st; - void *map, *data, *data2; + void *map, *data; int fd, yn, xn, cn, dyn, dxn, syn, sxn; CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path); CHECK_NE(-1, fstat(fd, &st)); diff --git a/tool/viz/printimage.c b/tool/viz/printimage.c index 7c0167c9c..926a0a1d3 100644 --- a/tool/viz/printimage.c +++ b/tool/viz/printimage.c @@ -178,8 +178,8 @@ static void GetOpts(int *argc, char *argv[]) { g_winsize.ws_col = 80; g_winsize.ws_row = 24; if (!g_flags.full && (!g_flags.width || !g_flags.height)) { - tcgetwinsize(STDIN_FILENO, &g_winsize) != -1 || - tcgetwinsize(STDOUT_FILENO, &g_winsize); + (void)(tcgetwinsize(STDIN_FILENO, &g_winsize) != -1 || + tcgetwinsize(STDOUT_FILENO, &g_winsize)); } ttyquantsetup(g_flags.quant, kTtyQuantRgb, g_flags.blocks); } @@ -220,11 +220,10 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn], long y0, long yn, long x0, long xn, long dy, long dx) { long y, x; - bool didhalfy, didfirstx; + bool didhalfy; unsigned char a[3], b[3]; didhalfy = false; for (y = y0; y < yn; y += dy) { - didfirstx = false; if (y) printf("\e[0m\n"); for (x = x0; x < xn; x += dx) { a[0] = RGB[0][y][x]; @@ -239,7 +238,6 @@ static void PrintImageImpl(long syn, long sxn, unsigned char RGB[3][syn][sxn], } printf("\e[48;2;%d;%d;%d;38;2;%d;%d;%dm%lc", a[0], a[1], a[2], b[0], b[1], b[2], dy > 1 ? u'▄' : u'▐'); - didfirstx = true; } printf("\e[0m"); if (g_flags.ruler) { @@ -363,7 +361,7 @@ static void ProcessImage(long yn, long xn, unsigned char RGB[3][yn][xn]) { void WithImageFile(const char *path, void fn(long yn, long xn, unsigned char RGB[3][yn][xn])) { struct stat st; - void *map, *data, *data2; + void *map, *data; int fd, yn, xn, cn, dyn, dxn, syn, sxn, wyn, wxn; CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path); CHECK_NE(-1, fstat(fd, &st)); diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c index ff0f8729e..c1da85b28 100644 --- a/tool/viz/printpeb.c +++ b/tool/viz/printpeb.c @@ -43,7 +43,7 @@ #include "tool/decode/lib/idname.h" #if defined(__x86_64__) && SupportsWindows() -char *GetString(struct NtUnicodeString *s) { +char *GetString(const struct NtUnicodeString *s) { static char buf[1024]; unsigned len = min(sizeof(buf) - 1, s->Length); for (unsigned i = 0; i < len; ++i) { diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 42256d7d4..b8f2e273c 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -278,15 +278,15 @@ static uint64_t t1, t2, t3, t4, t5, t6, t8; static const char *sox_, *ffplay_, *patharg_; static struct VtFrame vtframe_[2], *f1_, *f2_; static struct Graphic graphic_[2], *g1_, *g2_; +static long double deadline_, dura_, starttime_; static bool yes_, stats_, dither_, ttymode_, istango_; -static long double deadline_, dura_, skip_, starttime_; static long double decode_start_, f1_start_, f2_start_; static int16_t pcm_[PLM_AUDIO_SAMPLES_PER_FRAME * 2 / 8][8]; static int16_t pcmscale_[PLM_AUDIO_SAMPLES_PER_FRAME * 2 / 8][8]; static bool fullclear_, historyclear_, tuned_, yonly_, gotvideo_; -static int homerow_, lastrow_, playfd_, infd_, outfd_, nullfd_, speakerfails_; -static char host_[DNS_NAME_MAX + 1], status_[7][200], logpath_[PATH_MAX], - fifopath_[PATH_MAX], chansstr_[32], sratestr_[32], port_[32]; +static int homerow_, lastrow_, playfd_, infd_, outfd_, speakerfails_; +static char status_[7][200], logpath_[PATH_MAX], fifopath_[PATH_MAX], + chansstr_[32], sratestr_[32]; static void OnCtrlC(void) { longjmp(jb_, 1); @@ -324,7 +324,7 @@ static int GetNamedVector(const struct NamedVector *choices, size_t n, const char *s) { int i; char name[sizeof(choices->name)]; - strncpy(name, s, sizeof(name)); + strlcpy(name, s, sizeof(name)); strntoupper(name, sizeof(name)); for (i = 0; i < n; ++i) { if (memcmp(choices[i].name, name, sizeof(name)) == 0) {