disallowed fixed point decimal literal with no digit after the point.

fixed a bug in hcl_divnums
This commit is contained in:
hyung-hwan 2018-03-30 17:37:40 +00:00
parent 2253d09a18
commit e466c6b68a
4 changed files with 15 additions and 6 deletions

View File

@ -100,7 +100,7 @@ enum hcl_synerrnum_t
HCL_SYNERR_STRCHRNC, /* string/character not closed */
HCL_SYNERR_HASHLIT, /* wrong hashed literal */
HCL_SYNERR_CHARLIT, /* wrong character literal */
HCL_SYNERR_RADNUMLIT , /* invalid numeric literal with radix */
HCL_SYNERR_NUMLIT , /* invalid numeric literal */
HCL_SYNERR_NUMRANGE, /* number range error */
HCL_SYNERR_ERRORLIT, /* wrong error literal */
HCL_SYNERR_SMPTRLIT, /* wrong smptr literal */

View File

@ -233,7 +233,7 @@ hcl_oop_t hcl_divnums (hcl_t* hcl, hcl_oop_t x, hcl_oop_t y)
nv = xv;
hcl_pushtmp (hcl, &y);
hcl_pushtmp (hcl, &yv);
for (i = 0; i < ys; i++)
{
nv = hcl_mulints(hcl, nv, HCL_SMOOI_TO_OOP(10));
@ -244,7 +244,7 @@ hcl_oop_t hcl_divnums (hcl_t* hcl, hcl_oop_t x, hcl_oop_t y)
}
}
nv = hcl_divints(hcl, nv, y, 0, HCL_NULL);
nv = hcl_divints(hcl, nv, yv, 0, HCL_NULL);
hcl_poptmp (hcl);
if (!nv) return HCL_NULL;

View File

@ -273,7 +273,11 @@ hcl_oop_t hcl_makefpdec (hcl_t* hcl, hcl_oop_t value, hcl_ooi_t scale)
{
hcl_oop_fpdec_t f;
if (!HCL_IN_SMOOI_RANGE(scale))
HCL_ASSERT (hcl, hcl_isint(hcl, value));
if (scale <= 0) return value; /* if scale is 0 or less, return the value as it it */
if (scale > HCL_SMOOI_MAX)
{
hcl_seterrbfmt (hcl, HCL_EINVAL, "fpdec scale too large - %zd", scale);
return HCL_NULL;

View File

@ -719,7 +719,7 @@ static int get_radix_number (hcl_t* hcl, hcl_ooci_t rc, int radix)
if (CHAR_TO_NUM(c, radix) >= radix)
{
hcl_setsynerrbfmt (hcl, HCL_SYNERR_RADNUMLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl),
hcl_setsynerrbfmt (hcl, HCL_SYNERR_NUMLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl),
"no digit after radix specifier in %.*js", hcl->c->tok.name.len, hcl->c->tok.name.ptr);
return -1;
}
@ -740,7 +740,7 @@ static int get_radix_number (hcl_t* hcl, hcl_ooci_t rc, int radix)
}
while (!is_delimiter(c));
hcl_setsynerrbfmt (hcl, HCL_SYNERR_RADNUMLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl),
hcl_setsynerrbfmt (hcl, HCL_SYNERR_NUMLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl),
"invalid digit in radixed number in %.*js", hcl->c->tok.name.len, hcl->c->tok.name.ptr);
return -1;
}
@ -1154,6 +1154,11 @@ retry:
SET_TOKEN_TYPE (hcl, HCL_IOTOK_FPDECLIT);
ADD_TOKEN_CHAR (hcl, c);
GET_CHAR_TO (hcl, c);
if (!is_digitchar(c))
{
hcl_setsynerrbfmt (hcl, HCL_SYNERR_NUMLIT, TOKEN_LOC(hcl), TOKEN_NAME(hcl), "invalid numeric literal with no digit after fixed-point");
return -1;
}
}
if (!is_digitchar(c))