[2/3] Do not call fputc from _bfd_doprnt

Message ID 20240130010540.1754740-3-tom@tromey.com
State Accepted
Headers
Series Fix some error-printing issues |

Checks

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

Commit Message

Tom Tromey Jan. 30, 2024, 1:03 a.m. UTC
  I noticed that _bfd_doprnt can unconditionally call fputc.  However,
when called from error_handler_sprintf, this will likely result in a
crash, as the stream argument does not actually point to a FILE.

bfd/ChangeLog
2024-01-29  Tom Tromey  <tom@tromey.com>

	* bfd.c (_bfd_doprnt): Do not call fputc.
---
 bfd/ChangeLog | 4 ++++
 bfd/bfd.c     | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
  

Comments

Nick Clifton Feb. 12, 2024, 3:04 p.m. UTC | #1
Hi Tom,

> I noticed that _bfd_doprnt can unconditionally call fputc.  However,
> when called from error_handler_sprintf, this will likely result in a
> crash, as the stream argument does not actually point to a FILE.
> 
> bfd/ChangeLog
> 2024-01-29  Tom Tromey  <tom@tromey.com>
> 
> 	* bfd.c (_bfd_doprnt): Do not call fputc.

Approved - please apply.

Cheers
   Nick
  

Patch

diff --git a/bfd/bfd.c b/bfd/bfd.c
index 5619799e403..0f1eaa1629f 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1027,7 +1027,7 @@  _bfd_doprnt (print_func print, void *stream, const char *format,
 	}
       else if (ptr[1] == '%')
 	{
-	  fputc ('%', stream);
+	  print (stream, "%%");
 	  result = 1;
 	  ptr += 2;
 	}