Re: [PATCH 03/13] opcodes/z80: remove use of sprintf
Jan Beulich <[email protected]>
| Newsgroups | gmane.comp.gdb.patches,gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <[email protected]> |
On 17.08.2026 17:16, Simon Marchi wrote:
> --- a/opcodes/z80-dis.c
> +++ b/opcodes/z80-dis.c
> @@ -768,11 +768,55 @@ pref_ind (struct buffer *buf, disassemble_info *info, const char *txt)
> static int
> print_insn_z80_buf (struct buffer *buf, disassemble_info *info);
>
> +struct sized_buf
> +{
> + char *buf;
> + size_t size;
> +};
> +
> +/* An fprintf_ftype implementation writing to STREAM, which must point to a
> + struct sized_buf. */
> +
> +static int ATTRIBUTE_PRINTF_2
> +sized_buf_printf (void *stream, const char *format, ...)
> +{
> + va_list ap;
> + int ret;
> + struct sized_buf *sbuf = (struct sized_buf *) stream;
We're in the (slow going) process of removing such unnecessary casts, in the
interest of getting the amount of casts down in general. Please drop this one
as well as ...
> + va_start (ap, format);
> + ret = vsnprintf (sbuf->buf, sbuf->size, format, ap);
> + va_end (ap);
> +
> + return ret;
> +}
> +
> +/* Same as sized_buf_printf, but as an fprintf_styled_ftype implementation.
> + The style is ignored for now. */
> +
> +static int ATTRIBUTE_PRINTF_3
> +sized_buf_styled_printf (void *stream,
> + enum disassembler_style style ATTRIBUTE_UNUSED,
> + const char *format, ...)
> +{
> + va_list ap;
> + int ret;
> + struct sized_buf *sbuf = (struct sized_buf *) stream;
... the one here.
> + va_start (ap, format);
> + ret = vsnprintf (sbuf->buf, sbuf->size, format, ap);
> + va_end (ap);
> +
> + return ret;
> +}
> +
> static int
> suffix (struct buffer *buf, disassemble_info *info, const char *txt)
> {
> char mybuf[TXTSIZ*4];
> + struct sized_buf sbuf = { mybuf, sizeof (mybuf) };
Please use ARRAY_SIZE() here. sizeof() happens to be correct for char[], but
wouldn't be correct for e.g. wchar_t[].
Okay with these adjustments.
Jan