public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] gprof: sprintf sanitizer null destination pointer
@ 2023-08-03 11:51 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-08-03 11:51 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=23f6f86ca03e87883150d21a6ac3c00590ea450a

commit 23f6f86ca03e87883150d21a6ac3c00590ea450a
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Aug 3 08:23:51 2023 +0930

    gprof: sprintf sanitizer null destination pointer
    
            * basic_blocks.c (annotate_with_count): Use output of sprintf
            rather than strlen.

Diff:
---
 gprof/basic_blocks.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/gprof/basic_blocks.c b/gprof/basic_blocks.c
index 6073f556f47..7fbba8c03fa 100644
--- a/gprof/basic_blocks.c
+++ b/gprof/basic_blocks.c
@@ -360,8 +360,7 @@ annotate_with_count (char *buf, unsigned int width, int line_num, void *arg)
 	 execution count (if bb_annotate_all_lines is set).  */
       if (b->is_func)
 	{
-	  sprintf (p, "%lu", b->ncalls);
-	  p += strlen (p);
+	  p += sprintf (p, "%lu", b->ncalls);
 	  last_count = b->ncalls;
 	  last_print = last_count;
 	  ncalls = b->ncalls;
@@ -370,8 +369,7 @@ annotate_with_count (char *buf, unsigned int width, int line_num, void *arg)
       else if (bb_annotate_all_lines
 	       && b->bb_addr[0] && b->bb_addr[0] > b->addr)
 	{
-	  sprintf (p, "%lu", last_count);
-	  p += strlen (p);
+	  p += sprintf (p, "%lu", last_count);
 	  last_print = last_count;
 	  ncalls = last_count;
 	  ncalls_set = 1;
@@ -396,8 +394,7 @@ annotate_with_count (char *buf, unsigned int width, int line_num, void *arg)
 
 	  if (p > tmpbuf)
 	    *p++ = ',';
-	  sprintf (p, "%lu", last_count);
-	  p += strlen (p);
+	  p += sprintf (p, "%lu", last_count);
 
 	  last_print = last_count;
 	}
@@ -410,8 +407,7 @@ annotate_with_count (char *buf, unsigned int width, int line_num, void *arg)
 
       if (bb_annotate_all_lines && p == tmpbuf)
 	{
-	  sprintf (p, "%lu", last_count);
-	  p += strlen (p);
+	  p += sprintf (p, "%lu", last_count);
 	  ncalls = last_count;
 	  ncalls_set = 1;
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-03 11:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 11:51 [binutils-gdb] gprof: sprintf sanitizer null destination pointer Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).