public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] cris: 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=b077a53b2b8e4da725f1563e95b55650d61b47e7

commit b077a53b2b8e4da725f1563e95b55650d61b47e7
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Aug 3 07:59:47 2023 +0930

    cris: sprintf sanitizer null destination pointer
    
    Simplify the sprintf calls, and use sprintf return value.  Older code
    in binutils avoided using the sprintf return count of chars printed,
    because with some older C libraries it wasn't reliable.  Nowadays it
    should be OK to use (and we already use the return value elsewhere).
    sprintf can't return an error status of -1 here.
    
            * cris-dis.c (format_dec): Avoid sanitizer warning.  Use sprintf
            return value rather than calling strlen.

Diff:
---
 opcodes/cris-dis.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c
index b8eaa4b7942..681fccf0dca 100644
--- a/opcodes/cris-dis.c
+++ b/opcodes/cris-dis.c
@@ -580,12 +580,7 @@ static char *
 format_dec (long number, char *outbuffer, int signedp)
 {
   last_immediate = number;
-  if (signedp)
-    sprintf (outbuffer, "%ld", number);
-  else
-    sprintf (outbuffer, "%lu", (unsigned long) number);
-
-  return outbuffer + strlen (outbuffer);
+  return outbuffer + sprintf (outbuffer, signedp ? "%ld" : "%lu", number);
 }
 
 /* Format the name of the general register regno into outbuffer.  */

^ 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] cris: 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).