diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-11-04 12:04:55 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-11-04 12:04:55 -0500 |
commit | 9e15e076c1f3e647b1f7ed7e3c12a1f23fdbe98c (patch) | |
tree | ac3c1e11ce7e4a7a1fd53459b3e0e4f9e2892188 | |
parent | 726d78019593d5b5f192d2962f5bc975bfe85785 (diff) | |
download | bfs-9e15e076c1f3e647b1f7ed7e3c12a1f23fdbe98c.tar.xz |
Enable -Wsign-compare to catch bugs like 726d7801
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | bftw.c | 2 | ||||
-rw-r--r-- | color.c | 2 | ||||
-rw-r--r-- | eval.c | 10 | ||||
-rw-r--r-- | printf.c | 4 | ||||
-rw-r--r-- | util.c | 2 |
6 files changed, 11 insertions, 11 deletions
@@ -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) @@ -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; @@ -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; @@ -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); } @@ -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); @@ -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; |