From: Bastian Dehn Date: Sat, 11 Oct 2025 12:05:03 +0000 (+0200) Subject: fix allocation issues in type check tests X-Git-Tag: v1.1.10^2~5 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ecdb7ee1e05fd6522f0ad6b14c70f9fe3d6779e1;p=sane-kds-s2000w-net.git fix allocation issues in type check tests --- diff --git a/tests/kds_s2000w_image_type_check_tests.c b/tests/kds_s2000w_image_type_check_tests.c index cbba50a..758a6ca 100644 --- a/tests/kds_s2000w_image_type_check_tests.c +++ b/tests/kds_s2000w_image_type_check_tests.c @@ -9,8 +9,17 @@ void kds_s2000w_image_type_check_is_tiff_true_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; image->data = malloc(sizeof(char) * 4); char* imagedata = (char*) image->data; + if (imagedata == NULL) { + free(image->data); + image->data = NULL; + free(image); + image = NULL; + return; + } imagedata[0] = 0x49; imagedata[1] = 0x49; imagedata[2] = 0x2A; @@ -30,6 +39,9 @@ void kds_s2000w_image_type_check_is_tiff_true_test() void kds_s2000w_image_type_check_is_tiff_false_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; + image->size = 0; bool result = kds_s2000w_image_type_check_is_tiff(image); @@ -43,8 +55,15 @@ void kds_s2000w_image_type_check_is_tiff_false_test() void kds_s2000w_image_type_check_is_pnm_true_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; image->size = 2; image->data = malloc(sizeof(char) * image->size); + if (image->data == NULL) { + free(image); + image = NULL; + return; + } char* imagedata = (char*) image->data; imagedata[0] = 'P'; imagedata[1] = '6'; @@ -62,6 +81,8 @@ void kds_s2000w_image_type_check_is_pnm_true_test() void kds_s2000w_image_type_check_is_pnm_false_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; image->size = 0; bool result = kds_s2000w_image_type_check_is_pnm(image); @@ -75,7 +96,14 @@ void kds_s2000w_image_type_check_is_pnm_false_test() void kds_s2000w_image_type_check_is_jpeg_true_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; image->data = malloc(sizeof(char) * 2); + if (image->data == NULL) { + free(image); + image = NULL; + return; + } char* imagedata = (char*) image->data; imagedata[0] = (char) 0xff; imagedata[1] = (char) 0xd8; @@ -94,6 +122,8 @@ void kds_s2000w_image_type_check_is_jpeg_true_test() void kds_s2000w_image_type_check_is_jpeg_false_test() { blobdata* image = malloc(sizeof(blobdata)); + if (image == NULL) + return; image->size = 0; bool result = kds_s2000w_image_type_check_is_jpeg(image);