Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/regex stylistic improvements.
details: https://anonhg.NetBSD.org/src/rev/08111f83f4ee
branches: trunk
changeset: 770963:08111f83f4ee
user: christos <christos%NetBSD.org@localhost>
date: Fri Nov 04 15:48:10 2011 +0000
description:
stylistic improvements.
diffstat:
tests/lib/libc/regex/t_exhaust.c | 36 ++++++++++++++++++++----------------
1 files changed, 20 insertions(+), 16 deletions(-)
diffs (84 lines):
diff -r 33cb6d513ac1 -r 08111f83f4ee tests/lib/libc/regex/t_exhaust.c
--- a/tests/lib/libc/regex/t_exhaust.c Fri Nov 04 15:32:34 2011 +0000
+++ b/tests/lib/libc/regex/t_exhaust.c Fri Nov 04 15:48:10 2011 +0000
@@ -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 <sys/cdefs.h>
-__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 <stdio.h>
#include <regex.h>
@@ -52,8 +52,7 @@
{
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 @@
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 @@
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 @@
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);
}
}
Home |
Main Index |
Thread Index |
Old Index