From 33c506bfed3ead4cc96819ce600895082c214755 Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Thu, 31 Jul 2003 21:48:04 +0000 Subject: various cleanups; david says results are same --- src/regress/lib/libc/regex/debug.c | 6 +++--- src/regress/lib/libc/regex/main.c | 29 +++++++++++++++-------------- src/regress/lib/libc/regex/split.c | 10 ++++------ 3 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src/regress/lib/libc/regex') diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c index 7834e970c7..11129e7249 100644 --- a/src/regress/lib/libc/regex/debug.c +++ b/src/regress/lib/libc/regex/debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: debug.c,v 1.3 2001/01/29 02:05:43 niklas Exp $ */ +/* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ #include @@ -238,8 +238,8 @@ int ch; static char buf[10]; if (isprint(ch) || ch == ' ') - sprintf(buf, "%c", ch); + snprintf(buf, sizeof buf, "%c", ch); else - sprintf(buf, "\\%o", ch); + snprintf(buf, sizeof buf, "\\%o", ch); return(buf); } diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 6e63ffc235..02f4bd7cf2 100644 --- a/src/regress/lib/libc/regex/main.c +++ b/src/regress/lib/libc/regex/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.3 1997/01/15 23:41:07 millert Exp $ */ +/* $OpenBSD: main.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ #include @@ -22,16 +22,15 @@ regoff_t startoff = 0; regoff_t endoff = 0; -extern int split(); -extern void regprint(); +extern int split(char *, char *[], int, char *); +extern void regprint(regex_t *, FILE *); /* - main - do the simple case, hand off to regress() for regression */ int -main(argc, argv) -int argc; -char *argv[]; +main(int argc, char *argv[]) + { regex_t re; # define NS 10 @@ -431,8 +430,9 @@ char *should; (sub.rm_so != -1 && sub.rm_eo == -1) || (sub.rm_so != -1 && sub.rm_so < 0) || (sub.rm_eo != -1 && sub.rm_eo < 0) ) { - sprintf(grump, "start %ld end %ld", (long)sub.rm_so, - (long)sub.rm_eo); + snprintf(grump, sizeof grump, + "start %ld end %ld", (long)sub.rm_so, + (long)sub.rm_eo); return(grump); } @@ -444,8 +444,9 @@ char *should; /* check for in range */ if (sub.rm_eo > strlen(str)) { - sprintf(grump, "start %ld end %ld, past end of string", - (long)sub.rm_so, (long)sub.rm_eo); + snprintf(grump, sizeof grump, + "start %ld end %ld, past end of string", + (long)sub.rm_so, (long)sub.rm_eo); return(grump); } @@ -455,13 +456,13 @@ char *should; /* check for not supposed to match */ if (should == NULL) { - sprintf(grump, "matched `%.*s'", len, p); + snprintf(grump, sizeof grump, "matched `%.*s'", len, p); return(grump); } /* check for wrong match */ if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { - sprintf(grump, "matched `%.*s' instead", len, p); + snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); return(grump); } if (shlen > 0) @@ -474,7 +475,7 @@ char *should; if (shlen == 0) shlen = 1; /* force check for end-of-string */ if (strncmp(p, at, shlen) != 0) { - sprintf(grump, "matched null at `%.20s'", p); + snprintf(grump, sizeof grump, "matched null at `%.20s'", p); return(grump); } return(NULL); @@ -507,7 +508,7 @@ char *name; static char efbuf[100]; regex_t re; - sprintf(efbuf, "REG_%s", name); + snprintf(efbuf, sizeof efbuf, "REG_%s", name); assert(strlen(efbuf) < sizeof(efbuf)); re.re_endp = efbuf; (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c index 52cb6c681e..1e17a55b89 100644 --- a/src/regress/lib/libc/regex/split.c +++ b/src/regress/lib/libc/regex/split.c @@ -1,19 +1,17 @@ -/* $OpenBSD: split.c,v 1.2 2001/01/29 02:05:44 niklas Exp $ */ +/* $OpenBSD: split.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ #include #include +int split(char *string, char *fields[], int nfields, char *sep); + /* - split - divide a string into fields, like awk split() = int split(char *string, char *fields[], int nfields, char *sep); */ int /* number of fields, including overflow */ -split(string, fields, nfields, sep) -char *string; -char *fields[]; /* list is not NULL-terminated */ -int nfields; /* number of entries available in fields[] */ -char *sep; /* "" white, "c" single char, "ab" [ab]+ */ +split(char *string, char *fields[], int nfields, char *sep) { register char *p = string; register char c; /* latest character */ -- cgit v1.2.3-55-g6feb