Skip to content

Commit

Permalink
gcov: Use xstrdup()
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
sebhub committed Apr 28, 2022
1 parent e543d9d commit f9b59dd
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions libgcc/libgcov-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f9b59dd

Please sign in to comment.