added more context-sensitive error messages upon memory allocation failures in comp.c and read.c
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-06 18:11:39 +09:00
parent 3ea6b92b5f
commit a960af379a
3 changed files with 71 additions and 18 deletions

View File

@ -109,7 +109,12 @@ static int copy_string_to (hcl_t* hcl, const hcl_oocs_t* src, hcl_oocs_t* dst, h
capa = HCL_ALIGN(len + 1, TV_BUFFER_ALIGN);
tmp = (hcl_ooch_t*)hcl_reallocmem(hcl, dst->ptr, HCL_SIZEOF(*tmp) * capa);
if (HCL_UNLIKELY(!tmp)) return -1;
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to grow string buffer - %js", orgmsg);
return -1;
}
dst->ptr = tmp;
*dstcapa = capa - 1;
@ -526,11 +531,18 @@ static int emit_byte_instruction (hcl_t* hcl, hcl_oob_t bc, const hcl_loc_t* src
newcapa = HCL_ALIGN(hcl->code.bc.capa + 1, HCL_BC_BUFFER_ALIGN);
tmp = (hcl_oob_t*)hcl_reallocmem(hcl, hcl->code.bc.ptr, HCL_SIZEOF(*tmp) * newcapa);
if (HCL_UNLIKELY(!tmp)) return -1;
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to grow byte code buffer - %js", orgmsg);
return -1;
}
tmp2 = (hcl_dbgi_t*)hcl_reallocmem(hcl, hcl->code.dbgi, HCL_SIZEOF(*tmp2) * newcapa);
if (HCL_UNLIKELY(!tmp2))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to grow debug info buffer - %js", orgmsg);
hcl_freemem (hcl, tmp);
return -1;
}
@ -953,7 +965,12 @@ static int push_cblk (hcl_t* hcl, const hcl_loc_t* errloc, hcl_cblk_type_t type)
newcapa = HCL_ALIGN(new_depth + 1, BLK_INFO_BUFFER_ALIGN);
tmp = (hcl_cblk_info_t*)hcl_reallocmem(hcl, hcl->c->cblk.info, newcapa * HCL_SIZEOF(*tmp));
if (HCL_UNLIKELY(!tmp)) return -1;
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to resize control block info buffer - %js", orgmsg);
return -1;
}
hcl->c->cblk.info_capa = newcapa;
hcl->c->cblk.info = tmp;
@ -998,7 +1015,12 @@ static int push_clsblk (hcl_t* hcl, const hcl_loc_t* errloc, hcl_oow_t nivars, h
newcapa = HCL_ALIGN(new_depth + 1, BLK_INFO_BUFFER_ALIGN);
tmp = (hcl_clsblk_info_t*)hcl_reallocmem(hcl, hcl->c->clsblk.info, newcapa * HCL_SIZEOF(*tmp));
if (HCL_UNLIKELY(!tmp)) return -1;
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to resize class block info buffer - %js", orgmsg);
return -1;
}
hcl->c->clsblk.info_capa = newcapa;
hcl->c->clsblk.info = tmp;
@ -1097,7 +1119,12 @@ static int push_fnblk (hcl_t* hcl, const hcl_loc_t* errloc,
newcapa = HCL_ALIGN(new_depth + 1, BLK_INFO_BUFFER_ALIGN);
tmp = (hcl_fnblk_info_t*)hcl_reallocmem(hcl, hcl->c->fnblk.info, newcapa * HCL_SIZEOF(*tmp));
if (HCL_UNLIKELY(!tmp)) return -1;
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to resize function block info buffer - %js", orgmsg);
return -1;
}
hcl->c->fnblk.info_capa = newcapa;
hcl->c->fnblk.info = tmp;
@ -1207,9 +1234,11 @@ static HCL_INLINE int _insert_cframe (hcl_t* hcl, hcl_ooi_t index, int opcode, h
hcl_oow_t newcapa;
newcapa = HCL_ALIGN (hcl->c->cfs.top + 256, 256); /* TODO: adjust this capacity */
tmp = (hcl_cframe_t*)hcl_reallocmem (hcl, hcl->c->cfs.ptr, newcapa * HCL_SIZEOF(*tmp));
tmp = (hcl_cframe_t*)hcl_reallocmem(hcl, hcl->c->cfs.ptr, newcapa * HCL_SIZEOF(*tmp));
if (HCL_UNLIKELY(!tmp))
{
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
hcl_seterrbfmt (hcl, hcl_geterrnum(hcl), "failed to grow compiler frame stack- %js", orgmsg);
hcl->c->cfs.top--;
return -1;
}