[PATCH 03/13] opcodes/z80: remove use of sprintf

Simon Marchi simark@simark.ca
Tue Aug 18 16:48:14 GMT 2026


On 8/18/26 2:40 AM, Jan Beulich wrote:
> 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 ...

Ah sorry, C++ habit.

> 
>> +  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.

Fixed.

>> +  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[].

Fixed.

> Okay with these adjustments.

Thanks, pushed with those changes.

Simon


More information about the Binutils mailing list