changed Array to use 0-based index

This commit is contained in:
hyunghwan.chung
2016-03-16 14:05:34 +00:00
parent 117473f638
commit 00a4fd78d6
3 changed files with 32 additions and 34 deletions

View File

@ -1059,18 +1059,15 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs)
pos = ACTIVE_STACK_GET(stix, stix->sp);
if (stix_inttooow (stix, pos, &idx) <= 0)
{
/* integer out of range or not integer */
/* negative integer or not integer */
return 0;
}
if (idx < 1 || idx > STIX_OBJ_GET_SIZE(rcv))
if (idx >= STIX_OBJ_GET_SIZE(rcv))
{
/* index out of range */
return 0;
}
/* [NOTE] basicAt: and basicAt:put: uses a 1-based index. */
idx = idx - 1;
switch (STIX_OBJ_GET_FLAGS_TYPE(rcv))
{
case STIX_OBJ_TYPE_BYTE:
@ -1123,10 +1120,10 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
if (stix_inttooow (stix, pos, &idx) <= 0)
{
/* integer out of range or not integer */
/* negative integer or not integer */
return 0;
}
if (idx < 1 || idx > STIX_OBJ_GET_SIZE(rcv))
if (idx >= STIX_OBJ_GET_SIZE(rcv))
{
/* index out of range */
return 0;
@ -1140,9 +1137,6 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs)
return 0;
}
/* [NOTE] basicAt: and basicAt:put: uses a 1-based index. */
idx = idx - 1;
switch (STIX_OBJ_GET_FLAGS_TYPE(rcv))
{
case STIX_OBJ_TYPE_BYTE: