aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--files.c8
-rw-r--r--match.c1
-rw-r--r--pattern.c21
-rw-r--r--types.h7
5 files changed, 21 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 87ff4b0..dd12609 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ leaktest:
valgrind --leak-check=full ./bp -l -g grammars/bp.bp -p Grammar grammars/bp.bp
splint:
- splint -posix-lib $(CFILES) bp.c
+ splint -posix-lib -weak -initallelements $(CFILES) bp.c
install: $(NAME)
mkdir -p -m 755 "$(PREFIX)/share/man/man1" "$(PREFIX)/bin" "$(SYSCONFDIR)/xdg/$(NAME)"
diff --git a/files.c b/files.c
index d111e4f..fba666a 100644
--- a/files.c
+++ b/files.c
@@ -51,7 +51,7 @@ file_t *load_filef(file_t **files, const char *fmt, ...)
char filename[PATH_MAX+1] = {0};
va_list args;
va_start(args, fmt);
- check(vsnprintf(filename, PATH_MAX, fmt, args) <= PATH_MAX,
+ check(vsnprintf(filename, PATH_MAX, fmt, args) <= (int)PATH_MAX,
"File name is too large");
va_end(args);
return load_file(files, filename);
@@ -217,7 +217,7 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons
size_t linenum = get_line_number(f, start);
const char *line = get_line(f, linenum);
size_t charnum = get_char_number(f, start);
- fprintf(dest, "\033[1m%s:%ld:\033[0m ", f->filename[0] ? f->filename : "stdin", linenum);
+ fprintf(dest, "\033[1m%s:%lu:\033[0m ", f->filename[0] ? f->filename : "stdin", linenum);
va_list args;
va_start(args, fmt);
@@ -227,12 +227,12 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons
const char *eol = linenum == f->nlines ? strchr(line, '\0') : strchr(line, '\n');
if (end == NULL || end > eol) end = eol;
- fprintf(dest, "\033[2m% 5ld |\033[0m %.*s\033[41;30m%.*s\033[0m%.*s\n",
+ fprintf(dest, "\033[2m%5lu\033(0\x78\033(B\033[0m%.*s\033[41;30m%.*s\033[0m%.*s\n",
linenum,
(int)charnum - 1, line,
(int)(end - &line[charnum-1]), &line[charnum-1],
(int)(eol - end - 1), end);
- fprintf(dest, " \033[34;1m");
+ fprintf(dest, " \033[34;1m");
const char *p = line;
for (; p < start; ++p) (void)fputc(*p == '\t' ? '\t' : ' ', dest);
if (start == end) ++end;
diff --git a/match.c b/match.c
index b30a183..e2e00c2 100644
--- a/match.c
+++ b/match.c
@@ -381,6 +381,7 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool
.lines=f->lines, // I think this works, but am not 100% sure
.nlines=1 + get_line_number(f, m1->end)-get_line_number(f, m1->start),
.mmapped=f->mmapped,
+ .pats = NULL, .next = NULL,
};
match_t *m2 = match(defs, &inner, str, pat->args.multiple.second, ignorecase);
if ((m2 == NULL || m2->end != m1->end) == (pat->type == BP_EQUAL)) {
diff --git a/pattern.c b/pattern.c
index e28933b..cd154b4 100644
--- a/pattern.c
+++ b/pattern.c
@@ -20,7 +20,7 @@ static pat_t *expand_choices(file_t *f, pat_t *first);
__attribute__((nonnull))
static pat_t *_bp_simplepattern(file_t *f, const char *str);
__attribute__((nonnull(1,2,3,6)))
-static pat_t *new_range(file_t *f, const char *start, const char *end, ssize_t min, ssize_t max, pat_t *repeating, pat_t *sep);
+static pat_t *new_range(file_t *f, const char *start, const char *end, size_t min, ssize_t max, pat_t *repeating, pat_t *sep);
__attribute__((nonnull(1,2)))
static pat_t *bp_simplepattern(file_t *f, const char *str);
@@ -42,11 +42,11 @@ pat_t *new_pat(file_t *f, const char *start, enum pattype_e type)
//
// Helper function to initialize a range object.
//
-static pat_t *new_range(file_t *f, const char *start, const char *end, ssize_t min, ssize_t max, pat_t *repeating, pat_t *sep)
+static pat_t *new_range(file_t *f, const char *start, const char *end, size_t min, ssize_t max, pat_t *repeating, pat_t *sep)
{
pat_t *range = new_pat(f, start, BP_REPEAT);
- if (repeating->len >= 0 && (sep == NULL || sep->len >= 0) && min == max && min >= 0)
- range->len = repeating->len * min + (sep == NULL || min == 0 ? 0 : sep->len * (min-1));
+ if (repeating->len >= 0 && (sep == NULL || sep->len >= 0) && (ssize_t)min == max)
+ range->len = (ssize_t)repeating->len * (ssize_t)min + (sep == NULL || min == 0 ? 0 : (ssize_t)sep->len * (ssize_t)(min-1));
else
range->len = -1;
range->args.repetitions.min = min;
@@ -346,19 +346,20 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str)
// Number of repetitions: <N>(-<N> / - / + / "")
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': {
- ssize_t min = -1, max = -1;
+ size_t min = 0;
+ ssize_t max = -1;
--str;
long n1 = strtol(str, (char**)&str, 10);
if (matchchar(&str, '-')) {
str = after_spaces(str);
const char *numstart = str;
long n2 = strtol(str, (char**)&str, 10);
- if (str == numstart) min = 0, max = n1;
- else min = n1, max = n2;
+ if (str == numstart) min = 0, max = (ssize_t)n1;
+ else min = (size_t)n1, max = (ssize_t)n2;
} else if (matchchar(&str, '+')) {
- min = n1, max = -1;
+ min = (size_t)n1, max = -1;
} else {
- min = n1, max = n1;
+ min = (size_t)n1, max = (ssize_t)n1;
}
pat_t *repeating = bp_simplepattern(f, str);
if (!repeating)
@@ -431,7 +432,7 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str)
}
// Repeating
case '*': case '+': {
- ssize_t min = c == '*' ? 0 : 1;
+ size_t min = (size_t)(c == '*' ? 0 : 1);
pat_t *repeating = bp_simplepattern(f, str);
if (!repeating)
file_err(f, str, str, "There should be a valid pattern here after the '%c'", c);
diff --git a/types.h b/types.h
index 28b0d07..1fee2a6 100644
--- a/types.h
+++ b/types.h
@@ -50,7 +50,8 @@ typedef struct pat_s {
unsigned char low, high;
} range;
struct {
- ssize_t min, max;
+ size_t min;
+ ssize_t max;
struct pat_s *sep, *repeat_pat;
} repetitions;
// TODO: use a linked list instead of a binary tree
@@ -81,7 +82,7 @@ typedef struct pat_s {
//
// Pattern matching result object
//
-typedef /*@refcounted@*/ struct match_s {
+typedef struct match_s {
// Where the match starts and ends (end is after the last character)
const char *start, *end;
struct match_s *child, *nextsibling;
@@ -91,7 +92,7 @@ typedef /*@refcounted@*/ struct match_s {
#ifdef DEBUG_HEAP
struct match_s **atme;
#endif
- /*@refs@*/ int refcount;
+ int refcount;
// If skip_replacement is set to 1, that means the user wants to not print
// the replaced text when printing this match:
// TODO: this is a bit hacky, there is probably a better way to go about