summaryrefslogtreecommitdiffstats
path: root/contrib/awk/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/awk/node.c')
-rw-r--r--contrib/awk/node.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/contrib/awk/node.c b/contrib/awk/node.c
index 6f10b9f..a8892a3 100644
--- a/contrib/awk/node.c
+++ b/contrib/awk/node.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
+ * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -21,6 +21,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * $FreeBSD$
*/
#include "awk.h"
@@ -36,6 +38,7 @@ register NODE *n;
char save;
char *ptr;
unsigned int newflags;
+ extern double strtod();
#ifdef DEBUG
if (n == NULL)
@@ -140,7 +143,16 @@ register NODE *s;
/* not an integral value, or out of range */
if ((val = double_to_int(s->numbr)) != s->numbr
|| val < LONG_MIN || val > LONG_MAX) {
-#ifdef GFMT_WORKAROUND
+ /*
+ * Once upon a time, if GFMT_WORKAROUND wasn't defined,
+ * we just blindly did this:
+ * sprintf(sp, format, s->numbr);
+ * s->stlen = strlen(sp);
+ * s->stfmt = (char) index;
+ * but that's no good if, e.g., OFMT is %s. So we punt,
+ * and just always format the value ourselves.
+ */
+
NODE *dummy, *r;
unsigned short oflags;
extern NODE *format_tree P((const char *, int, NODE *));
@@ -161,15 +173,6 @@ register NODE *s;
freenode(dummy); /* to keep s->stptr == r->stpr. */
goto no_malloc;
-#else
- /*
- * no need for a "replacement" formatting by gawk,
- * just use sprintf
- */
- sprintf(sp, format, s->numbr);
- s->stlen = strlen(sp);
- s->stfmt = (char) index;
-#endif /* GFMT_WORKAROUND */
} else {
/* integral value */
/* force conversion to long only once */
@@ -183,11 +186,9 @@ register NODE *s;
}
s->stfmt = -1;
}
- emalloc(s->stptr, char *, s->stlen + 2, "force_string");
+ emalloc(s->stptr, char *, s->stlen + 2, "format_val");
memcpy(s->stptr, sp, s->stlen+1);
-#ifdef GFMT_WORKAROUND
no_malloc:
-#endif /* GFMT_WORKAROUND */
s->stref = 1;
s->flags |= STR;
return s;
@@ -495,7 +496,9 @@ char **string_ptr;
}
i = 0;
for (;;) {
- if (ISXDIGIT((c = *(*string_ptr)++))) {
+ /* do outside test to avoid multiple side effects */
+ c = *(*string_ptr)++;
+ if (ISXDIGIT(c)) {
i *= 16;
if (ISDIGIT(c))
i += c - '0';
OpenPOWER on IntegriCloud