changed basicShift and basicFill primitives not to validate source position and destination position when count is <= 0
This commit is contained in:
@ -465,13 +465,6 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_ooi_t nargs)
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid source position - %O", spos);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
if (sidx >= MOO_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "source position out of bound - %zu", sidx);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (moo_inttooow(moo, slen, &ssz) <= 0)
|
||||
{
|
||||
/* negative integer or not integer */
|
||||
@ -479,6 +472,20 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_ooi_t nargs)
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (ssz <= 0)
|
||||
{
|
||||
/* no filling is performed. also no validation about the range of
|
||||
* source position is performed */
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (sidx >= MOO_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "source position out of bound - %zu", sidx);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
maxlen = MOO_OBJ_GET_SIZE(rcv) - sidx;
|
||||
if (ssz > maxlen) ssz = maxlen;
|
||||
end = sidx + ssz;
|
||||
@ -519,6 +526,7 @@ moo_pfrc_t moo_pf_basic_fill (moo_t* moo, moo_ooi_t nargs)
|
||||
}
|
||||
|
||||
|
||||
done:
|
||||
#if defined(MOO_LIMIT_OBJ_SIZE)
|
||||
MOO_ASSERT (moo, ssz <= MOO_SMOOI_MAX);
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(ssz));
|
||||
@ -574,19 +582,32 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_ooi_t nargs)
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid source position - %O", spos);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
if (sidx >= MOO_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "source position out of bound - %zu", sidx);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (moo_inttooow(moo, dpos, &didx) <= 0)
|
||||
{
|
||||
/* negative integer or not integer */
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid destination position - %O", dpos);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
if (moo_inttooow(moo, slen, &ssz) <= 0)
|
||||
{
|
||||
/* negative integer or not integer */
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid shift count - %O", slen);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (ssz <= 0)
|
||||
{
|
||||
/* no shifting is performed. also no validation about the range of
|
||||
* source position and destionation position is performed */
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (sidx >= MOO_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "source position out of bound - %zu", sidx);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
if (didx >= MOO_OBJ_GET_SIZE(rcv))
|
||||
{
|
||||
/* index out of range */
|
||||
@ -594,14 +615,7 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_ooi_t nargs)
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (moo_inttooow(moo, slen, &ssz) <= 0)
|
||||
{
|
||||
/* negative integer or not integer */
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid shift count - %O", slen);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (sidx != didx && ssz > 0)
|
||||
if (sidx != didx)
|
||||
{
|
||||
moo_oow_t maxlen;
|
||||
|
||||
@ -699,6 +713,7 @@ moo_pfrc_t moo_pf_basic_shift (moo_t* moo, moo_ooi_t nargs)
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
#if defined(MOO_LIMIT_OBJ_SIZE)
|
||||
MOO_ASSERT (moo, ssz <= MOO_SMOOI_MAX);
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(ssz));
|
||||
|
Reference in New Issue
Block a user