-int getNextOid(short * offsetarray, unsigned int *dfsList, int *top, int *depth, oidAtDepth_t *odep, unsigned int baseoid) {
- if(*top == 0) {
- odep->oid = baseoid;
- odep->depth = 0;
- } else {
- int prev = (*top) - 2;
- unsigned int oid = *(dfsList+prev);
- objheader_t * header = searchObj(oid);
- if(header == NULL) {
- odep->oid = 0;
- odep->depth = 0;
- return 0;
- } else {
- int range = GET_RANGE(*(offsetarray+(*depth) + 1));
- short stride = GET_STRIDE(*(offsetarray+(*depth) + 1));
- stride++; //Note bit pattern 000 => stride = 1 etc
- //if Array
- if(TYPE(header) > NUMCLASSES) {
- int elementsize = classsize[TYPE(header)];
- struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t));
- int length = ao->___length___;
- //check is stride is +ve or -ve
- int sign;
- if(GET_STRIDEINC(*(offsetarray+ (*depth) + 1))) {
- sign = -1;
- } else {
- sign = 1;
- }
- int startelement = *(offsetarray + (*depth));
- if(startelement < 0 || startelement >=length) {
- printf("%s() Error: Offset out of range at %d\n", __func__, __LINE__);
- odep->oid = 0;
- odep->depth = 0;
- return 0;
- }
- int index = *(dfsList+(*top)+1);
- odep->oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) \
- + (elementsize * (startelement + (sign*stride*index)))));
- odep->depth = *(depth);
- } else { //linked list
- int dep;
- int startelement;
- if(range > 0) { //go to the next offset
- startelement = *((int *)(offsetarray + (*depth) + 2));
- *depth = *depth + 2;
- } else if(range == 0) {
- startelement = *((int *)(offsetarray + (*depth)));
- } else { //range < 0
- odep->oid = 0;
- odep->depth = 0;
+ //Also have to check whether we will eventually index into array
+ if (currindex>=length) {
+ //Skip to the point that we will index into array
+ int delta=(currindex-length-1)/stride+1; //-1, +1 is to make sure that it rounds up
+ if ((delta+currcount)>range)