Re: [PATCH 3/5] Let phex and phex_nz handle sizeof_l==1

Simon Marchi via Gdb-patches
2022-03-01T14:30:27Z

On 2022-02-28 13:33, Tom Tromey via Gdb-patches wrote:
> Currently, neither phex nor phex_nz handle sizeof_l==1 -- they let
> this case fall through to the default case. However, a subsequent
> patch in this series needs this case to work correctly.
>
> I looked at all calls to these functions that pass a 1 for the
> sizeof_l parameter. The only such case seems to be correct with this
> change.
> ---
> gdbsupport/print-utils.cc | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/gdbsupport/print-utils.cc b/gdbsupport/print-utils.cc
> index 0ef8cb829a1..73ff1afda30 100644
> --- a/gdbsupport/print-utils.cc
> +++ b/gdbsupport/print-utils.cc
> @@ -168,6 +168,10 @@ phex (ULONGEST l, int sizeof_l)
> str = get_print_cell ();
> xsnprintf (str, PRINT_CELL_SIZE, "%04x", (unsigned short) (l & 0xffff));
> break;
> + case 1:
> + str = get_print_cell ();
> + xsnprintf (str, PRINT_CELL_SIZE, "%02x", (unsigned short) (l & 0xff));

I'm just wondering why you're casting to unsigned short specifically (and not
unsigned char). But in practice it works, the patch LGTM.

Simon