mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
gcov: return failure if malloc fails
Don't assume that malloc always returns a non-null pointer. xmalloc is sometimes an alias for malloc due to this in libgcc/libgcov.h: /* work around the poisoned malloc/calloc in system.h. */ #ifndef xmalloc #define xmalloc malloc #endif libgcc/ChangeLog: * libgcov-driver-system.c (gcov_exit_open_gcda_file): Handle potential NULL value from malloc. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
This commit is contained in:
@@ -301,6 +301,11 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr,
|
||||
|
||||
size_t prefix_length = gf->prefix ? strlen (gf->prefix) : 0;
|
||||
gf->filename = (char *) xmalloc (prefix_length + strlen (fname) + 2);
|
||||
if (!gf->filename)
|
||||
{
|
||||
fprintf (stderr, "profiling:Failed to allocate memory for filename");
|
||||
return -1;
|
||||
}
|
||||
*gf->filename = '\0';
|
||||
if (prefix_length)
|
||||
strcat (gf->filename, gf->prefix);
|
||||
|
||||
Reference in New Issue
Block a user