[PATCH] gdb/nat/linux-osdata.c: fix build on gcc-12 (string overfow)

Pedro Alves pedro@palves.net
Mon Nov 15 10:54:20 GMT 2021


On 2021-11-15 00:30, Simon Marchi via Binutils wrote:

> But actually, would you mind updating this code so that cores_str is an
> std::string and you just append to it?  That would get rid of the manual
> memory management.  I'm expecting that it could just look like this (but
> I haven't tested):
> 
> 	  std::string cores_str;
> 	  for (i = 0; i < num_cores && task_count > 0; ++i)
> 	    if (cores[i])
> 	      {
> 		cores_str += string_printf ("%d", i);

You can use string_appendf instead to save allocating/destroying a new string:

 		 string_printf (cores_str, "%d", i);

Pedro Alves

> 
> 		task_count -= cores[i];
> 		if (task_count > 0)
> 		  cores_str += ',';
> 	      }
> 
> Simon
> 



More information about the Binutils mailing list