Fix warnings

This change fixes Cosmopolitan so it has fewer opinions about compiler
warnings. The whole repository had to be cleaned up to be buildable in
-Werror -Wall mode. This lets us benefit from things like strict const
checking. Some actual bugs might have been caught too.
This commit is contained in:
Justine Tunney 2023-09-01 20:49:13 -07:00
parent e2b3c3618e
commit 0d748ad58e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
571 changed files with 1306 additions and 1888 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

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