summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Valchev <pvalchev@cvs.openbsd.org>2003-04-06 06:12:02 +0000
committerPeter Valchev <pvalchev@cvs.openbsd.org>2003-04-06 06:12:02 +0000
commitb4b554091d09542655ec20a4662ffdc741e847e3 (patch)
treeca19f3175c9cfc8dd7580d247f9aef8007d9a5af
parentf55330f67f5d8f384f364f1c35cbf5bf1e25b367 (diff)
more string business; millert ok and suggestion for strdup
-rw-r--r--usr.bin/awk/run.c14
-rw-r--r--usr.bin/awk/tran.c14
2 files changed, 11 insertions, 17 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c
index abbf3d3717b..a2528d662c5 100644
--- a/usr.bin/awk/run.c
+++ b/usr.bin/awk/run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: run.c,v 1.19 2003/04/04 00:42:34 deraadt Exp $ */
+/* $OpenBSD: run.c,v 1.20 2003/04/06 06:12:01 pvalchev Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -458,9 +458,9 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
s = getsval(y);
if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
FATAL("out of memory for %s[%s...]", x->nval, buf);
- strcat(buf, s);
+ strlcat(buf, s, bufsz);
if (np->nnext)
- strcat(buf, *SUBSEP);
+ strlcat(buf, *SUBSEP, bufsz);
tempfree(y);
}
if (!isarr(x)) {
@@ -505,9 +505,9 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts *
s = getsval(y);
if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
FATAL("out of memory deleting %s[%s...]", x->nval, buf);
- strcat(buf, s);
+ strlcat(buf, s, bufsz);
if (np->nnext)
- strcat(buf, *SUBSEP);
+ strlcat(buf, *SUBSEP, bufsz);
tempfree(y);
}
freeelem(x, buf);
@@ -544,10 +544,10 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */
s = getsval(x);
if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
FATAL("out of memory deleting %s[%s...]", x->nval, buf);
- strcat(buf, s);
+ strlcat(buf, s, bufsz);
tempfree(x);
if (p->nnext)
- strcat(buf, *SUBSEP);
+ strlcat(buf, *SUBSEP, bufsz);
}
k = lookup(buf, (Array *) ap->sval);
tempfree(ap);
diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c
index f7f8440b503..170fe76d0fa 100644
--- a/usr.bin/awk/tran.c
+++ b/usr.bin/awk/tran.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tran.c,v 1.9 2003/04/04 00:42:34 deraadt Exp $ */
+/* $OpenBSD: tran.c,v 1.10 2003/04/06 06:12:01 pvalchev Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -372,9 +372,9 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
if (freeable(vp))
xfree(vp->sval);
if (modf(vp->fval, &dtemp) == 0) /* it's integral */
- sprintf(s, "%.30g", vp->fval);
+ snprintf(s, sizeof(s), "%.30g", vp->fval);
else
- sprintf(s, *fmt, vp->fval);
+ snprintf(s, sizeof(s), *fmt, vp->fval);
vp->sval = tostring(s);
vp->tval &= ~DONTFREE;
vp->tval |= STR;
@@ -396,13 +396,7 @@ char *getpssval(Cell *vp) /* get string val of a Cell for print */
char *tostring(const char *s) /* make a copy of string s */
{
- char *p;
-
- p = (char *) malloc(strlen(s)+1);
- if (p == NULL)
- FATAL("out of space in tostring on %s", s);
- strcpy(p, s);
- return(p);
+ return (strdup(s));
}
char *qstring(const char *is, int delim) /* collect string up to next delim */