public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: libbfc.c: Use stdint types for unsigned char and unsigned long
Date: Wed, 3 May 2023 15:31:42 +0930	[thread overview]
Message-ID: <ZFH4xh+ePb7tKT7Q@squeak.grove.modra.org> (raw)

	* libbfd.c (bfd_put_8): Use bfd_byte rather than unsigned char.
	(bfd_get_8, bfd_get_signed_8): Likewise.
	(_bfd_read_unsigned_leb128, _bfd_safe_read_leb128): Likewise.
	(_bfd_read_signed_leb128): Likewise.
	(bfd_getb24, bfd_getl24): Replace unsigned long with uint32_t.
	(bfd_getb32, bfd_getl32): Likewise.
	(bfd_getb_signed_32, bfd_getl_signed_32): Likewise.

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index d695402b62f..c7bcd5f51fb 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -544,13 +544,13 @@ const char *bfd_set_filename (bfd *abfd, const char *filename);
 /* Byte swapping macros for user section data.  */
 
 #define bfd_put_8(abfd, val, ptr) \
-  ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
+  ((void) (*((bfd_byte *) (ptr)) = (val) & 0xff))
 #define bfd_put_signed_8 \
   bfd_put_8
 #define bfd_get_8(abfd, ptr) \
-  ((bfd_vma) *(const unsigned char *) (ptr) & 0xff)
+  ((bfd_vma) *(const bfd_byte *) (ptr) & 0xff)
 #define bfd_get_signed_8(abfd, ptr) \
-  ((((bfd_signed_vma) *(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
+  ((((bfd_signed_vma) *(const bfd_byte *) (ptr) & 0xff) ^ 0x80) - 0x80)
 
 #define bfd_put_16(abfd, val, ptr) \
   BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index d4f1478ec07..e21cd988208 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -477,13 +477,13 @@ DESCRIPTION
 .{* Byte swapping macros for user section data.  *}
 .
 .#define bfd_put_8(abfd, val, ptr) \
-.  ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
+.  ((void) (*((bfd_byte *) (ptr)) = (val) & 0xff))
 .#define bfd_put_signed_8 \
 .  bfd_put_8
 .#define bfd_get_8(abfd, ptr) \
-.  ((bfd_vma) *(const unsigned char *) (ptr) & 0xff)
+.  ((bfd_vma) *(const bfd_byte *) (ptr) & 0xff)
 .#define bfd_get_signed_8(abfd, ptr) \
-.  ((((bfd_signed_vma) *(const unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
+.  ((((bfd_signed_vma) *(const bfd_byte *) (ptr) & 0xff) ^ 0x80) - 0x80)
 .
 .#define bfd_put_16(abfd, val, ptr) \
 .  BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
@@ -685,11 +685,11 @@ bfd_vma
 bfd_getb24 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v =  (unsigned long) addr[0] << 16;
-  v |= (unsigned long) addr[1] << 8;
-  v |= (unsigned long) addr[2];
+  v =  (uint32_t) addr[0] << 16;
+  v |= (uint32_t) addr[1] << 8;
+  v |= (uint32_t) addr[2];
   return v;
 }
 
@@ -697,11 +697,11 @@ bfd_vma
 bfd_getl24 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v = (unsigned long) addr[0];
-  v |= (unsigned long) addr[1] << 8;
-  v |= (unsigned long) addr[2] << 16;
+  v = (uint32_t) addr[0];
+  v |= (uint32_t) addr[1] << 8;
+  v |= (uint32_t) addr[2] << 16;
   return v;
 }
 
@@ -709,12 +709,12 @@ bfd_vma
 bfd_getb32 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v = (unsigned long) addr[0] << 24;
-  v |= (unsigned long) addr[1] << 16;
-  v |= (unsigned long) addr[2] << 8;
-  v |= (unsigned long) addr[3];
+  v = (uint32_t) addr[0] << 24;
+  v |= (uint32_t) addr[1] << 16;
+  v |= (uint32_t) addr[2] << 8;
+  v |= (uint32_t) addr[3];
   return v;
 }
 
@@ -722,12 +722,12 @@ bfd_vma
 bfd_getl32 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v = (unsigned long) addr[0];
-  v |= (unsigned long) addr[1] << 8;
-  v |= (unsigned long) addr[2] << 16;
-  v |= (unsigned long) addr[3] << 24;
+  v = (uint32_t) addr[0];
+  v |= (uint32_t) addr[1] << 8;
+  v |= (uint32_t) addr[2] << 16;
+  v |= (uint32_t) addr[3] << 24;
   return v;
 }
 
@@ -735,12 +735,12 @@ bfd_signed_vma
 bfd_getb_signed_32 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v = (unsigned long) addr[0] << 24;
-  v |= (unsigned long) addr[1] << 16;
-  v |= (unsigned long) addr[2] << 8;
-  v |= (unsigned long) addr[3];
+  v = (uint32_t) addr[0] << 24;
+  v |= (uint32_t) addr[1] << 16;
+  v |= (uint32_t) addr[2] << 8;
+  v |= (uint32_t) addr[3];
   return COERCE32 (v);
 }
 
@@ -748,12 +748,12 @@ bfd_signed_vma
 bfd_getl_signed_32 (const void *p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  unsigned long v;
+  uint32_t v;
 
-  v = (unsigned long) addr[0];
-  v |= (unsigned long) addr[1] << 8;
-  v |= (unsigned long) addr[2] << 16;
-  v |= (unsigned long) addr[3] << 24;
+  v = (uint32_t) addr[0];
+  v |= (uint32_t) addr[1] << 8;
+  v |= (uint32_t) addr[2] << 16;
+  v |= (uint32_t) addr[3] << 24;
   return COERCE32 (v);
 }
 
@@ -1084,7 +1084,7 @@ _bfd_read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
   bfd_vma result;
   unsigned int num_read;
   unsigned int shift;
-  unsigned char byte;
+  bfd_byte byte;
 
   result = 0;
   shift = 0;
@@ -1118,7 +1118,7 @@ _bfd_safe_read_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
 {
   bfd_vma result = 0;
   unsigned int shift = 0;
-  unsigned char byte = 0;
+  bfd_byte byte = 0;
   bfd_byte *data = *ptr;
 
   while (data < end)
@@ -1152,7 +1152,7 @@ _bfd_read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
   bfd_vma result;
   unsigned int shift;
   unsigned int num_read;
-  unsigned char byte;
+  bfd_byte byte;
 
   result = 0;
   shift = 0;

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-05-03  6:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ZFH4xh+ePb7tKT7Q@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).