[3/8] test: initialize_palette may failed

Submitted by bansan85 on Dec. 13, 2017, 7:41 p.m.

Details

Message ID 20171213194139.19359-3-legarrec.vincent@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Pixman

Not browsing as part of any series.

Commit Message

bansan85 Dec. 13, 2017, 7:41 p.m.
with no infinite random data.
---
 test/stress-test.c | 13 +++++++++++--
 test/utils.c       | 15 +++++++++++++--
 test/utils.h       |  2 +-
 3 files changed, 25 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/stress-test.c b/test/stress-test.c
index 1f03c75..bdd70a8 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -256,13 +256,22 @@  create_random_bits_image (alpha_preference_t alpha_preference)
     {
 	indexed = malloc (sizeof (pixman_indexed_t));
 
-	initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), TRUE);
+	if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), TRUE))
+        {
+	    free (indexed);
+	    return NULL;
+        }
+
     }
     else if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_GRAY)
     {
 	indexed = malloc (sizeof (pixman_indexed_t));
 
-	initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), FALSE);
+	if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), FALSE))
+        {
+	    free (indexed);
+	    return NULL;
+        }
     }
     else
     {
diff --git a/test/utils.c b/test/utils.c
index f8e42a5..bfed94c 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -1025,7 +1025,7 @@  convert_linear_to_srgb (double c)
         return 1.055 * pow (c, 1.0/2.4) - 0.055;
 }
 
-void
+int
 initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
 {
     int i;
@@ -1039,8 +1039,11 @@  initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
     for (i = 0; i < mask + 1; ++i)
     {
 	uint32_t rgba24;
- 	pixman_bool_t retry;
+	pixman_bool_t retry;
 	uint32_t i15;
+	/* With random data from file, there's not infini random data.
+         * So break when add char tried.*/
+	size_t size_data_i = size_data;
 
 	/* We filled the rgb->index map with random numbers, but we
 	 * do need the ability to round trip, that is if some indexed
@@ -1060,6 +1063,12 @@  initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
 		retry = 1;
 	    else
 		retry = 0;
+	    if (random_data != NULL)
+	    {
+		if (size_data_i == 0)
+		    return FALSE;
+		size_data_i--;
+            }
 	} while (retry);
 
 	palette->rgba[i] = rgba24;
@@ -1070,6 +1079,8 @@  initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
     {
 	assert (palette->ent[CONVERT_15 (palette->rgba[i], is_rgb)] == i);
     }
+
+    return TRUE;
 }
 
 struct operator_entry {
diff --git a/test/utils.h b/test/utils.h
index e299d1d..43eca8a 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -205,7 +205,7 @@  convert_srgb_to_linear (double component);
 double
 convert_linear_to_srgb (double component);
 
-void
+int
 initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);
 
 pixman_format_code_t