[PATCH] BFD: Don't crash if the size of a reloc is 3.

Hans-Peter Nilsson hp@bitrange.com
Fri Jul 20 10:23:00 GMT 2018


On Wed, 18 Jul 2018, John Darrington wrote:
> --- a/bfd/libbfd.c
> +++ b/bfd/libbfd.c
> @@ -458,6 +458,29 @@ DESCRIPTION
>  .#define bfd_get_signed_16(abfd, ptr) \
>  .  BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
>  .
> +.#define bfd_put_24(abfd, val, ptr) \
> +.do \
> +.{ \
> +.if (bfd_big_endian (abfd)) \
> +.{ \
> +.  bfd_put_8 (abfd, val >> 0,  ptr + 2); \
> +.  bfd_put_8 (abfd, val >> 8,  ptr + 1); \
> +.  bfd_put_8 (abfd, val >> 16, ptr + 0); \
> +.} \
> +.else \
> +.{ \
> +.  bfd_put_8 (abfd, val >> 0,  ptr + 0); \
> +.  bfd_put_8 (abfd, val >> 8,  ptr + 1); \
> +.  bfd_put_8 (abfd, val >> 16, ptr + 2); \
> +.} \
> +.} \
> +.while (0)
> +.
> +.#define bfd_get_24(abfd, ptr) \
> +.  bfd_get_8 (abfd, ptr + 0) << (bfd_big_endian (abfd) ? 16 : 0) | \
> +.  bfd_get_8 (abfd, ptr + 1) << 8 | \
> +.  bfd_get_8 (abfd, ptr + 2) << (bfd_big_endian (abfd) ? 0 : 16) \
> +.

Much better, thanks, but please wrap that bfd_get_24 expression
in parentheses and also all macro parameter references.  I bit
cute on the bfd_get_24 stylistically (a personal remark) but
functionally mostly correct AFAICT.

Watch your ChangeLog and code formatting though, regarding
indentation as well as line breaks before operators; that's not
the style used here.  Lots of examples in nearby code.

(I'm not an approver, this was from a random spotting.)

brgds, H-P



More information about the Binutils mailing list