aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-12-13 22:46:36 +0000
committerJoão Valverde <j@v6e.pt>2021-12-13 23:57:32 +0000
commitfb0e1a49076a3268a5e8c29c46c8516a91a6cefe (patch)
tree2b0ab17c9a9b506623683c93b7fc34202a706e03
parentff7a5c87e997d2839070b922fc5326feef89a37b (diff)
regex: Remove requirement for ssize_t
The type ssize_t is not available on Windows. Because this is used in the public API we must provide a definition for it. To avoid having to add a header to fix this use a size_t in the API instead, and assign SIZE_MAX to represent a null terminated string.
-rw-r--r--epan/ftypes/ftype-protocol.c2
-rw-r--r--epan/ftypes/ftype-string.c2
-rw-r--r--wsutil/regex.c6
-rw-r--r--wsutil/regex.h4
4 files changed, 8 insertions, 6 deletions
diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c
index fa67c5750f..b50b52ef03 100644
--- a/epan/ftypes/ftype-protocol.c
+++ b/epan/ftypes/ftype-protocol.c
@@ -293,7 +293,7 @@ cmp_matches(const fvalue_t *fv, const ws_regex_t *regex)
data = (const char *)tvb_get_ptr(a->tvb, 0, tvb_len);
rc = ws_regex_matches(regex, data, tvb_len);
} else {
- rc = ws_regex_matches(regex, a->proto_string, -1);
+ rc = ws_regex_matches(regex, a->proto_string, WS_REGEX_ZERO_TERMINATED);
}
}
CATCH_ALL {
diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c
index cda6aaf344..cf631e0176 100644
--- a/epan/ftypes/ftype-string.c
+++ b/epan/ftypes/ftype-string.c
@@ -152,7 +152,7 @@ cmp_matches(const fvalue_t *fv, const ws_regex_t *regex)
if (! regex) {
return FALSE;
}
- return ws_regex_matches(regex, str, -1);
+ return ws_regex_matches(regex, str, WS_REGEX_ZERO_TERMINATED);
}
void
diff --git a/wsutil/regex.c b/wsutil/regex.c
index 83caa96291..0698df9161 100644
--- a/wsutil/regex.c
+++ b/wsutil/regex.c
@@ -83,13 +83,13 @@ ws_regex_compile(const char *patt, char **errmsg)
static bool
-match_pcre2(pcre2_code *code, const char *subj, ssize_t subj_size)
+match_pcre2(pcre2_code *code, const char *subj, size_t subj_size)
{
PCRE2_SIZE length;
pcre2_match_data *match_data;
int rc;
- length = subj_size < 0 ? PCRE2_ZERO_TERMINATED : (PCRE2_SIZE)subj_size;
+ length = subj_size == WS_REGEX_ZERO_TERMINATED ? PCRE2_ZERO_TERMINATED : (PCRE2_SIZE)subj_size;
/* We don't use the matched substring but pcre2_match requires
* at least one pair of offsets. */
@@ -123,7 +123,7 @@ match_pcre2(pcre2_code *code, const char *subj, ssize_t subj_size)
bool
-ws_regex_matches(const ws_regex_t *re, const char *subj, ssize_t subj_size)
+ws_regex_matches(const ws_regex_t *re, const char *subj, size_t subj_size)
{
ws_return_val_if_null(re, FALSE);
ws_return_val_if_null(subj, FALSE);
diff --git a/wsutil/regex.h b/wsutil/regex.h
index 1ba4fe3834..eec51b7baf 100644
--- a/wsutil/regex.h
+++ b/wsutil/regex.h
@@ -12,6 +12,8 @@
#include <wireshark.h>
+#define WS_REGEX_ZERO_TERMINATED SIZE_MAX
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -23,7 +25,7 @@ WS_DLL_PUBLIC ws_regex_t *
ws_regex_compile(const char *patt, char **errmsg);
WS_DLL_PUBLIC bool
-ws_regex_matches(const ws_regex_t *re, const char *subj, ssize_t subj_size);
+ws_regex_matches(const ws_regex_t *re, const char *subj, size_t subj_size);
WS_DLL_PUBLIC void
ws_regex_free(ws_regex_t *re);