COMMON_INTERCEPTOR_READ_RANGE(ctx, preg, struct_regex_sz);
REAL(regfree)(preg);
}
+#define INIT_REGEX \
+ COMMON_INTERCEPT_FUNCTION(regcomp); \
+ COMMON_INTERCEPT_FUNCTION(regexec); \
+ COMMON_INTERCEPT_FUNCTION(regerror); \
+ COMMON_INTERCEPT_FUNCTION(regfree);
+#else
+#define INIT_REGEX
+#endif
+
+#if SANITIZER_INTERCEPT_REGEXSUB
INTERCEPTOR(SSIZE_T, regnsub, char *buf, SIZE_T bufsiz, const char *sub,
const struct __sanitizer_regmatch *rm, const char *str) {
void *ctx;
}
return res;
}
-#define INIT_REGEX \
- COMMON_INTERCEPT_FUNCTION(regcomp); \
- COMMON_INTERCEPT_FUNCTION(regexec); \
- COMMON_INTERCEPT_FUNCTION(regerror); \
- COMMON_INTERCEPT_FUNCTION(regfree); \
+
+#define INIT_REGEXSUB \
COMMON_INTERCEPT_FUNCTION(regnsub); \
COMMON_INTERCEPT_FUNCTION(regasub);
#else
-#define INIT_REGEX
+#define INIT_REGEXSUB
#endif
#if SANITIZER_INTERCEPT_FTS
INIT_SETVBUF;
INIT_GETVFSSTAT;
INIT_REGEX;
+ INIT_REGEXSUB;
INIT_FTS;
INIT_SYSCTL;
INIT_ASYSCTL;
#define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
#define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
#define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
-#define SANITIZER_INTERCEPT_REGEX SI_NETBSD
+#define SANITIZER_INTERCEPT_REGEX (SI_NETBSD || SI_FREEBSD)
+#define SANITIZER_INTERCEPT_REGEXSUB SI_NETBSD
#define SANITIZER_INTERCEPT_FTS SI_NETBSD
#define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD || SI_MAC)
#define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+//
+// UNSUPPORTED: linux, darwin, solaris
#include <assert.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
+#ifndef __arraycount
+#define __arraycount(a) ((sizeof(a) / sizeof(a[0])))
+#endif
+
void test_matched(const regex_t *preg, const char *string) {
int rv = regexec(preg, string, 0, NULL, 0);
if (!rv)
abort();
}
-void test_nsub(const regex_t *preg, const char *string) {
- regmatch_t rm[10];
- int rv = regexec(preg, string, __arraycount(rm), rm, 0);
- if (!rv) {
- char buf[1024];
- ssize_t ss = regnsub(buf, __arraycount(buf), "\\1xyz", rm, string);
- assert(ss != -1);
-
- printf("'%s' -> '%s'\n", string, buf);
- } else if (rv == REG_NOMATCH)
- printf("%s: not-matched\n", string);
- else
- abort();
-}
-
-void test_asub(const regex_t *preg, const char *string) {
- regmatch_t rm[10];
- int rv = regexec(preg, string, __arraycount(rm), rm, 0);
- if (!rv) {
- char *buf;
- ssize_t ss = regasub(&buf, "\\1xyz", rm, string);
- assert(ss != -1);
-
- printf("'%s' -> '%s'\n", string, buf);
- free(buf);
- } else if (rv == REG_NOMATCH)
- printf("%s: not-matched\n", string);
- else
- abort();
-}
-
int main(void) {
printf("regex\n");
test_print_matches(®ex, "ABC");
- test_nsub(®ex, "ABC DEF");
- test_asub(®ex, "GHI JKL");
-
regfree(®ex);
rv = regcomp(®ex, "[[:upp:]]", 0);
// CHECK: ABC: matched
// CHECK: matched[0]='AB'
// CHECK: matched[1]='B'
- // CHECK: 'ABC DEF' -> 'Bxyz'
- // CHECK: 'GHI JKL' -> 'Hxyz'
// CHECK: error:{{.*}}
return 0;