On 19/01/2019 23:49, 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;


The difference between strndup & snprintf is that the former one copies n characters plus an additional '\0' while the latter copies n characters including '\0'.


Reviewed-by: Lionel Landwerlin <lionel.g.landwer...@intel.com>


if (output_source)
                *output_source = strndup(first_line, text_size);


_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to