From: Bastian Dehn Date: Mon, 30 Dec 2024 09:54:18 +0000 (+0100) Subject: change order read image last frame abort contition X-Git-Tag: v1.0.19^2~2 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=09d7f1048f8562c2e0bfa5990f19e0841eecb18d;p=sane-kds-s2000w-net.git change order read image last frame abort contition --- 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,