cris: sprintf sanitizer null destination pointer

Message ID ZMuSxcYhotN4qQqx@squeak.grove.modra.org
State Accepted
Headers
Series cris: sprintf sanitizer null destination pointer |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Alan Modra Aug. 3, 2023, 11:43 a.m. UTC
  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.
  

Patch

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.  */