[Mesa-dev] [PATCH] util: fix off-by-one when loading source

Eric Engestrom eric at engestrom.ch
Sun Jan 20 09:09:56 UTC 2019



On January 19, 2019 11:40:41 PM UTC, Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com> wrote:
> One extra character is leaking from the text into the copied line.
> The "+ 1" is an artifact from when malloc was used, strndup will add
> the extra '\0' after copying text_size bytes (if available).

Yeah, I had that change locally, but didn't push it :]

Reviewed-by: Eric Engestrom <eric at engestrom.ch>

> 
> 7c8ee3f0f "util: simplify string duplication logic"

"Fixes:" ?

> ---
>  tests/util/piglit-shader-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/util/piglit-shader-test.c
> b/tests/util/piglit-shader-test.c
> index 39df2948d..35ed3a81e 100644
> --- a/tests/util/piglit-shader-test.c
> +++ b/tests/util/piglit-shader-test.c
> @@ -140,7 +140,7 @@ piglit_load_source_from_shader_test(const char
> *filename,
>  		return false;
>  	}
>  
> -	text_size = line - first_line + 1;
> +	text_size = line - first_line;
>  
>  	if (output_source)
>  		*output_source = strndup(first_line, text_size);
> -- 
> 2.20.0


More information about the mesa-dev mailing list