Don't seek past rows in xport
Row count is unknown, so row_offset > actual row count will be a seek error.
@@ -570,13 +570,18 @@ static readstat_error_t xport_process_row(xport_ctx_t *ctx, const char *row, siz
}
pos += variable->storage_width;
- if (ctx->handle.value && !ctx->variables[i]->skip) {
+ if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) {
if (ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
retval = READSTAT_ERROR_USER_ABORT;
goto cleanup;
}
}
}
+ if (ctx->row_offset) {
+ ctx->row_offset--;
+ } else {
+ ctx->parsed_row_count++;
+ }
cleanup:
free(string);
@@ -600,14 +605,6 @@ static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
goto cleanup;
}
- if (ctx->row_offset) {
- if (ctx->io->seek(ctx->row_length * ctx->row_offset, READSTAT_SEEK_CUR, ctx->io->io_ctx) == -1) {
- retval = READSTAT_ERROR_SEEK;
- goto cleanup;
- }
- ctx->row_offset = 0;
- }
-
memset(blank_row, ' ', ctx->row_length);
while (1) {
ssize_t bytes_read = read_bytes(ctx, row, ctx->row_length);
@@ -639,7 +636,7 @@ static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
if (retval != READSTAT_OK)
goto cleanup;
- if (++(ctx->parsed_row_count) == ctx->row_limit)
+ if (ctx->parsed_row_count == ctx->row_limit)
goto cleanup;
num_blank_rows--;
@@ -653,7 +650,7 @@ static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
if (retval != READSTAT_OK)
goto cleanup;
- if (++(ctx->parsed_row_count) == ctx->row_limit)
+ if (ctx->parsed_row_count == ctx->row_limit)
break;
}
