diff options
Diffstat (limited to 'src/regress/lib/libc/regex')
| -rw-r--r-- | src/regress/lib/libc/regex/Makefile | 18 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/debug.c | 7 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/debug.ih | 7 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/main.c | 52 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/main.ih | 17 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/split.c | 17 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/t_exhaust.c | 186 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/tests | 26 |
8 files changed, 278 insertions, 52 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile index 93b7bb9052..6b646a46ac 100644 --- a/src/regress/lib/libc/regex/Makefile +++ b/src/regress/lib/libc/regex/Makefile | |||
| @@ -1,16 +1,24 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.8 2011/11/05 15:07:12 otto Exp $ | ||
| 1 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ |
| 2 | 3 | ||
| 3 | PROG= re | 4 | PROG= re |
| 4 | SRCS= main.c split.c debug.c | 5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c |
| 5 | NOMAN= | 6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex |
| 7 | CLEANFILES += t_exhaust | ||
| 6 | 8 | ||
| 7 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex | 9 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE |
| 8 | 10 | ||
| 9 | TESTS= ${.CURDIR}/tests | 11 | TESTS= ${.CURDIR}/tests |
| 10 | 12 | ||
| 11 | regress: | 13 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref do-t_exhaust |
| 14 | |||
| 15 | do-reg: ${PROG} | ||
| 12 | ./re < ${TESTS} | 16 | ./re < ${TESTS} |
| 17 | do-reg-long: ${PROG} | ||
| 13 | ./re -el < ${TESTS} | 18 | ./re -el < ${TESTS} |
| 19 | do-reg-backref: ${PROG} | ||
| 14 | ./re -er < ${TESTS} | 20 | ./re -er < ${TESTS} |
| 21 | do-t_exhaust: t_exhaust | ||
| 22 | ./t_exhaust | ||
| 15 | 23 | ||
| 16 | .include <bsd.prog.mk> | 24 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c index 861f550611..11129e7249 100644 --- a/src/regress/lib/libc/regex/debug.c +++ b/src/regress/lib/libc/regex/debug.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 1 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | 2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| @@ -218,7 +219,7 @@ FILE *d; | |||
| 218 | fprintf(d, ">"); | 219 | fprintf(d, ">"); |
| 219 | break; | 220 | break; |
| 220 | default: | 221 | default: |
| 221 | fprintf(d, "!%d(%d)!", OP(*s), opnd); | 222 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); |
| 222 | break; | 223 | break; |
| 223 | } | 224 | } |
| 224 | if (!done) | 225 | if (!done) |
| @@ -237,8 +238,8 @@ int ch; | |||
| 237 | static char buf[10]; | 238 | static char buf[10]; |
| 238 | 239 | ||
| 239 | if (isprint(ch) || ch == ' ') | 240 | if (isprint(ch) || ch == ' ') |
| 240 | sprintf(buf, "%c", ch); | 241 | snprintf(buf, sizeof buf, "%c", ch); |
| 241 | else | 242 | else |
| 242 | sprintf(buf, "\\%o", ch); | 243 | snprintf(buf, sizeof buf, "\\%o", ch); |
| 243 | return(buf); | 244 | return(buf); |
| 244 | } | 245 | } |
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih index fb9bac0c75..9eb313af23 100644 --- a/src/regress/lib/libc/regex/debug.ih +++ b/src/regress/lib/libc/regex/debug.ih | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 1 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | 2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
| @@ -6,9 +7,9 @@ extern "C" { | |||
| 6 | #endif | 7 | #endif |
| 7 | 8 | ||
| 8 | /* === debug.c === */ | 9 | /* === debug.c === */ |
| 9 | void regprint __P((regex_t *r, FILE *d)); | 10 | void regprint(regex_t *r, FILE *d); |
| 10 | static void s_print __P((register struct re_guts *g, FILE *d)); | 11 | static void s_print(register struct re_guts *g, FILE *d); |
| 11 | static char *regchar __P((int ch)); | 12 | static char *regchar(int ch); |
| 12 | 13 | ||
| 13 | #ifdef __cplusplus | 14 | #ifdef __cplusplus |
| 14 | } | 15 | } |
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 8d88a8b9b8..e0ed86f5e8 100644 --- a/src/regress/lib/libc/regex/main.c +++ b/src/regress/lib/libc/regex/main.c | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.7 2007/09/12 19:32:35 otto Exp $ */ | ||
| 1 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> | ||
| 4 | #include <string.h> | 6 | #include <string.h> |
| 5 | #include <sys/types.h> | 7 | #include <sys/types.h> |
| 6 | #include <regex.h> | 8 | #include <regex.h> |
| 7 | #include <assert.h> | 9 | #include <assert.h> |
| 10 | #include <unistd.h> | ||
| 8 | 11 | ||
| 9 | #include "main.ih" | 12 | #include "main.ih" |
| 10 | 13 | ||
| @@ -19,15 +22,15 @@ regoff_t startoff = 0; | |||
| 19 | regoff_t endoff = 0; | 22 | regoff_t endoff = 0; |
| 20 | 23 | ||
| 21 | 24 | ||
| 22 | extern int split(); | 25 | extern int split(char *, char *[], int, char *); |
| 23 | extern void regprint(); | 26 | extern void regprint(regex_t *, FILE *); |
| 24 | 27 | ||
| 25 | /* | 28 | /* |
| 26 | - main - do the simple case, hand off to regress() for regression | 29 | - main - do the simple case, hand off to regress() for regression |
| 27 | */ | 30 | */ |
| 28 | main(argc, argv) | 31 | int |
| 29 | int argc; | 32 | main(int argc, char *argv[]) |
| 30 | char *argv[]; | 33 | |
| 31 | { | 34 | { |
| 32 | regex_t re; | 35 | regex_t re; |
| 33 | # define NS 10 | 36 | # define NS 10 |
| @@ -43,7 +46,7 @@ char *argv[]; | |||
| 43 | 46 | ||
| 44 | progname = argv[0]; | 47 | progname = argv[0]; |
| 45 | 48 | ||
| 46 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) | 49 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1) |
| 47 | switch (c) { | 50 | switch (c) { |
| 48 | case 'c': /* compile options */ | 51 | case 'c': /* compile options */ |
| 49 | copts = options('c', optarg); | 52 | copts = options('c', optarg); |
| @@ -79,7 +82,7 @@ char *argv[]; | |||
| 79 | err = regcomp(&re, argv[optind++], copts); | 82 | err = regcomp(&re, argv[optind++], copts); |
| 80 | if (err) { | 83 | if (err) { |
| 81 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 84 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
| 82 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 85 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
| 83 | eprint(err), len, sizeof(erbuf), erbuf); | 86 | eprint(err), len, sizeof(erbuf), erbuf); |
| 84 | exit(status); | 87 | exit(status); |
| 85 | } | 88 | } |
| @@ -97,15 +100,15 @@ char *argv[]; | |||
| 97 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | 100 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); |
| 98 | if (err) { | 101 | if (err) { |
| 99 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 102 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
| 100 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 103 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
| 101 | eprint(err), len, sizeof(erbuf), erbuf); | 104 | eprint(err), len, sizeof(erbuf), erbuf); |
| 102 | exit(status); | 105 | exit(status); |
| 103 | } | 106 | } |
| 104 | if (!(copts®_NOSUB)) { | 107 | if (!(copts®_NOSUB)) { |
| 105 | len = (int)(subs[0].rm_eo - subs[0].rm_so); | 108 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); |
| 106 | if (subs[0].rm_so != -1) { | 109 | if (subs[0].rm_so != -1) { |
| 107 | if (len != 0) | 110 | if (len != 0) |
| 108 | printf("match `%.*s'\n", len, | 111 | printf("match `%.*s'\n", (int)len, |
| 109 | argv[optind] + subs[0].rm_so); | 112 | argv[optind] + subs[0].rm_so); |
| 110 | else | 113 | else |
| 111 | printf("match `'@%.1s\n", | 114 | printf("match `'@%.1s\n", |
| @@ -144,7 +147,7 @@ FILE *in; | |||
| 144 | line++; | 147 | line++; |
| 145 | if (inbuf[0] == '#' || inbuf[0] == '\n') | 148 | if (inbuf[0] == '#' || inbuf[0] == '\n') |
| 146 | continue; /* NOTE CONTINUE */ | 149 | continue; /* NOTE CONTINUE */ |
| 147 | inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ | 150 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ |
| 148 | if (debug) | 151 | if (debug) |
| 149 | fprintf(stdout, "%d:\n", line); | 152 | fprintf(stdout, "%d:\n", line); |
| 150 | nf = split(inbuf, f, MAXF, "\t\t"); | 153 | nf = split(inbuf, f, MAXF, "\t\t"); |
| @@ -225,14 +228,14 @@ int opts; /* may not match f1 */ | |||
| 225 | char f0copy[1000]; | 228 | char f0copy[1000]; |
| 226 | char f2copy[1000]; | 229 | char f2copy[1000]; |
| 227 | 230 | ||
| 228 | strcpy(f0copy, f0); | 231 | strlcpy(f0copy, f0, sizeof f0copy); |
| 229 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | 232 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; |
| 230 | fixstr(f0copy); | 233 | fixstr(f0copy); |
| 231 | err = regcomp(&re, f0copy, opts); | 234 | err = regcomp(&re, f0copy, opts); |
| 232 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | 235 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { |
| 233 | /* unexpected error or wrong error */ | 236 | /* unexpected error or wrong error */ |
| 234 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 237 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
| 235 | fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n", | 238 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", |
| 236 | line, type, eprint(err), len, | 239 | line, type, eprint(err), len, |
| 237 | sizeof(erbuf), erbuf); | 240 | sizeof(erbuf), erbuf); |
| 238 | status = 1; | 241 | status = 1; |
| @@ -249,7 +252,7 @@ int opts; /* may not match f1 */ | |||
| 249 | return; | 252 | return; |
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | strcpy(f2copy, f2); | 255 | strlcpy(f2copy, f2, sizeof f2copy); |
| 253 | fixstr(f2copy); | 256 | fixstr(f2copy); |
| 254 | 257 | ||
| 255 | if (options('e', f1)®_STARTEND) { | 258 | if (options('e', f1)®_STARTEND) { |
| @@ -263,7 +266,7 @@ int opts; /* may not match f1 */ | |||
| 263 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | 266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { |
| 264 | /* unexpected error or wrong error */ | 267 | /* unexpected error or wrong error */ |
| 265 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
| 266 | fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n", | 269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", |
| 267 | line, type, eprint(err), len, | 270 | line, type, eprint(err), len, |
| 268 | sizeof(erbuf), erbuf); | 271 | sizeof(erbuf), erbuf); |
| 269 | status = 1; | 272 | status = 1; |
| @@ -427,8 +430,9 @@ char *should; | |||
| 427 | (sub.rm_so != -1 && sub.rm_eo == -1) || | 430 | (sub.rm_so != -1 && sub.rm_eo == -1) || |
| 428 | (sub.rm_so != -1 && sub.rm_so < 0) || | 431 | (sub.rm_so != -1 && sub.rm_so < 0) || |
| 429 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | 432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { |
| 430 | sprintf(grump, "start %ld end %ld", (long)sub.rm_so, | 433 | snprintf(grump, sizeof grump, |
| 431 | (long)sub.rm_eo); | 434 | "start %ld end %ld", (long)sub.rm_so, |
| 435 | (long)sub.rm_eo); | ||
| 432 | return(grump); | 436 | return(grump); |
| 433 | } | 437 | } |
| 434 | 438 | ||
| @@ -440,8 +444,9 @@ char *should; | |||
| 440 | 444 | ||
| 441 | /* check for in range */ | 445 | /* check for in range */ |
| 442 | if (sub.rm_eo > strlen(str)) { | 446 | if (sub.rm_eo > strlen(str)) { |
| 443 | sprintf(grump, "start %ld end %ld, past end of string", | 447 | snprintf(grump, sizeof grump, |
| 444 | (long)sub.rm_so, (long)sub.rm_eo); | 448 | "start %ld end %ld, past end of string", |
| 449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
| 445 | return(grump); | 450 | return(grump); |
| 446 | } | 451 | } |
| 447 | 452 | ||
| @@ -451,13 +456,13 @@ char *should; | |||
| 451 | 456 | ||
| 452 | /* check for not supposed to match */ | 457 | /* check for not supposed to match */ |
| 453 | if (should == NULL) { | 458 | if (should == NULL) { |
| 454 | sprintf(grump, "matched `%.*s'", len, p); | 459 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); |
| 455 | return(grump); | 460 | return(grump); |
| 456 | } | 461 | } |
| 457 | 462 | ||
| 458 | /* check for wrong match */ | 463 | /* check for wrong match */ |
| 459 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | 464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { |
| 460 | sprintf(grump, "matched `%.*s' instead", len, p); | 465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); |
| 461 | return(grump); | 466 | return(grump); |
| 462 | } | 467 | } |
| 463 | if (shlen > 0) | 468 | if (shlen > 0) |
| @@ -470,7 +475,7 @@ char *should; | |||
| 470 | if (shlen == 0) | 475 | if (shlen == 0) |
| 471 | shlen = 1; /* force check for end-of-string */ | 476 | shlen = 1; /* force check for end-of-string */ |
| 472 | if (strncmp(p, at, shlen) != 0) { | 477 | if (strncmp(p, at, shlen) != 0) { |
| 473 | sprintf(grump, "matched null at `%.20s'", p); | 478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); |
| 474 | return(grump); | 479 | return(grump); |
| 475 | } | 480 | } |
| 476 | return(NULL); | 481 | return(NULL); |
| @@ -501,10 +506,9 @@ efind(name) | |||
| 501 | char *name; | 506 | char *name; |
| 502 | { | 507 | { |
| 503 | static char efbuf[100]; | 508 | static char efbuf[100]; |
| 504 | size_t n; | ||
| 505 | regex_t re; | 509 | regex_t re; |
| 506 | 510 | ||
| 507 | sprintf(efbuf, "REG_%s", name); | 511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); |
| 508 | assert(strlen(efbuf) < sizeof(efbuf)); | 512 | assert(strlen(efbuf) < sizeof(efbuf)); |
| 509 | re.re_endp = efbuf; | 513 | re.re_endp = efbuf; |
| 510 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | 514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); |
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih index 135e3e792d..0860e26333 100644 --- a/src/regress/lib/libc/regex/main.ih +++ b/src/regress/lib/libc/regex/main.ih | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 1 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | 2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
| @@ -6,14 +7,14 @@ extern "C" { | |||
| 6 | #endif | 7 | #endif |
| 7 | 8 | ||
| 8 | /* === main.c === */ | 9 | /* === main.c === */ |
| 9 | void regress __P((FILE *in)); | 10 | void regress(FILE *in); |
| 10 | void try __P((char *f0, char *f1, char *f2, char *f3, char *f4, int opts)); | 11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); |
| 11 | int options __P((int type, char *s)); | 12 | int options(int type, char *s); |
| 12 | int opt __P((int c, char *s)); | 13 | int opt(int c, char *s); |
| 13 | void fixstr __P((register char *p)); | 14 | void fixstr(register char *p); |
| 14 | char *check __P((char *str, regmatch_t sub, char *should)); | 15 | char *check(char *str, regmatch_t sub, char *should); |
| 15 | static char *eprint __P((int err)); | 16 | static char *eprint(int err); |
| 16 | static int efind __P((char *name)); | 17 | static int efind(char *name); |
| 17 | 18 | ||
| 18 | #ifdef __cplusplus | 19 | #ifdef __cplusplus |
| 19 | } | 20 | } |
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c index dd1ca14480..fcd81a3503 100644 --- a/src/regress/lib/libc/regex/split.c +++ b/src/regress/lib/libc/regex/split.c | |||
| @@ -1,18 +1,17 @@ | |||
| 1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
| 1 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | 2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| 4 | #include <string.h> | 5 | #include <string.h> |
| 5 | 6 | ||
| 7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
| 8 | |||
| 6 | /* | 9 | /* |
| 7 | - split - divide a string into fields, like awk split() | 10 | - split - divide a string into fields, like awk split() |
| 8 | = int split(char *string, char *fields[], int nfields, char *sep); | 11 | = int split(char *string, char *fields[], int nfields, char *sep); |
| 9 | */ | 12 | */ |
| 10 | int /* number of fields, including overflow */ | 13 | int /* number of fields, including overflow */ |
| 11 | split(string, fields, nfields, sep) | 14 | split(char *string, char *fields[], int nfields, char *sep) |
| 12 | char *string; | ||
| 13 | char *fields[]; /* list is not NULL-terminated */ | ||
| 14 | int nfields; /* number of entries available in fields[] */ | ||
| 15 | char *sep; /* "" white, "c" single char, "ab" [ab]+ */ | ||
| 16 | { | 15 | { |
| 17 | register char *p = string; | 16 | register char *p = string; |
| 18 | register char c; /* latest character */ | 17 | register char c; /* latest character */ |
| @@ -161,18 +160,18 @@ char *argv[]; | |||
| 161 | 160 | ||
| 162 | if (argc > 4) | 161 | if (argc > 4) |
| 163 | for (n = atoi(argv[3]); n > 0; n--) { | 162 | for (n = atoi(argv[3]); n > 0; n--) { |
| 164 | (void) strcpy(buf, argv[1]); | 163 | (void) strlcpy(buf, argv[1], sizeof buf); |
| 165 | } | 164 | } |
| 166 | else if (argc > 3) | 165 | else if (argc > 3) |
| 167 | for (n = atoi(argv[3]); n > 0; n--) { | 166 | for (n = atoi(argv[3]); n > 0; n--) { |
| 168 | (void) strcpy(buf, argv[1]); | 167 | (void) strlcpy(buf, argv[1], sizeof buf); |
| 169 | (void) split(buf, fields, MNF, argv[2]); | 168 | (void) split(buf, fields, MNF, argv[2]); |
| 170 | } | 169 | } |
| 171 | else if (argc > 2) | 170 | else if (argc > 2) |
| 172 | dosplit(argv[1], argv[2]); | 171 | dosplit(argv[1], argv[2]); |
| 173 | else if (argc > 1) | 172 | else if (argc > 1) |
| 174 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | 173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { |
| 175 | buf[strlen(buf)-1] = '\0'; /* stomp newline */ | 174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ |
| 176 | dosplit(buf, argv[1]); | 175 | dosplit(buf, argv[1]); |
| 177 | } | 176 | } |
| 178 | else | 177 | else |
| @@ -287,7 +286,7 @@ regress() | |||
| 287 | register char *f; | 286 | register char *f; |
| 288 | 287 | ||
| 289 | for (n = 0; tests[n].str != NULL; n++) { | 288 | for (n = 0; tests[n].str != NULL; n++) { |
| 290 | (void) strcpy(buf, tests[n].str); | 289 | (void) strlcpy(buf, tests[n].str, sizeof buf); |
| 291 | fields[RNF] = NULL; | 290 | fields[RNF] = NULL; |
| 292 | nf = split(buf, fields, RNF, tests[n].seps); | 291 | nf = split(buf, fields, RNF, tests[n].seps); |
| 293 | printit = 0; | 292 | printit = 0; |
diff --git a/src/regress/lib/libc/regex/t_exhaust.c b/src/regress/lib/libc/regex/t_exhaust.c new file mode 100644 index 0000000000..e4d4e4f5d7 --- /dev/null +++ b/src/regress/lib/libc/regex/t_exhaust.c | |||
| @@ -0,0 +1,186 @@ | |||
| 1 | /* $OpenBSD: t_exhaust.c,v 1.2 2011/11/06 15:47:07 otto Exp $ */ | ||
| 2 | /* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 9 | * by Christos Zoulas. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * 3. All advertising materials mentioning features or use of this software | ||
| 20 | * must display the following acknowledgement: | ||
| 21 | * This product includes software developed by the NetBSD | ||
| 22 | * Foundation, Inc. and its contributors. | ||
| 23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
| 24 | * contributors may be used to endorse or promote products derived | ||
| 25 | * from this software without specific prior written permission. | ||
| 26 | * | ||
| 27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 37 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <sys/cdefs.h> | ||
| 41 | |||
| 42 | #include <stdio.h> | ||
| 43 | #include <regex.h> | ||
| 44 | #include <string.h> | ||
| 45 | #include <stdlib.h> | ||
| 46 | #include <err.h> | ||
| 47 | //#include <atf-c.h> | ||
| 48 | |||
| 49 | |||
| 50 | static char * | ||
| 51 | mkstr(const char *str, size_t len) | ||
| 52 | { | ||
| 53 | size_t i, slen = strlen(str); | ||
| 54 | char *p = malloc(slen * len + 1); | ||
| 55 | if (p == NULL) | ||
| 56 | err(1, "malloc"); | ||
| 57 | for (i = 0; i < len; i++) | ||
| 58 | strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen)); | ||
| 59 | return p; | ||
| 60 | } | ||
| 61 | |||
| 62 | static char * | ||
| 63 | concat(const char *d, const char *s) | ||
| 64 | { | ||
| 65 | size_t dlen = strlen(d); | ||
| 66 | size_t slen = strlen(s); | ||
| 67 | char *p = malloc(dlen + slen + 1); | ||
| 68 | strlcpy(p, d, dlen + slen + 1); | ||
| 69 | strlcat(p, s, dlen + slen + 1); | ||
| 70 | return p; | ||
| 71 | } | ||
| 72 | |||
| 73 | static char * | ||
| 74 | p0(size_t len) | ||
| 75 | { | ||
| 76 | char *d, *s1, *s2; | ||
| 77 | s1 = mkstr("\\(", len); | ||
| 78 | s2 = concat(s1, ")"); | ||
| 79 | free(s1); | ||
| 80 | d = concat("(", s2); | ||
| 81 | free(s2); | ||
| 82 | return d; | ||
| 83 | } | ||
| 84 | |||
| 85 | static char * | ||
| 86 | p1(size_t len) | ||
| 87 | { | ||
| 88 | char *d, *s1, *s2, *s3; | ||
| 89 | s1 = mkstr("\\(", 60); | ||
| 90 | s2 = mkstr("(.*)", len); | ||
| 91 | s3 = concat(s1, s2); | ||
| 92 | free(s2); | ||
| 93 | free(s1); | ||
| 94 | s1 = concat(s3, ")"); | ||
| 95 | free(s3); | ||
| 96 | d = concat("(", s1); | ||
| 97 | free(s1); | ||
| 98 | return d; | ||
| 99 | } | ||
| 100 | |||
| 101 | static char * | ||
| 102 | ps(const char *m, const char *s, size_t len) | ||
| 103 | { | ||
| 104 | char *d, *s1, *s2, *s3; | ||
| 105 | s1 = mkstr(m, len); | ||
| 106 | s2 = mkstr(s, len); | ||
| 107 | s3 = concat(s1, s2); | ||
| 108 | free(s2); | ||
| 109 | free(s1); | ||
| 110 | d = concat("(.?)", s3); | ||
| 111 | free(s3); | ||
| 112 | return d; | ||
| 113 | } | ||
| 114 | |||
| 115 | static char * | ||
| 116 | p2(size_t len) | ||
| 117 | { | ||
| 118 | return ps("((.*){0,255}", ")", len); | ||
| 119 | } | ||
| 120 | |||
| 121 | static char * | ||
| 122 | p3(size_t len) | ||
| 123 | { | ||
| 124 | return ps("(.\\{0,}", ")", len); | ||
| 125 | } | ||
| 126 | |||
| 127 | static char * | ||
| 128 | p4(size_t len) | ||
| 129 | { | ||
| 130 | return ps("((.*){1,255}", ")", len); | ||
| 131 | } | ||
| 132 | |||
| 133 | static char * | ||
| 134 | p5(size_t len) | ||
| 135 | { | ||
| 136 | return ps("(", "){1,100}", len); | ||
| 137 | } | ||
| 138 | |||
| 139 | static char * | ||
| 140 | p6(size_t len) | ||
| 141 | { | ||
| 142 | char *d, *s1, *s2; | ||
| 143 | s1 = mkstr("(?:(.*)|", len); | ||
| 144 | s2 = concat(s1, "(.*)"); | ||
| 145 | free(s1); | ||
| 146 | s1 = mkstr(")", len); | ||
| 147 | d = concat(s2, s1); | ||
| 148 | free(s1); | ||
| 149 | free(s2); | ||
| 150 | return d; | ||
| 151 | } | ||
| 152 | |||
| 153 | static char *(*patterns[])(size_t) = { | ||
| 154 | p0, | ||
| 155 | p1, | ||
| 156 | p2, | ||
| 157 | p3, | ||
| 158 | p4, | ||
| 159 | p5, | ||
| 160 | p6, | ||
| 161 | }; | ||
| 162 | |||
| 163 | |||
| 164 | main() | ||
| 165 | { | ||
| 166 | regex_t re; | ||
| 167 | int e, ret = 0; | ||
| 168 | size_t i; | ||
| 169 | |||
| 170 | for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { | ||
| 171 | char *d = (*patterns[i])(9999); | ||
| 172 | e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); | ||
| 173 | free(d); | ||
| 174 | if (e) { | ||
| 175 | if (e != REG_ESPACE) { | ||
| 176 | printf("regcomp returned %d for pattern %zu", e, i); | ||
| 177 | ret = 1; | ||
| 178 | } | ||
| 179 | continue; | ||
| 180 | } | ||
| 181 | (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); | ||
| 182 | regfree(&re); | ||
| 183 | } | ||
| 184 | return ret; | ||
| 185 | } | ||
| 186 | |||
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests index 8e89f161b1..c827c868b7 100644 --- a/src/regress/lib/libc/regex/tests +++ b/src/regress/lib/libc/regex/tests | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | # $OpenBSD: tests,v 1.5 2004/11/29 16:50:31 otto Exp $ | ||
| 1 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | 2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ |
| 2 | 3 | ||
| 3 | # regular expression test set | 4 | # regular expression test set |
| @@ -168,6 +169,30 @@ a\(\(b\)*\2\)*d b abbbd abbbd | |||
| 168 | \(a\)\1bc*d b aabcccd aabcccd | 169 | \(a\)\1bc*d b aabcccd aabcccd |
| 169 | \(a\)\1bc*[ce]d b aabcccd aabcccd | 170 | \(a\)\1bc*[ce]d b aabcccd aabcccd |
| 170 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | 171 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd |
| 172 | \(b*\)\(a*\1\)* b ab a | ||
| 173 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
| 174 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
| 175 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
| 176 | \(.*\)\1 b "" "" | ||
| 177 | \(.*\)\1 b a "" | ||
| 178 | \(.*\)\1 b aa aa | ||
| 179 | \(.*\)\1 b aaa aa | ||
| 180 | \(.*\)\1 b aaaa aaaa | ||
| 181 | \([^_]*\)\1 b "" "" | ||
| 182 | \([^_]*\)\1 b a "" | ||
| 183 | \([^_]*\)\1 b aa aa | ||
| 184 | \([^_]*\)\1 b aaa aa | ||
| 185 | \([^_]*\)\1 b aaaa aaaa | ||
| 186 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
| 187 | foo\(.*\)bar\1 b foobar foobar "" | ||
| 188 | \(\(.\)b\)*\1 b aba | ||
| 189 | \(\(.\)b\)*\1 b abba | ||
| 190 | \(\(.\)b\)*\1 b abbba | ||
| 191 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
| 192 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
| 193 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
| 194 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
| 195 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
| 171 | 196 | ||
| 172 | # ordinary repetitions | 197 | # ordinary repetitions |
| 173 | ab*c & abc abc | 198 | ab*c & abc abc |
| @@ -475,3 +500,4 @@ CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | |||
| 475 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | 500 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz |
| 476 | a?b - ab ab | 501 | a?b - ab ab |
| 477 | -\{0,1\}[0-9]*$ b -5 -5 | 502 | -\{0,1\}[0-9]*$ b -5 -5 |
| 503 | |||
