aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-31 13:25:11 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-31 13:25:11 -0700
commit67b62c7294984eaa3b199765dd76b258dc979473 (patch)
tree2311b9f5cee690ee523378262f1fd805394eb8bc
parent60db11fbb8f5893047aae4289ceccd6b712b5f2d (diff)
Added lots of extra compiler checks and fixed a few minor issues.
-rw-r--r--Makefile14
-rw-r--r--bb.c18
-rw-r--r--draw.c4
-rw-r--r--terminal.c8
4 files changed, 30 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 2de32c1..d81fb4c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,19 @@ CC=cc
G=
O=-O2
CFLAGS=-std=c99 -Werror -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
-CWARN=-Wall -Wpedantic -Wextra -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference
+CWARN=-Wall -Wpedantic -Wextra \
+ -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
+ -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
+ -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
+ -Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
+ -Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
+ -Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
+ -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
+ -Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
+ -Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
+ -Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
+ -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \
+ -Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
CFLAGS += '-DBB_NAME="$(NAME)"'
diff --git a/bb.c b/bb.c
index 1a9968a..185c70e 100644
--- a/bb.c
+++ b/bb.c
@@ -45,12 +45,13 @@ static int compare_files(void *v, const void *v1, const void *v2);
#else
static int compare_files(const void *v1, const void *v2, void *v);
#endif
+__attribute__((format(printf,2,3)))
void flash_warn(bb_t *bb, const char *fmt, ...);
static void handle_next_key_binding(bb_t *bb);
static void init_term(void);
static int is_simple_bbcmd(const char *s);
static entry_t* load_entry(bb_t *bb, const char *path);
-static inline int matches_cmd(const char *str, const char *cmd);
+static int matches_cmd(const char *str, const char *cmd);
static void* memcheck(void *p);
static char* normalize_path(const char *root, const char *path, char *pbuf);
static int populate_files(bb_t *bb, const char *path);
@@ -240,6 +241,7 @@ static int compare_files(const void *v1, const void *v2, void *v)
case COL_CTIME: COMPARE_TIME(ctime(e1->info), ctime(e2->info)); break;
case COL_ATIME: COMPARE_TIME(atime(e1->info), atime(e2->info)); break;
case COL_RANDOM: COMPARE(e2->shufflepos, e1->shufflepos); break;
+ default: break;
}
}
return 0;
@@ -418,7 +420,7 @@ static entry_t* load_entry(bb_t *bb, const char *path)
// Return whether a string matches a command
// e.g. matches_cmd("sel:x", "select:") == 1, matches_cmd("q", "quit") == 1
//
-static inline int matches_cmd(const char *str, const char *cmd)
+static int matches_cmd(const char *str, const char *cmd)
{
if ((strchr(cmd, ':') == NULL) != (strchr(str, ':') == NULL))
return 0;
@@ -642,7 +644,7 @@ static void run_bbcmd(bb_t *bb, const char *cmd)
char *description;
if (script[0] == '#') {
description = trim(strsep(&script, "\n") + 1);
- if (!script) script = "";
+ if (!script) script = (char*)"";
else script = trim(script);
} else description = script;
for (char *key; (key = strsep(&keys, ",")); ) {
@@ -834,7 +836,7 @@ static int run_script(bb_t *bb, const char *cmd)
(void)setpgid(0, pgrp);
if (tcsetpgrp(STDIN_FILENO, pgrp))
clean_err("Couldn't set pgrp");
- char **args = xcalloc(4 + (size_t)bb->nselected + 1, sizeof(char*));
+ const char **args = xcalloc(4 + (size_t)bb->nselected + 1, sizeof(char*));
int i = 0;
args[i++] = "sh";
args[i++] = "-c";
@@ -850,7 +852,7 @@ static int run_script(bb_t *bb, const char *cmd)
dup2(fileno(tty_out), STDOUT_FILENO);
dup2(fileno(tty_in), STDIN_FILENO);
- execvp(args[0], args);
+ execvp(args[0], (char**)args);
clean_err("Failed to execute command: '%s'", cmd);
return -1;
}
@@ -970,8 +972,8 @@ static void set_selected(bb_t *bb, entry_t *e, int selected)
//
static void set_sort(bb_t *bb, const char *sort)
{
- char sortbuf[strlen(sort)+1];
- strcpy(sortbuf, sort);
+ char sortbuf[MAX_SORT+1];
+ strncpy(sortbuf, sort, MAX_SORT);
for (char *s = sortbuf; s[0] && s[1]; s += 2) {
char *found;
if ((found = strchr(bb->sort, s[1]))) {
@@ -1074,7 +1076,7 @@ static int wait_for_process(proc_t **proc)
int main(int argc, char *argv[])
{
- char *initial_path;
+ const char *initial_path;
if (argc >= 3 && streq(argv[argc-2], "--")) {
initial_path = argv[argc-1];
argc -= 2;
diff --git a/draw.c b/draw.c
index 24dd8bc..01ed4f3 100644
--- a/draw.c
+++ b/draw.c
@@ -46,7 +46,7 @@ static char* stpcpy_escaped(char *buf, const char *str, const char *color)
if (*c > 0 && *c <= '\x1b' && escapes[(int)*c] != ' ') { // "\n", etc.
buf += sprintf(buf, "\033[31m\\%c%s", escapes[(int)*c], color);
} else if (*c >= 0 && !(' ' <= *c && *c <= '~')) { // "\x02", etc.
- buf += sprintf(buf, "\033[31m\\x%02X%s", *c, color);
+ buf += sprintf(buf, "\033[31m\\x%02X%s", (unsigned int)*c, color);
} else {
*(buf++) = *c;
}
@@ -69,7 +69,7 @@ static int fputs_escaped(FILE *f, const char *str, const char *color)
fprintf(f, "\033[31m\\%c%s", escapes[(int)*c], color);
++escaped;
} else if (*c >= 0 && !(' ' <= *c && *c <= '~')) { // "\x02", etc.
- fprintf(f, "\033[31m\\x%02X%s", *c, color);
+ fprintf(f, "\033[31m\\x%02X%s", (unsigned int)*c, color);
++escaped;
} else {
fputc(*c, f);
diff --git a/terminal.c b/terminal.c
index 09debb6..ae9fe66 100644
--- a/terminal.c
+++ b/terminal.c
@@ -58,13 +58,13 @@ static keyname_t key_names[] = {
{':', "Colon"}, {',', "Comma"},
};
-static inline int nextchar(int fd)
+static int nextchar(int fd)
{
char c;
return read(fd, &c, 1) == 1 ? c : -1;
}
-static inline int nextnum(int fd, int c, int *n)
+static int nextnum(int fd, int c, int *n)
{
for (*n = 0; '0' <= c && c <= '9'; c = nextchar(fd))
*n = 10*(*n) + (c - '0');
@@ -143,6 +143,7 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y)
case 21: return modifiers | KEY_F10;
case 23: return modifiers | KEY_F11;
case 24: return modifiers | KEY_F12;
+ default: break;
}
return -1;
case '<': { // Mouse clicks
@@ -185,6 +186,7 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y)
case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break;
case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break;
case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break;
+ default: break;
}
}
}
@@ -238,7 +240,7 @@ char *bkeyname(int key, char *buf)
if (' ' < key && key <= '~')
return buf + sprintf(buf, "%c", key);
else
- return buf + sprintf(buf, "\\x%02X", key);
+ return buf + sprintf(buf, "\\x%02X", (unsigned int)key);
}
//