From f72bcb4313350e228d2553f2ed3b7d23386c234a Mon Sep 17 00:00:00 2001 From: hopper-vul Date: Thu, 15 Dec 2022 16:46:13 +0800 Subject: [PATCH] Change return type of cre2_set_compile from int to bool The inner implementation RE2::Set::Compile() will return true for success and false for failure of prog_ compilation. The cast int type will confuse developers to use the null prog_ without checking the returned status and then cause crash. Signed-off-by: hopper-vul --- src/cre2.cpp | 4 ++-- src/cre2.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cre2.cpp b/src/cre2.cpp index 5a63b93..f9c8e16 100644 --- a/src/cre2.cpp +++ b/src/cre2.cpp @@ -718,11 +718,11 @@ cre2_set_add_simple(cre2_set *set, const char *pattern) // Compile the regex set into a DFA. Must be called after add and before match. -int +bool cre2_set_compile(cre2_set *set) { RE2::Set *s = TO_RE2_SET(set); - return static_cast(s->Compile()); + return s->Compile(); } // Match the set of regex against text and store indices of matching regexes in match array. diff --git a/src/cre2.h b/src/cre2.h index 92eaf65..374c02c 100644 --- a/src/cre2.h +++ b/src/cre2.h @@ -330,8 +330,8 @@ cre2_decl int cre2_set_add(cre2_set *set, const char *pattern, size_t pattern_le cre2_decl int cre2_set_add_simple(cre2_set *set, const char *pattern); /* Compile the regex set into a DFA. Must be called after add and before match. - * Returns 1 on success, 0 on error */ -cre2_decl int cre2_set_compile(cre2_set *set); + * Returns true on success, false on error */ +cre2_decl bool cre2_set_compile(cre2_set *set); /* Match the set of regex against text and store indices of matching regexes in match array. * Returns the number of regexes which match. */