diff --git a/Makefile b/Makefile index 00ef21f..06b0854 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,8 @@ splint: splint -posix-lib -standard -mustfreefresh -mustfreeonly -temptrans -immediatetrans -branchstate \ -compmempass -nullret -nullpass -nullderef -kepttrans -boolops -initallelements -fullinitblock \ -compdef -usereleased -unrecog -dependenttrans -predboolothers -ownedtrans -unqualifiedtrans \ - -onlytrans $(CFILES) bp.c + -onlytrans -usedef -nullassign -compdestroy -globstate -nullstate -statictrans -predboolint \ + $(CFILES) bp.c install: $(NAME) mkdir -p -m 755 "$(PREFIX)/share/man/man1" "$(PREFIX)/bin" "$(SYSCONFDIR)/xdg/$(NAME)" diff --git a/bp.c b/bp.c index ea6360c..b9e5eb5 100644 --- a/bp.c +++ b/bp.c @@ -132,8 +132,8 @@ static int is_text_file(const char *filename) { int fd = open(filename, O_RDONLY); if (fd < 0) return 0; - unsigned char buf[64]; - ssize_t len = read(fd, buf, sizeof(buf)/sizeof(unsigned char)); + char buf[64]; + ssize_t len = read(fd, buf, sizeof(buf)/sizeof(char)); if (len < 0) return 0; (void)close(fd); @@ -264,7 +264,7 @@ static void confirm_replacements(file_t *f, match_t *m, confirm_t *confirm) // static int inplace_modify_file(def_t *defs, file_t *f, pat_t *pattern) { - char tmp_filename[PATH_MAX+1] = {0}; + char tmp_filename[PATH_MAX+1] = {'\0'}; printer_t pr = { .file = f, .context_lines = ALL_CONTEXT, @@ -396,7 +396,7 @@ static int process_dir(def_t *defs, const char *dirname, pat_t *pattern) { int matches = 0; glob_t globbuf; - char globpath[PATH_MAX+1] = {0}; + char globpath[PATH_MAX+1] = {'\0'}; check(snprintf(globpath, PATH_MAX, "%s/*", dirname) <= (int)PATH_MAX, "Filename is too long: %s/*", dirname); int status = glob(globpath, 0, NULL, &globbuf); diff --git a/files.c b/files.c index fba666a..9912226 100644 --- a/files.c +++ b/files.c @@ -48,7 +48,7 @@ static void populate_lines(file_t *f) // file_t *load_filef(file_t **files, const char *fmt, ...) { - char filename[PATH_MAX+1] = {0}; + char filename[PATH_MAX+1] = {'\0'}; va_list args; va_start(args, fmt); check(vsnprintf(filename, PATH_MAX, fmt, args) <= (int)PATH_MAX, diff --git a/match.c b/match.c index a8451e6..eb9b383 100644 --- a/match.c +++ b/match.c @@ -271,7 +271,7 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool match_t *mp = match(defs, f, str, pat->args.repetitions.repeat_pat, ignorecase); if (mp == NULL) { str = start; - recycle_if_unused(&msep); + if (msep) recycle_if_unused(&msep); break; } if (mp->end == start && reps > 0) { @@ -281,7 +281,7 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool // the next loop either. We know that this will continue to // loop until reps==max, so let's just cut to the chase // instead of looping infinitely. - recycle_if_unused(&msep); + if (msep) recycle_if_unused(&msep); recycle_if_unused(&mp); if (pat->args.repetitions.max == -1) reps = ~(size_t)0; @@ -573,7 +573,6 @@ match_t *get_capture(match_t *m, const char **id) if (**id == ';') ++(*id); return cap; } - return NULL; } // diff --git a/print.c b/print.c index c5610a9..21c1aee 100644 --- a/print.c +++ b/print.c @@ -2,6 +2,7 @@ // print.c - Code for printing and visualizing matches. // +#include #include #include #include @@ -347,7 +348,7 @@ static void _print_match(FILE *out, printer_t *pr, match_t *m) void print_match(FILE *out, printer_t *pr, match_t *m) { current_color = color_normal; - int first = (pr->pos == NULL); + bool first = (pr->pos == NULL); if (first) { // First match printed: pr->pos = pr->file->contents; pr->needs_line_number = 1; diff --git a/utils.c b/utils.c index 93de1f4..08a5b6f 100644 --- a/utils.c +++ b/utils.c @@ -101,7 +101,7 @@ char unescapechar(const char *escaped, const char **end) break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': { // Octal - ret = (unsigned char)escaped[0] - '0'; + ret = (unsigned char)(escaped[0] - '0'); if ('0' <= escaped[1] && escaped[1] <= '7') { ++len; ret = (ret << 3) | (escaped[1] - '0');