[Mesa-dev] [PATCH shader-db] run: simplify filename handling
Eric Engestrom
eric.engestrom at intel.com
Fri Aug 10 12:21:31 UTC 2018
Compiler wasn't happy about strncpy() depending on the source's length and not
the target's, but this whole thing can be simplified by simply using asprintf()
(which is already used in this file, so no #include necessary).
run.c: In function ‘main._omp_fn.0’:
run.c:964:21: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
strncpy(out_filename, current_shader_name,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strlen(current_shader_name) + 1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
---
run.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/run.c b/run.c
index 200c0f4d6ffb1a2be467..43f1bf5bdd5f160e86fd 100644
--- a/run.c
+++ b/run.c
@@ -959,11 +959,8 @@ main(int argc, char **argv)
continue;
}
- char *out_filename = malloc(strlen(current_shader_name) + 5);
-
- strncpy(out_filename, current_shader_name,
- strlen(current_shader_name) + 1);
- out_filename = strcat(out_filename, ".bin");
+ char *out_filename;
+ asprintf(&out_filename, "%s.bin", current_shader_name);
fp = fopen(out_filename, "wb");
fprintf(stdout,
--
Cheers,
Eric
More information about the mesa-dev
mailing list