Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Jan Beulich <jbeulich@suse.com>,
	Simon Marchi <simon.marchi@efficios.com>
Cc: gdb-patches@sourceware.org, binutils@sourceware.org
Subject: Re: [PATCH 03/13] opcodes/z80: remove use of sprintf
Date: Tue, 18 Aug 2026 12:48:14 -0400	[thread overview]
Message-ID: <686e0627-038b-46df-a0ff-6a0d65b2e5dd@simark.ca> (raw)
In-Reply-To: <94f0421e-2159-4483-b536-2473fa65ef4d@suse.com>

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

  reply	other threads:[~2026-08-18 16:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17 15:16 [PATCH 00/13] Fix various warnings when building on macOS Simon Marchi
2026-08-17 15:16 ` [PATCH 01/13] gdbsupport: remove uses of vsprintf Simon Marchi
2026-08-17 15:47   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 02/13] gdbsupport: remove uses of sprintf Simon Marchi
2026-08-17 15:49   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 03/13] opcodes/z80: remove use " Simon Marchi
2026-08-18  6:40   ` Jan Beulich
2026-08-18 16:48     ` Simon Marchi [this message]
2026-08-17 15:16 ` [PATCH 04/13] sim/ppc: make defines.h sed command portable Simon Marchi
2026-08-17 15:36   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 05/13] sim/m32r: fix unused variable warning on non-Linux hosts Simon Marchi
2026-08-17 15:36   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 06/13] sim/m32r: fix unused function warnings " Simon Marchi
2026-08-17 15:37   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 07/13] gdb/csky: remove uses of sprintf Simon Marchi
2026-08-17 16:26   ` Andrew Burgess
2026-08-17 17:03     ` Simon Marchi
2026-08-17 20:50     ` Tom Tromey
2026-08-18 18:26       ` Simon Marchi
2026-08-17 15:16 ` [PATCH 08/13] gdb/dwarf2: " Simon Marchi
2026-08-17 16:35   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 09/13] gdb/elfread: remove use " Simon Marchi
2026-08-17 16:38   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 10/13] gdbsupport: add xstrcpy Simon Marchi
2026-08-17 16:45   ` Andrew Burgess
2026-08-17 17:30     ` Simon Marchi
2026-08-17 15:16 ` [PATCH 11/13] gdb/remote-fileio: remove uses of sprintf Simon Marchi
2026-08-17 16:53   ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 12/13] gdb/remote: " Simon Marchi
2026-08-17 16:51   ` Andrew Burgess
2026-08-17 17:34     ` Simon Marchi
2026-08-17 15:16 ` [PATCH 13/13] gdb/tracepoint: " Simon Marchi
2026-08-17 16:51   ` Andrew Burgess
2026-08-17 20:52 ` [PATCH 00/13] Fix various warnings when building on macOS Tom Tromey
2026-08-18 18:10 ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=686e0627-038b-46df-a0ff-6a0d65b2e5dd@simark.ca \
    --to=simark@simark.ca \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox