]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
fix allocation issues in type check tests
authorBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 12:05:03 +0000 (14:05 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 12:05:03 +0000 (14:05 +0200)
tests/kds_s2000w_image_type_check_tests.c

index cbba50a4bf5b62773021d72c16e7fbf5af9fd103..758a6ca1775637b4d59637200aed4a78e906505d 100644 (file)
@@ -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);