summaryrefslogtreecommitdiff
path: root/usr.bin/awk
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-04-15 15:54:27 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-04-15 15:54:27 +0000
commit267302849ada3e678d80d57c5a34931ad67841eb (patch)
treebf13d339b3e483430faad120f546781928533733 /usr.bin/awk
parentfaf01ac311a51242ed3d2d01510b9031d37360f4 (diff)
Use asprint(), not snprintf() when converting strings to numbers
since CONVFMT is user-settable (hence we can't know the actual buffer size requirements) and we need to store a dynamic copy of the result anyway. Fixes a truncation issue with weird CONVFMT values and closes PR 4172 (Matthias Kilian).
Diffstat (limited to 'usr.bin/awk')
-rw-r--r--usr.bin/awk/tran.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c
index ae6a508221f..288288637ce 100644
--- a/usr.bin/awk/tran.c
+++ b/usr.bin/awk/tran.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tran.c,v 1.12 2004/12/30 02:06:00 millert Exp $ */
+/* $OpenBSD: tran.c,v 1.13 2005/04/15 15:54:26 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -362,7 +362,7 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
{
- char s[100]; /* BUG: unchecked */
+ int n;
double dtemp;
if ((vp->tval & (NUM | STR)) == 0)
@@ -375,10 +375,11 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
if (freeable(vp))
xfree(vp->sval);
if (modf(vp->fval, &dtemp) == 0) /* it's integral */
- snprintf(s, sizeof(s), "%.30g", vp->fval);
+ n = asprintf(&vp->sval, "%.30g", vp->fval);
else
- snprintf(s, sizeof(s), *fmt, vp->fval);
- vp->sval = tostring(s);
+ n = asprintf(&vp->sval, *fmt, vp->fval);
+ if (n == -1)
+ FATAL("out of space in get_str_val");
vp->tval &= ~DONTFREE;
vp->tval |= STR;
}