opcodes/z80: remove use of sprintf

When building on macOS, I get:

      CC       z80-dis.lo
    /Users/smarchi/src/binutils-gdb/opcodes/z80-dis.c:804:41: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
      804 |   info->fprintf_func = (fprintf_ftype) &sprintf;
          |                                         ^

Replace this use of sprintf with the safer snprintf.  Add a small
structure and wrappers around snprintf in order to glue everything
together.

When asked to review my patch, Claude Code mentioned that the existing
code had a latent bug: while info->fprintf_func and info->stream get set
temporarily, info->fprintf_styled_func doesn't.  If fprintf_styled_func
happened to be called, it would receive a `stream` it doesn't expect.
It's probably not a problem today, if the disassembler doesn't emit
styling, but it seems like a good moment to fix it.  Use
the disassemble_set_printf function to set both fprintf functions and
the stream argument at the same time.

Change-Id: I85dee82f3a0c53f38e52ca1158bc605854ab4896
1 file changed