/* -------------------------------------------------------------------- */
/* Verify selection. */
/* -------------------------------------------------------------------- */
- if( iShape < 0 || iShape >= psDBF->nRecords )
+ if( iShape < 0 || (psDBF->nRecords > 0 && iShape >= psDBF->nRecords) )
return TRUE;
/* -------------------------------------------------------------------- */
/* Have we read the record? */
/* -------------------------------------------------------------------- */
- if( !DBFLoadRecord( psDBF, iShape ) )
+ if( psDBF->nRecords > 0 && !DBFLoadRecord( psDBF, iShape ) )
return FALSE;
/* -------------------------------------------------------------------- */
sb = stringbuffer_create();
stringbuffer_clear(sb);
- /* If we are reading the DBF only and the record has been marked deleted, return deleted record status */
- if (state->config->readshape == 0 && DBFIsRecordDeleted(state->hDBFHandle, item))
+ /* Skip deleted records */
+ if (state->hDBFHandle && DBFIsRecordDeleted(state->hDBFHandle, item))
{
*strrecord = NULL;
return SHPLOADERRECDELETED;