fixed wrong capacity computation for hcl->inttostr.t and hcl->inttostr.xbuf in bigint.c

This commit is contained in:
hyung-hwan 2018-12-20 14:12:36 +00:00
parent e935ba7221
commit 985ec11cae

View File

@ -4110,7 +4110,7 @@ hcl_oop_t hcl_inttostr (hcl_t* hcl, hcl_oop_t num, int radix, int ngc)
reqcapa = HCL_OOW_BITS + 1; reqcapa = HCL_OOW_BITS + 1;
if (hcl->inttostr.xbuf.capa < reqcapa) if (hcl->inttostr.xbuf.capa < reqcapa)
{ {
xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa); xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa * HCL_SIZEOF(*xbuf));
if (!xbuf) return HCL_NULL; if (!xbuf) return HCL_NULL;
hcl->inttostr.xbuf.capa = reqcapa; hcl->inttostr.xbuf.capa = reqcapa;
hcl->inttostr.xbuf.ptr = xbuf; hcl->inttostr.xbuf.ptr = xbuf;
@ -4146,10 +4146,10 @@ hcl_oop_t hcl_inttostr (hcl_t* hcl, hcl_oop_t num, int radix, int ngc)
xlen = as * ((HCL_LIW_BITS + exp) / exp) + 1; xlen = as * ((HCL_LIW_BITS + exp) / exp) + 1;
xpos = xlen; xpos = xlen;
reqcapa = HCL_SIZEOF(*xbuf) * xlen; reqcapa = xlen;
if (hcl->inttostr.xbuf.capa < reqcapa) if (hcl->inttostr.xbuf.capa < reqcapa)
{ {
xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa); xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa * HCL_SIZEOF(*xbuf));
if (!xbuf) return HCL_NULL; if (!xbuf) return HCL_NULL;
hcl->inttostr.xbuf.capa = reqcapa; hcl->inttostr.xbuf.capa = reqcapa;
hcl->inttostr.xbuf.ptr = xbuf; hcl->inttostr.xbuf.ptr = xbuf;
@ -4203,10 +4203,10 @@ hcl_oop_t hcl_inttostr (hcl_t* hcl, hcl_oop_t num, int radix, int ngc)
/* Do it in a hard way for other cases */ /* Do it in a hard way for other cases */
/* TODO: find an optimial buffer size */ /* TODO: find an optimial buffer size */
reqcapa = HCL_SIZEOF(*xbuf) * (as * HCL_LIW_BITS + 1); reqcapa = as * HCL_LIW_BITS + 1;
if (hcl->inttostr.xbuf.capa < reqcapa) if (hcl->inttostr.xbuf.capa < reqcapa)
{ {
xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa); xbuf = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->inttostr.xbuf.ptr, reqcapa * HCL_SIZEOF(*xbuf));
if (!xbuf) return HCL_NULL; if (!xbuf) return HCL_NULL;
hcl->inttostr.xbuf.capa = reqcapa; hcl->inttostr.xbuf.capa = reqcapa;
hcl->inttostr.xbuf.ptr = xbuf; hcl->inttostr.xbuf.ptr = xbuf;
@ -4216,10 +4216,10 @@ hcl_oop_t hcl_inttostr (hcl_t* hcl, hcl_oop_t num, int radix, int ngc)
xbuf = hcl->inttostr.xbuf.ptr; xbuf = hcl->inttostr.xbuf.ptr;
} }
reqcapa = HCL_SIZEOF(*t) * as * 3; reqcapa = as * 3;
if (hcl->inttostr.t.capa < reqcapa) if (hcl->inttostr.t.capa < reqcapa)
{ {
t = (hcl_liw_t*)hcl_reallocmem(hcl, hcl->inttostr.t.ptr, reqcapa); t = (hcl_liw_t*)hcl_reallocmem(hcl, hcl->inttostr.t.ptr, reqcapa * HCL_SIZEOF(*t));
if (!t) return HCL_NULL; if (!t) return HCL_NULL;
hcl->inttostr.t.capa = reqcapa; hcl->inttostr.t.capa = reqcapa;
hcl->inttostr.t.ptr = t; hcl->inttostr.t.ptr = t;