summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-11-04 12:04:55 -0500
committerTavian Barnes <tavianator@tavianator.com>2020-11-04 12:04:55 -0500
commit9e15e076c1f3e647b1f7ed7e3c12a1f23fdbe98c (patch)
treeac3c1e11ce7e4a7a1fd53459b3e0e4f9e2892188
parent726d78019593d5b5f192d2962f5bc975bfe85785 (diff)
downloadbfs-9e15e076c1f3e647b1f7ed7e3c12a1f23fdbe98c.tar.xz
Enable -Wsign-compare to catch bugs like 726d7801
-rw-r--r--Makefile2
-rw-r--r--bftw.c2
-rw-r--r--color.c2
-rw-r--r--eval.c10
-rw-r--r--printf.c4
-rw-r--r--util.c2
6 files changed, 11 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 21c15be..4e67cf6 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ INSTALL ?= install
MKDIR ?= mkdir -p
RM ?= rm -f
-WFLAGS ?= -Wall -Wmissing-declarations -Wstrict-prototypes
+WFLAGS ?= -Wall -Wmissing-declarations -Wstrict-prototypes -Wsign-compare
CFLAGS ?= -g $(WFLAGS)
LDFLAGS ?=
DEPFLAGS ?= -MD -MP -MF $(@:.o=.d)
diff --git a/bftw.c b/bftw.c
index 0e541c6..8d561ff 100644
--- a/bftw.c
+++ b/bftw.c
@@ -426,7 +426,7 @@ static int bftw_file_open(struct bftw_cache *cache, struct bftw_file *file, cons
// Handle ENAMETOOLONG by manually traversing the path component-by-component
// -1 to include the root, which has depth == 0
- size_t offset = base ? base->depth : -1;
+ size_t offset = base ? base->depth : (size_t)-1;
size_t levels = file->depth - offset;
if (levels < 2) {
return fd;
diff --git a/color.c b/color.c
index 94f58fc..24c7f4b 100644
--- a/color.c
+++ b/color.c
@@ -790,7 +790,7 @@ static int print_dirs_colored(CFILE *cfile, const char *path, const struct BFTW
}
}
- if (broken < nameoff) {
+ if ((size_t)broken < nameoff) {
const char *color = colors->missing;
if (!color) {
color = colors->orphan;
diff --git a/eval.c b/eval.c
index 09c253f..a6282bf 100644
--- a/eval.c
+++ b/eval.c
@@ -794,7 +794,7 @@ bool eval_regex(const struct expr *expr, struct eval_state *state) {
#endif
int err = regexec(expr->regex, path, 1, &match, flags);
if (err == 0) {
- return match.rm_so == 0 && match.rm_eo == len;
+ return match.rm_so == 0 && (size_t)match.rm_eo == len;
} else if (err != REG_NOMATCH) {
char *str = xregerror(err, expr->regex);
if (str) {
@@ -1300,7 +1300,7 @@ static enum bftw_action eval_callback(const struct BFTW *ftwbuf, void *ptr) {
goto done;
}
- if (ctx->maxdepth < 0 || ftwbuf->depth >= ctx->maxdepth) {
+ if (ctx->maxdepth < 0 || ftwbuf->depth >= (size_t)ctx->maxdepth) {
state.action = BFTW_PRUNE;
}
@@ -1308,13 +1308,13 @@ static enum bftw_action eval_callback(const struct BFTW *ftwbuf, void *ptr) {
enum bftw_visit expected_visit = BFTW_PRE;
if ((ctx->flags & BFTW_POST_ORDER)
&& (ctx->strategy == BFTW_IDS || ftwbuf->type == BFTW_DIR)
- && ftwbuf->depth < ctx->maxdepth) {
+ && ftwbuf->depth < (size_t)ctx->maxdepth) {
expected_visit = BFTW_POST;
}
if (ftwbuf->visit == expected_visit
- && ftwbuf->depth >= ctx->mindepth
- && ftwbuf->depth <= ctx->maxdepth) {
+ && ftwbuf->depth >= (size_t)ctx->mindepth
+ && ftwbuf->depth <= (size_t)ctx->maxdepth) {
eval_expr(ctx->expr, &state);
}
diff --git a/printf.c b/printf.c
index 003c1b0..e07feb4 100644
--- a/printf.c
+++ b/printf.c
@@ -73,7 +73,7 @@ static int bfs_printf_flush(FILE *file, const struct bfs_printf *directive, cons
#define BFS_PRINTF_BUF(buf, format, ...) \
char buf[256]; \
int ret = snprintf(buf, sizeof(buf), format, __VA_ARGS__); \
- assert(ret >= 0 && ret < sizeof(buf)); \
+ assert(ret >= 0 && (size_t)ret < sizeof(buf)); \
(void)ret
/** %a, %c, %t: ctime() */
@@ -172,7 +172,7 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf *directive, c
break;
}
- assert(ret >= 0 && ret < sizeof(buf));
+ assert(ret >= 0 && (size_t)ret < sizeof(buf));
(void)ret;
return fprintf(file, directive->str, buf);
diff --git a/util.c b/util.c
index 468d664..e3bea4c 100644
--- a/util.c
+++ b/util.c
@@ -77,7 +77,7 @@ char *xreadlinkat(int fd, const char *path, size_t size) {
len = readlinkat(fd, path, name, size);
if (len < 0) {
goto error;
- } else if (len >= size) {
+ } else if ((size_t)len >= size) {
size *= 2;
} else {
break;