From fcc088cd59760315c73d42b545a6cf7219456d97 Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 4 Nov 2011 15:48:10 +0000 Subject: [PATCH] stylistic improvements. --- tests/lib/libc/regex/t_exhaust.c | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/lib/libc/regex/t_exhaust.c b/tests/lib/libc/regex/t_exhaust.c index 2520df5a7d83..59fb7808114a 100644 --- a/tests/lib/libc/regex/t_exhaust.c +++ b/tests/lib/libc/regex/t_exhaust.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ +/* $NetBSD: t_exhaust.c,v 1.3 2011/11/04 15:48:10 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__RCSID("$NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $"); +__RCSID("$NetBSD: t_exhaust.c,v 1.3 2011/11/04 15:48:10 christos Exp $"); #include #include @@ -52,8 +52,7 @@ mkstr(const char *str, size_t len) { size_t slen = strlen(str); char *p = malloc(slen * len + 1); - if (p == NULL) - err(1, "malloc"); + ATF_REQUIRE(p != NULL); for (size_t i = 0; i < len; i++) strcpy(&p[i * slen], str); return p; @@ -65,6 +64,8 @@ concat(const char *d, const char *s) size_t dlen = strlen(d); size_t slen = strlen(s); char *p = malloc(dlen + slen + 1); + + ATF_REQUIRE(p != NULL); strcpy(p, d); strcpy(p + dlen, s); return p; @@ -150,14 +151,17 @@ p6(size_t len) return d; } -static char *(*patterns[])(size_t) = { - p0, - p1, - p2, - p3, - p4, - p5, - p6, +static const struct { + char *(*pattern)(size_t); + int type; +} tests[] = { + { p0, REG_EXTENDED }, + { p1, REG_EXTENDED }, + { p2, REG_EXTENDED }, + { p3, REG_EXTENDED }, + { p4, REG_EXTENDED }, + { p5, REG_EXTENDED }, + { p6, REG_BASIC }, }; ATF_TC(regcomp_too_big); @@ -174,16 +178,16 @@ ATF_TC_BODY(regcomp_too_big, tc) regex_t re; int e; - for (size_t i = 0; i < __arraycount(patterns); i++) { - char *d = (*patterns[i])(9999); - e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); + for (size_t i = 0; i < __arraycount(tests); i++) { + char *d = (*tests[i].pattern)(9999); + e = regcomp(&re, d, tests[i].type); free(d); if (e) { ATF_REQUIRE_MSG(e == REG_ESPACE, "regcomp returned %d for pattern %zu", e, i); continue; } - (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); + (void)regexec(&re, "aaaaaaaaaaa", 0, NULL, 0); regfree(&re); } }