From: Sebastian Huber Date: Wed, 30 Mar 2022 19:49:51 +0000 (+0200) Subject: gcov: Use xstrdup() X-Git-Tag: basepoints/gcc-14~7193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9b59dd8e5586862cd3c2fa53901ee2e90226a3c;p=thirdparty%2Fgcc.git gcov: Use xstrdup() Move duplication of filename to caller and use xstrdup() instead of custom code. This helps to reuse read_gcda_file() for other purposes. libgcc/ * libgcov-util.c (read_gcda_file): Do not duplicate filename. (ftw_read_file): Duplicate filename for read_gcda_file(). --- diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index db157220c9d..ae5712c0138 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -296,16 +296,11 @@ read_gcda_file (const char *filename) sizeof (struct gcov_ctr_info) * GCOV_COUNTERS, 1); obj_info->version = version; + obj_info->filename = filename; obstack_init (&fn_info); num_fn_info = 0; curr_fn_info = 0; - { - size_t len = strlen (filename) + 1; - char *str_dup = (char*) xmalloc (len); - memcpy (str_dup, filename, len); - obj_info->filename = str_dup; - } /* Read stamp. */ obj_info->stamp = gcov_read_unsigned (); @@ -415,7 +410,7 @@ ftw_read_file (const char *filename, if (verbose) fnotice (stderr, "reading file: %s\n", filename); - obj_info = read_gcda_file (filename); + obj_info = read_gcda_file (xstrdup (filename)); if (!obj_info) return 0;