diff --git a/moo/lib/bigint.c b/moo/lib/bigint.c index dbf0dae..c5c81c9 100644 --- a/moo/lib/bigint.c +++ b/moo/lib/bigint.c @@ -1454,7 +1454,7 @@ static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, * R := R << 1 left-shift R by 1 bit * R(0) := X(i) set the least-significant bit of R equal to bit i of the numerator * if R >= Y then - * R = R - Y + * R = R - Y * Q(i) := 1 * end * end @@ -4279,21 +4279,21 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix) do { - if (is_less_unsigned_array (b, bs, a, as)) + if (is_less_unsigned_array(b, bs, a, as)) { moo_liw_t* tmp; - divide_unsigned_array (moo, a, as, b, bs, q, r); + divide_unsigned_array(moo, a, as, b, bs, q, r); /* get 'rs' before 'as' gets changed */ - rs = count_effective (r, as); + rs = count_effective(r, as); /* swap a and q for later division */ tmp = a; a = q; q = tmp; - as = count_effective (a, as); + as = count_effective(a, as); } else { @@ -4315,7 +4315,7 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int flagged_radix) #else # error UNSUPPORTED LIW BIT SIZE #endif - seglen = oow_to_text (moo, w, flagged_radix, &xbuf[xlen]); + seglen = oow_to_text(moo, w, flagged_radix, &xbuf[xlen]); xlen += seglen; if (r == a) break; /* reached the last block */ diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 9c2c3a6..b333064 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -760,20 +760,6 @@ static moo_oop_t string_to_fpdec (moo_t* moo, moo_oocs_t* str, int prescaled) moo_oow_t explen; explen = len + xscale - scale; -#if 0 - tmp = moo_allocmem(moo, explen * MOO_SIZEOF(*tmp)); - if (!tmp) - { - const moo_ooch_t* oldmsg = moo_backuperrmsg(moo); - moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to convert to fpdec %.*js - %js", str->len, str->ptr, oldmsg); - return MOO_NULL; - } - - moo_copy_oochars (tmp, &str->ptr[pos], len); - moo_fill_oochars (&tmp[len], '0', explen - len); - v = moo_strtoint(moo, tmp, explen, base); - moo_freemem (moo, tmp); -#else if (moo_copyoocharstosbuf(moo, &str->ptr[pos], len, MOO_SBUF_ID_FPDEC) <= -1 || moo_concatoochartosbuf(moo, '0', explen - len, MOO_SBUF_ID_FPDEC) <= -1) { @@ -782,7 +768,6 @@ static moo_oop_t string_to_fpdec (moo_t* moo, moo_oocs_t* str, int prescaled) return MOO_NULL; } v = moo_strtoint(moo, moo->sbuf[MOO_SBUF_ID_FPDEC].ptr, moo->sbuf[MOO_SBUF_ID_FPDEC].len, base); -#endif scale = xscale; } else if (scale > xscale) diff --git a/moo/lib/utl.c b/moo/lib/utl.c index 6de844c..eac4405 100644 --- a/moo/lib/utl.c +++ b/moo/lib/utl.c @@ -1128,14 +1128,14 @@ static MOO_INLINE int secure_space_in_sbuf (moo_t* moo, moo_oow_t req, moo_sbuf_ moo_oow_t newcapa; moo_ooch_t* tmp; - newcapa = MOO_ALIGN_POW2(p->len + req, 512); /* TODO: adjust this capacity */ + newcapa = p->len + req + 1; + newcapa = MOO_ALIGN_POW2(newcapa, 512); /* TODO: adjust this capacity */ - /* +1 to handle line ending injection more easily */ - tmp = (moo_ooch_t*)moo_reallocmem(moo, p->ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); + tmp = (moo_ooch_t*)moo_reallocmem(moo, p->ptr, newcapa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; p->ptr = tmp; - p->capa = newcapa; + p->capa = newcapa - 1; } return 0; @@ -1151,23 +1151,20 @@ int moo_concatoocharstosbuf (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, m moo_sbuf_t* p; p = &moo->sbuf[id]; - if (secure_space_in_sbuf(moo, len, p) <= -1) return -1; - moo_copy_oochars (&p->ptr[p->len], ptr, len); p->len += len; p->ptr[p->len] = '\0'; return 0; } + int moo_concatoochartosbuf (moo_t* moo, moo_ooch_t ch, moo_oow_t count, moo_sbuf_id_t id) { moo_sbuf_t* p; p = &moo->sbuf[id]; - if (secure_space_in_sbuf(moo, count, p) <= -1) return -1; - moo_fill_oochars (&p->ptr[p->len], ch, count); p->len += count; p->ptr[p->len] = '\0'; @@ -1177,12 +1174,12 @@ int moo_concatoochartosbuf (moo_t* moo, moo_ooch_t ch, moo_oow_t count, moo_sbuf int moo_copyoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, moo_sbuf_id_t id) { - moo->sbuf[id].len = 0;; + moo->sbuf[id].len = 0; return moo_concatoocstrtosbuf(moo, str, id); } int moo_copyoocharstosbuf (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, moo_sbuf_id_t id) { - moo->sbuf[id].len = 0;; + moo->sbuf[id].len = 0; return moo_concatoocharstosbuf(moo, ptr, len, id); }