From: Bastian Dehn Date: Sat, 18 May 2024 06:18:56 +0000 (+0200) Subject: refactor max length calc X-Git-Tag: v1.0.3^2~8 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ff71ac423c5b743f62cd9bd3abe65894f42103b5;p=sane-kds-s2000w-net.git refactor max length calc --- diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index 8375822..593ac3a 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -229,16 +229,14 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data, } // calc max length - int maxlen = max_length; - int rest_size = h->pnm_image->size - h->read_info->read_size; - if (rest_size < max_length) - maxlen = rest_size; + *length = h->pnm_image->size - h->read_info->read_size; + if (*length > max_length) + *length = max_length; // read image if (h->pnm_image->data != NULL && h->read_info->read_size <= 0) h->read_info->read_size += _sane_kds_s2000w_net_find_first_data_byte(h->pnm_image->data); - *length = maxlen; memcpy(data, h->pnm_image->data + h->read_info->read_size, *length); h->read_info->read_size += *length;