[Piglit] [PATCH] Use malloc instead of variable size arrays.

Brian Paul brianp at vmware.com
Thu Feb 9 07:01:04 PST 2012


On 02/09/2012 04:59 AM, jfonseca at vmware.com wrote:
> From: José Fonseca<jfonseca at vmware.com>
>
> As the latter are not supported on MSVC.
> ---
>   tests/spec/arb_copy_buffer/overlap.c               |   12 ++++++++-
>   .../ext_texture_integer/getteximage-clamping.c     |   24 ++++++++++++++-----
>   2 files changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/tests/spec/arb_copy_buffer/overlap.c b/tests/spec/arb_copy_buffer/overlap.c
> index 2e9f2de..7b6cf7b 100644
> --- a/tests/spec/arb_copy_buffer/overlap.c
> +++ b/tests/spec/arb_copy_buffer/overlap.c
> @@ -42,11 +42,14 @@ int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
>   static void
>   test_copy(GLenum usage, int data_size, int src, int dst, int size)
>   {
> -	uint8_t data[data_size];
> -	uint8_t expected[data_size];
> +	uint8_t *data;
> +	uint8_t *expected;
>   	uint8_t *ptr;
>   	int i;
>
> +	data = (uint8_t *)malloc(data_size);
> +	expected = (uint8_t *)malloc(data_size);
> +
>   	for (i = 0; i<  data_size; i++) {
>   		data[i] = i;
>   	}
> @@ -66,6 +69,8 @@ test_copy(GLenum usage, int data_size, int src, int dst, int size)
>   				src, dst, size);
>   			piglit_report_result(PIGLIT_FAIL);
>   		} else {
> +			free(expected);
> +			free(data);
>   			return;
>   		}
>   	} else {
> @@ -99,6 +104,9 @@ test_copy(GLenum usage, int data_size, int src, int dst, int size)
>   		piglit_report_result(PIGLIT_FAIL);
>   	}
>   	glUnmapBuffer(GL_COPY_READ_BUFFER);
> +
> +	free(expected);
> +	free(data);
>   }
>
>   enum piglit_result
> diff --git a/tests/spec/ext_texture_integer/getteximage-clamping.c b/tests/spec/ext_texture_integer/getteximage-clamping.c
> index 16b4fba..969a314 100644
> --- a/tests/spec/ext_texture_integer/getteximage-clamping.c
> +++ b/tests/spec/ext_texture_integer/getteximage-clamping.c
> @@ -375,13 +375,12 @@ read_format(const struct format_info *tex_info,
>   	    const struct read_format_info *read_info,
>   	    uint32_t texels[][4], int num_texels)
>   {
> -	char expected[num_texels * 4 * sizeof(uint32_t)];
> -	char read[num_texels * 4 * sizeof(uint32_t)];
> +	size_t texels_size = num_texels * 4 * sizeof(uint32_t);
> +	char *expected;
> +	char *read;
>   	int i;
>   	int chans = 0;
> -
> -	memset(expected, 0xd0, sizeof(expected));
> -	memset(read, 0xd0, sizeof(read));
> +	enum piglit_result result;
>
>   	if (!test_rg&&  (read_info->format == GL_RED_INTEGER ||
>   			 read_info->format == GL_RG_INTEGER)) {
> @@ -413,6 +412,12 @@ read_format(const struct format_info *tex_info,
>   	printf("Reading from %s to %s/%s\n", tex_info->name,
>   	       read_info->format_name, read_info->type_name);
>
> +	expected = (char *)malloc(texels_size);
> +	read = (char *)malloc(texels_size);
> +
> +	memset(expected, 0xd0, texels_size);
> +	memset(read, 0xd0, texels_size);
> +
>   	glGetTexImage(GL_TEXTURE_2D, 0,
>   		      read_info->format, read_info->type, read);
>
> @@ -499,10 +504,15 @@ read_format(const struct format_info *tex_info,
>   	if (memcmp(expected, read, num_texels * chans * read_info->size / 8)) {
>   		report_fail(tex_info, read_info, texels, read, expected,
>   			    num_texels, chans);
> -		return PIGLIT_FAIL;
> +		result = PIGLIT_FAIL;
> +	} else {
> +		result = PIGLIT_PASS;
>   	}
>
> -	return PIGLIT_PASS;
> +	free(read);
> +	free(expected);
> +
> +	return result;
>   }
>
>   static enum piglit_result

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the Piglit mailing list