diff --git a/t/t_strlcat.c b/t/t_strlcat.c index 401b05c..3ab8a33 100644 --- a/t/t_strlcat.c +++ b/t/t_strlcat.c @@ -35,11 +35,12 @@ #include #include -#undef HAVE_STRLCAT #include #include +typedef size_t (*strlcat_f)(char *, const char *, size_t); + #define T_MAGIC_STR "squeamish ossifrage" #define T_MAGIC_LEN (sizeof(T_MAGIC_STR) - 1) #define T_BUFSIZE (T_MAGIC_LEN + 1 + T_MAGIC_LEN + 1) @@ -126,16 +127,15 @@ static struct t_case t_cases[] = { * Test function */ static int -t_strlcat(char **desc CRYB_UNUSED, void *arg) +t_strlcat(strlcat_f func, const struct t_case *t) { - struct t_case *t = arg; char buf[T_BUFSIZE + 1]; size_t sz; int ret; memcpy(buf, t->buf, sizeof t->buf); buf[T_BUFSIZE] = T_CANARY; - sz = strlcat(buf, t->in, T_BUFSIZE); + sz = func(buf, t->in, T_BUFSIZE); if (buf[T_BUFSIZE] != T_CANARY) { t_printv("buffer overflow\n"); return (0); @@ -146,6 +146,24 @@ t_strlcat(char **desc CRYB_UNUSED, void *arg) return (ret); } +static int +t_cryb_strlcat(char **desc CRYB_UNUSED, void *arg) +{ + const struct t_case *t = arg; + + return (t_strlcat(cryb_strlcat, t)); +} + +#if HAVE_STRLCAT +static int +t_libc_strlcat(char **desc CRYB_UNUSED, void *arg) +{ + const struct t_case *t = arg; + + return (t_strlcat(strlcat, t)); +} +#endif + /*************************************************************************** * Boilerplate @@ -160,7 +178,13 @@ t_prepare(int argc, char *argv[]) (void)argv; n = sizeof t_cases / sizeof t_cases[0]; for (i = 0; i < n; ++i) - t_add_test(t_strlcat, &t_cases[i], "%s", t_cases[i].desc); + t_add_test(t_cryb_strlcat, &t_cases[i], + "%s (cryb)", t_cases[i].desc); +#if HAVE_STRLCAT + for (i = 0; i < n; ++i) + t_add_test(t_libc_strlcat, &t_cases[i], + "%s (libc)", t_cases[i].desc); +#endif return (0); } diff --git a/t/t_strlcpy.c b/t/t_strlcpy.c index f5c66bf..c0493f7 100644 --- a/t/t_strlcpy.c +++ b/t/t_strlcpy.c @@ -35,11 +35,12 @@ #include #include -#undef HAVE_STRLCPY #include #include +typedef size_t (*strlcpy_f)(char *, const char *, size_t); + #define T_MAGIC_STR "squeamish ossifrage" #define T_MAGIC_LEN (sizeof(T_MAGIC_STR) - 1) #define T_BUFSIZE (T_MAGIC_LEN + 1 + T_MAGIC_LEN + 1) @@ -86,14 +87,13 @@ static struct t_case t_cases[] = { * Test function */ static int -t_strlcpy(char **desc CRYB_UNUSED, void *arg) +t_strlcpy(strlcpy_f func, const struct t_case *t) { - struct t_case *t = arg; char buf[T_BUFSIZE + 1]; size_t sz; memset(buf, T_CANARY, sizeof buf); - sz = strlcpy(buf, t->in, T_BUFSIZE); + sz = func(buf, t->in, T_BUFSIZE); if (buf[T_BUFSIZE] != T_CANARY) { t_printv("buffer overflow\n"); return (0); @@ -101,6 +101,24 @@ t_strlcpy(char **desc CRYB_UNUSED, void *arg) return (t_compare_sz(t->sz, sz) & t_compare_str(t->out, buf)); } +static int +t_cryb_strlcpy(char **desc CRYB_UNUSED, void *arg) +{ + const struct t_case *t = arg; + + return (t_strlcpy(cryb_strlcpy, t)); +} + +#if HAVE_STRLCPY +static int +t_libc_strlcpy(char **desc CRYB_UNUSED, void *arg) +{ + const struct t_case *t = arg; + + return (t_strlcpy(strlcpy, t)); +} +#endif + /*************************************************************************** * Boilerplate @@ -115,7 +133,13 @@ t_prepare(int argc, char *argv[]) (void)argv; n = sizeof t_cases / sizeof t_cases[0]; for (i = 0; i < n; ++i) - t_add_test(t_strlcpy, &t_cases[i], "%s", t_cases[i].desc); + t_add_test(t_cryb_strlcpy, &t_cases[i], + "%s (cryb)", t_cases[i].desc); +#if HAVE_STRLCPY + for (i = 0; i < n; ++i) + t_add_test(t_libc_strlcpy, &t_cases[i], + "%s (libc)", t_cases[i].desc); +#endif return (0); }