[Mesa-dev] [PATCH] util: fix off-by-one when loading source
Caio Marcelo de Oliveira Filho
caio.oliveira at intel.com
Sat Jan 19 23:50:04 UTC 2019
Sorry for the wrong list. Sent again to piglit at .
On Sat, Jan 19, 2019 at 03:40:01PM -0800, Caio Marcelo de Oliveira Filho 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).
>
> 7c8ee3f0f "util: simplify string duplication logic"
> ---
> 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
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Caio
More information about the mesa-dev
mailing list