Re: [PATCH] s/sprint/xsnprintf/ in remote.c

Pedro Alves
2012-03-08T11:05:07Z

On 03/08/2012 05:47 AM, Yao Qi wrote:

> @@ -8002,7 +8009,7 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
> {
> CORE_ADDR addr;
> struct remote_state *rs;
> - char *p;
> + char *p, *endbuf;
>
> /* The length field should be set to the size of a breakpoint
> instruction, even though we aren't inserting one ourselves. */
> @@ -8015,6 +8022,7 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
>
> rs = get_remote_state ();
> p = rs->buf;
> + endbuf = rs->buf + get_remote_packet_size ();
>
> *(p++) = 'Z';
> *(p++) = '1';
> @@ -8022,10 +8030,11 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
>
> addr = remote_address_masked (bp_tgt->placed_address);
> p += hexnumstr (p, (ULONGEST) addr);
> - sprintf (p, ",%x", bp_tgt->placed_size);
> + xsnprintf (p, rs->buf + get_remote_packet_size () - p, ",%x",
> + bp_tgt->placed_size);

You seem to have endbuf handy, so `endbuf - p' would be better.

>
> if (remote_supports_cond_breakpoints ())
> - remote_add_target_side_condition (gdbarch, bp_tgt, p);
> + remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
>
> putpkt (rs->buf);
> getpkt (&rs->buf, &rs->buf_size, 0);
> @@ -8060,7 +8069,8 @@ remote_remove_hw_breakpoint (struct gdbarch *gdbarch,
>
> addr = remote_address_masked (bp_tgt->placed_address);
> p += hexnumstr (p, (ULONGEST) addr);
> - sprintf (p, ",%x", bp_tgt->placed_size);
> + xsnprintf (p, rs->buf + get_remote_packet_size () - p, ",%x",
> + bp_tgt->placed_size);

Would probably make sense for consistency with
remote_insert_hw_breakpoint to do `endbuf - p' here too.

Otherwise looks fine. Thanks for doing this.

--
Pedro Alves