From 18c6b0f85db6683f1d0789e800acfdd35da3ce07 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Mon, 13 Jun 2016 18:39:10 -0400 Subject: Fix usage of scalar type flag bits and fix some bugs in numeric conversions and lint checks. --- int_array.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'int_array.c') diff --git a/int_array.c b/int_array.c index a8de3d55..4ba7c98b 100644 --- a/int_array.c +++ b/int_array.c @@ -89,6 +89,21 @@ is_integer(NODE *symbol, NODE *subs) if (subs == Nnull_string || do_mpfr) return NULL; + /* + * Protect against MAYBE_NUM values where the string may not regenerate + * correctly. There could be white space and/or a non-decimal value. + */ + if ((subs->flags & STRCUR) != 0) { + char *cp = subs->stptr; + + if ((cp[0] == '0') || isspace((unsigned char) cp[0]) + || (subs->stlen < 1) + || isspace((unsigned char) cp[subs->stlen - 1]) + || ((subs->stlen >= 2) && (cp[0] == '-') + && (cp[1] == '0'))) + return NULL; + } + if ((subs->flags & NUMINT) != 0) return & success_node; @@ -107,7 +122,8 @@ is_integer(NODE *symbol, NODE *subs) * a[-3]=1; print "-3" in a -- true */ - if ((subs->flags & (STRING|STRCUR)) != 0) { + { + /* must be a STRING */ char *cp = subs->stptr, *cpend, *ptr; char save; size_t len = subs->stlen; @@ -123,7 +139,7 @@ is_integer(NODE *symbol, NODE *subs) if (len == 1 && *cp != '-') { /* single digit */ subs->numbr = (long) (*cp - '0'); if ((subs->flags & MAYBE_NUM) != 0) { - subs->flags &= ~MAYBE_NUM; + subs->flags &= ~(MAYBE_NUM|STRING); subs->flags |= NUMBER; } subs->flags |= (NUMCUR|NUMINT); @@ -141,7 +157,7 @@ is_integer(NODE *symbol, NODE *subs) return NULL; subs->numbr = l; if ((subs->flags & MAYBE_NUM) != 0) { - subs->flags &= ~MAYBE_NUM; + subs->flags &= ~(MAYBE_NUM|STRING); subs->flags |= NUMBER; } subs->flags |= NUMCUR; -- cgit v1.2.3