From: Bastian Dehn Date: Sat, 11 Oct 2025 11:44:23 +0000 (+0200) Subject: fix allocation issue read test X-Git-Tag: v1.1.10^2~7 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=922ba29c51031ebf4e0897b770f3e1bd9a102c4a;p=sane-kds-s2000w-net.git fix allocation issue read test --- diff --git a/tests/kds_s2000w_net_read_tests.c b/tests/kds_s2000w_net_read_tests.c index 871169a..7a171f7 100644 --- a/tests/kds_s2000w_net_read_tests.c +++ b/tests/kds_s2000w_net_read_tests.c @@ -16,13 +16,36 @@ void sane_kds_s2000w_net_read_test() h->image->size = 65536; h->image->data = malloc(sizeof(char) * 65536); char* imagedata = (char*) h->image->data; + if (imagedata == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + return; + } + for (uint32_t i = 0; i < 65536; i++) { imagedata[i] = (char) 0xff; } SANE_Int maxlen = 65536; char* dataptr = malloc(sizeof(char) * maxlen); + if (dataptr == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + free(imagedata); + imagedata = NULL; + return; + } + SANE_Int* length = malloc(sizeof(SANE_Int)); + if (length == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + free(dataptr); + dataptr = NULL; + free(imagedata); + imagedata = NULL; + return; + } sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length); @@ -84,6 +107,11 @@ void sane_kds_s2000w_net_read_bytes_per_line_bigger_test() h->image->size = 95003; h->image->data = malloc(sizeof(char) * 95003); char* image = (char*) h->image->data; + if (image == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + return; + } for (uint32_t i = 0; i < 3; i++) { image[i] = 0x0a; } @@ -91,7 +119,21 @@ void sane_kds_s2000w_net_read_bytes_per_line_bigger_test() SANE_Int maxlen = 65536; char* dataptr = malloc(sizeof(char) * maxlen); + if (dataptr == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + free(image); + image = NULL; + return; + } SANE_Int* length = malloc(sizeof(SANE_Int)); + if (length == NULL) { + kds_s2000w_handler_free(h); + h = NULL; + free(dataptr); + dataptr = NULL; + return; + } sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length); sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);