mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 18:28:30 +00:00
Fix some static analysis issues
This commit is contained in:
parent
fb54604b31
commit
f147d3dde9
30 changed files with 375 additions and 266 deletions
|
@ -48,8 +48,10 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) {
|
|||
uint64_t z,h,l;\n\
|
||||
uint64_t ",
|
||||
(n + m) * 64, n * 64, m * 64, n + m, n, m, n, m, n + m, n, m);
|
||||
Rs = gc(calloc(sizeof(*Rs), n + m + 1));
|
||||
Ra = gc(calloc(sizeof(*Ra), n + m + 1));
|
||||
if (!(Rs = calloc(sizeof(*Rs), n + m + 1)))
|
||||
__builtin_trap();
|
||||
if (!(Ra = calloc(sizeof(*Ra), n + m + 1)))
|
||||
__builtin_trap();
|
||||
for (j = 0; j < n; ++j) {
|
||||
if (j)
|
||||
printf(", ");
|
||||
|
@ -172,6 +174,8 @@ void Multiply%dx%d(uint64_t C[%d], const uint64_t A[%d], const uint64_t B[%d]) {
|
|||
}
|
||||
printf("}\n");
|
||||
fflush(stdout);
|
||||
free(Ra);
|
||||
free(Rs);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -44,8 +46,8 @@ int main(int argc, char *argv[]) {
|
|||
long count = LONG_MAX;
|
||||
long blocksize = 1;
|
||||
int oflags = O_WRONLY | O_TRUNC | O_CREAT;
|
||||
const char *infile = "/dev/stdin";
|
||||
const char *oufile = "/dev/stdout";
|
||||
char *infile = gc(strdup("/dev/stdin"));
|
||||
char *oufile = gc(strdup("/dev/stdout"));
|
||||
|
||||
prog = argv[0];
|
||||
if (!prog)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
open(argv[1], O_RDWR);
|
||||
Elf64_Ehdr *e = mmap(0, 64, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0);
|
||||
int fd = open(argv[1], O_RDWR);
|
||||
Elf64_Ehdr *e = mmap(0, 64, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
e->e_ident[EI_OSABI] = ELFOSABI_SYSV;
|
||||
}
|
||||
|
|
|
@ -139,6 +139,7 @@ void Compress(const char *inpath) {
|
|||
FILE *input;
|
||||
gzFile output;
|
||||
int rc, errnum;
|
||||
FILE *closeme = 0;
|
||||
const char *outpath;
|
||||
char *p, openflags[5];
|
||||
if ((!inpath || opt_usestdout) && (!isatty(1) || opt_force)) {
|
||||
|
@ -151,7 +152,7 @@ void Compress(const char *inpath) {
|
|||
exit(1);
|
||||
}
|
||||
if (inpath) {
|
||||
input = fopen(inpath, "rb");
|
||||
input = closeme = fopen(inpath, "rb");
|
||||
} else {
|
||||
inpath = "/dev/stdin";
|
||||
input = stdin;
|
||||
|
@ -178,8 +179,9 @@ void Compress(const char *inpath) {
|
|||
}
|
||||
if (!output) {
|
||||
fputs(outpath, stderr);
|
||||
fputs(": gzopen() failed\n", stderr);
|
||||
fputs(_strerdoc(errno), stderr);
|
||||
fputs(": gzopen() failed: ", stderr);
|
||||
const char *s = _strerdoc(errno);
|
||||
fputs(s ? s : "EUNKNOWN", stderr);
|
||||
fputs("\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -189,7 +191,8 @@ void Compress(const char *inpath) {
|
|||
errnum = 0;
|
||||
fputs(inpath, stderr);
|
||||
fputs(": read failed: ", stderr);
|
||||
fputs(_strerdoc(ferror(input)), stderr);
|
||||
const char *s = _strerdoc(ferror(input));
|
||||
fputs(s ? s : "EUNKNOWN", stderr);
|
||||
fputs("\n", stderr);
|
||||
_Exit(1);
|
||||
}
|
||||
|
@ -201,8 +204,8 @@ void Compress(const char *inpath) {
|
|||
_Exit(1);
|
||||
}
|
||||
} while (rc == sizeof(databuf));
|
||||
if (input != stdin) {
|
||||
if (fclose(input)) {
|
||||
if (closeme) {
|
||||
if (fclose(closeme)) {
|
||||
fputs(inpath, stderr);
|
||||
fputs(": close failed\n", stderr);
|
||||
_Exit(1);
|
||||
|
@ -221,6 +224,7 @@ void Compress(const char *inpath) {
|
|||
void Decompress(const char *inpath) {
|
||||
FILE *output;
|
||||
gzFile input;
|
||||
FILE *closeme = 0;
|
||||
int rc, n, errnum;
|
||||
const char *outpath;
|
||||
outpath = 0;
|
||||
|
@ -233,8 +237,9 @@ void Decompress(const char *inpath) {
|
|||
}
|
||||
if (!input) {
|
||||
fputs(inpath, stderr);
|
||||
fputs(": gzopen() failed\n", stderr);
|
||||
fputs(_strerdoc(errno), stderr);
|
||||
fputs(": gzopen() failed: ", stderr);
|
||||
const char *s = _strerdoc(errno);
|
||||
fputs(s ? s : "EUNKNOWN", stderr);
|
||||
fputs("\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -248,10 +253,11 @@ void Decompress(const char *inpath) {
|
|||
memcpy(pathbuf, inpath, n - 3);
|
||||
pathbuf[n - 3] = 0;
|
||||
outpath = pathbuf;
|
||||
if (!(output = fopen(outpath, opt_append ? "wa" : "wb"))) {
|
||||
if (!(output = closeme = fopen(outpath, opt_append ? "wa" : "wb"))) {
|
||||
fputs(outpath, stderr);
|
||||
fputs(": open failed: ", stderr);
|
||||
fputs(_strerdoc(errno), stderr);
|
||||
const char *s = _strerdoc(errno);
|
||||
fputs(s ? s : "EUNKNOWN", stderr);
|
||||
fputs("\n", stderr);
|
||||
_Exit(1);
|
||||
}
|
||||
|
@ -273,7 +279,8 @@ void Decompress(const char *inpath) {
|
|||
if (fwrite(databuf, rc, 1, output) != 1) {
|
||||
fputs(outpath, stderr);
|
||||
fputs(": write failed: ", stderr);
|
||||
fputs(_strerdoc(ferror(output)), stderr);
|
||||
const char *s = _strerdoc(ferror(output));
|
||||
fputs(s ? s : "EUNKNOWN", stderr);
|
||||
fputs("\n", stderr);
|
||||
_Exit(1);
|
||||
}
|
||||
|
@ -283,8 +290,8 @@ void Decompress(const char *inpath) {
|
|||
fputs(": gzclose failed\n", stderr);
|
||||
_Exit(1);
|
||||
}
|
||||
if (output != stdout) {
|
||||
if (fclose(output)) {
|
||||
if (closeme) {
|
||||
if (fclose(closeme)) {
|
||||
fputs(outpath, stderr);
|
||||
fputs(": close failed\n", stderr);
|
||||
_Exit(1);
|
||||
|
|
|
@ -204,7 +204,8 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
|
|||
static bool once;
|
||||
static z_stream zs;
|
||||
zsize = 32768;
|
||||
zbuf = gc(malloc(zsize));
|
||||
if (!(zbuf = malloc(zsize)))
|
||||
__builtin_trap();
|
||||
if (!once) {
|
||||
CHECK_EQ(Z_OK, deflateInit2(&zs, 4, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
|
||||
Z_DEFAULT_STRATEGY));
|
||||
|
@ -226,6 +227,7 @@ bool Send(int tmpfd, const void *output, size_t outputsize) {
|
|||
break;
|
||||
}
|
||||
} while (!zs.avail_out);
|
||||
free(zbuf);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,7 +218,20 @@
|
|||
"__sysv_abi__"
|
||||
"__mode__"
|
||||
"__seg_fs"
|
||||
"__seg_gs"))
|
||||
"__seg_gs"
|
||||
"__access__"
|
||||
"__read_only__"
|
||||
"__write_only__"
|
||||
"__read_write__"
|
||||
"__read_only"
|
||||
"__write_only"
|
||||
"__read_write"
|
||||
"__fd_arg__"
|
||||
"__fd_arg"
|
||||
"__copy__"
|
||||
"__retain__"
|
||||
"__tainted_args__"
|
||||
"__zero_call_used_regs__"))
|
||||
|
||||
(clang
|
||||
'("__optnone__"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue