From 09d7f1048f8562c2e0bfa5990f19e0841eecb18d Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 30 Dec 2024 10:54:18 +0100 Subject: [PATCH] change order read image last frame abort contition --- src/kds_s2000w_net.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index 713e644..fd46d79 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -214,26 +214,22 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data, handler* h = (handler*) handle; - // max length *length = h->image->size - h->read_info->read_size; if (*length > max_length) *length = max_length; - // read image - if (h->read_info->read_size < h->image->size) { - memcpy(data, h->image->data + h->read_info->read_size, *length); - h->read_info->read_size += *length; + if (h->read_info->read_size >= h->image->size) { + free(h->image->data); + h->image->data = NULL; + h->image->size = 0; - return SANE_STATUS_GOOD; + *length = 0; + return SANE_STATUS_EOF; } - // last frame - free(h->image->data); - h->image->data = NULL; - h->image->size = 0; - - *length = 0; - return SANE_STATUS_EOF; + memcpy(data, h->image->data + h->read_info->read_size, *length); + h->read_info->read_size += *length; + return SANE_STATUS_GOOD; } SANE_Status _sane_kds_s2000w_net_set_io_mode(SANE_Handle handle, -- 2.39.5