[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:40:01 UTC 2019


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



More information about the mesa-dev mailing list