diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-05-31 12:38:42 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-05-31 12:38:42 -0700 |
| commit | da6c8857d6bad131635a846e8177e7c00a4c224e (patch) | |
| tree | 4adf3115388cdee07cdb169642133ef3a7ab2630 /match.c | |
| parent | 0443fbb06387138fc88be80104bef102246fdd25 (diff) | |
Moved utf8 code into a C file, fixed some potential null deref issues
Diffstat (limited to 'match.c')
| -rw-r--r-- | match.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -36,6 +36,7 @@ static match_t *unused_matches = NULL; static match_t *in_use_matches = NULL; #endif +__attribute__((nonnull(1))) static inline pat_t *deref(def_t *defs, pat_t *pat); __attribute__((returns_nonnull)) static match_t *new_match(pat_t *pat, const char *start, const char *end, match_t *child); @@ -52,10 +53,9 @@ 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->type == BP_REF) { + if (pat && pat->type == BP_REF) { def_t *def = lookup(defs, pat->args.ref.len, pat->args.ref.name); if (def) pat = def->pat; } @@ -297,6 +297,7 @@ static match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, bool } case BP_AFTER: { pat_t *back = deref(defs, pat->args.pat); + if (!back) return NULL; // We only care about the region from the backtrack pos up to the // current pos, so mock it out as a file slice. |
