A few more pedantic cleanups

This commit is contained in:
Bruce Hill 2021-01-18 11:28:39 -08:00
parent e98574570e
commit 0b0e99bfac
6 changed files with 12 additions and 11 deletions

View File

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

8
bp.c
View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
// print.c - Code for printing and visualizing matches.
//
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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;

View File

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