aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-31 10:32:48 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-31 10:32:48 -0700
commit0443fbb06387138fc88be80104bef102246fdd25 (patch)
tree05259bcf5da0ad76aa62753c69b105ccc64d2370
parentaa1faea83ccb60ae5c1918849dd62e377b7c7263 (diff)
Added warning flag for null derefs
-rw-r--r--Makefile2
-rw-r--r--match.c3
2 files changed, 3 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 23ff090..a107318 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ CC=cc
PREFIX=/usr/local
SYSCONFDIR=/etc
CFLAGS=-std=c99 -Werror -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
-CWARN=-Wall -Wpedantic -Wextra -Wsign-conversion -Wtype-limits -Wunused-result
+CWARN=-Wall -Wpedantic -Wextra -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference
EXTRA=
G=
O=-O3
diff --git a/match.c b/match.c
index 19cb14d..25a08a7 100644
--- a/match.c
+++ b/match.c
@@ -52,9 +52,10 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool
// If the given pattern is a reference, look it up and return the referenced
// pattern. This is used for an optimization to avoid repeated lookups.
//
+__attribute__((nonnull, returns_nonnull))
static inline pat_t *deref(def_t *defs, pat_t *pat)
{
- if (pat && pat->type == BP_REF) {
+ if (pat->type == BP_REF) {
def_t *def = lookup(defs, pat->args.ref.len, pat->args.ref.name);
if (def) pat = def->pat;
}