diff --git a/lib/hcl.h b/lib/hcl.h index b33b118..b8db134 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -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 */ diff --git a/lib/number.c b/lib/number.c index 331e77e..83314b0 100644 --- a/lib/number.c +++ b/lib/number.c @@ -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; diff --git a/lib/obj.c b/lib/obj.c index b232174..159ec7c 100644 --- a/lib/obj.c +++ b/lib/obj.c @@ -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; diff --git a/lib/read.c b/lib/read.c index ba6ee44..ecc0046 100644 --- a/lib/read.c +++ b/lib/read.c @@ -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))