Avoid out of scope access in hsa-dump.c

Message ID AM5PR0701MB26578FD125D5C3299AD9B318E4570@AM5PR0701MB2657.eurprd07.prod.outlook.com
State New
Headers show
Series
  • Avoid out of scope access in hsa-dump.c
Related show

Commit Message

Bernd Edlinger July 22, 2018, 7:09 p.m.
Hi,

this fixes an use of a buffer after the block scope
in hsa-dump.c: "buf" is assigned to "name" and used after
the scope ends in a fprintf.

I have not done any real checks, except boot-strapping with
all languages.
Is it OK for trunk?


Thanks
Bernd.

Comments

Martin Jambor July 23, 2018, 11:32 a.m. | #1
Hi,

On Sun, Jul 22 2018, Bernd Edlinger wrote:
> Hi,

>

> this fixes an use of a buffer after the block scope

> in hsa-dump.c: "buf" is assigned to "name" and used after

> the scope ends in a fprintf.

>

> I have not done any real checks, except boot-strapping with

> all languages.

> Is it OK for trunk?


I'd even say it's obvious.  So yes, and thanks for spotting it!

Martin

>

>

> Thanks

> Bernd.

> 2018-07-22  Bernd Edlinger  <bernd.edlinger@hotmail.de>

>

> 	hsa-dump.c (dump_hsa_symbol): Avoid out of scope access to buf.

>

> Index: gcc/hsa-dump.c

> ===================================================================

> --- gcc/hsa-dump.c	(revision 262904)

> +++ gcc/hsa-dump.c	(working copy)

> @@ -776,11 +776,11 @@ static void

>  dump_hsa_symbol (FILE *f, hsa_symbol *symbol)

>  {

>    const char *name;

> +  char buf[64];

>    if (symbol->m_name)

>      name = symbol->m_name;

>    else

>      {

> -      char buf[64];

>        sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment),

>  	       symbol->m_name_number);

>

Patch

2018-07-22  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	hsa-dump.c (dump_hsa_symbol): Avoid out of scope access to buf.

Index: gcc/hsa-dump.c
===================================================================
--- gcc/hsa-dump.c	(revision 262904)
+++ gcc/hsa-dump.c	(working copy)
@@ -776,11 +776,11 @@  static void
 dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
 {
   const char *name;
+  char buf[64];
   if (symbol->m_name)
     name = symbol->m_name;
   else
     {
-      char buf[64];
       sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment),
 	       symbol->m_name_number);