* [PATCH] add casts to avoid arithmetic on void *
@ 2016-04-21 4:44 tbsaunde+binutils
2016-04-21 10:38 ` Nick Clifton
0 siblings, 1 reply; 2+ messages in thread
From: tbsaunde+binutils @ 2016-04-21 4:44 UTC (permalink / raw)
To: binutils; +Cc: Trevor Saunders
From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
Hi,
arithmetic on void * is undefined in ISO C, so we should avoid it. In GNU C
sizeof void * is defined as 1, and that is pretty clearly what this code wants,
so change it to do arithmetic on bfd_byte *. Unfortunately most of the
argument types come from virtual function interfaces so changing the
types to bfd_byte * isn't trivial though it might make the code clearer.
So for the moment its easiest to leave the variable types as void * and
cast before doing arithmetic.
built --enable-targets=all, ok?
Trev
bfd/ChangeLog:
2016-04-21 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
* elf32-rx.c (rx_set_section_contents): Avoid arithmetic on void *.
* mmo.c (mmo_get_section_contents): Likewise.
(mmo_set_section_contents): Likewise.
---
bfd/elf32-rx.c | 6 +++---
bfd/mmo.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index 754eae1..147a1a3 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -3548,7 +3548,7 @@ rx_set_section_contents (bfd * abfd,
if (! rv)
return rv;
- location ++;
+ location = (bfd_byte *) location + 1;
offset ++;
count --;
caddr ++;
@@ -3574,7 +3574,7 @@ rx_set_section_contents (bfd * abfd,
}
count -= scount;
- location += scount;
+ location = (bfd_byte *) location + scount;
offset += scount;
if (count > 0)
@@ -3593,7 +3593,7 @@ rx_set_section_contents (bfd * abfd,
if (! rv)
return rv;
- location ++;
+ location = (bfd_byte *) location + 1;
offset ++;
count --;
caddr ++;
diff --git a/bfd/mmo.c b/bfd/mmo.c
index d396fd7..ee22b03 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -2120,7 +2120,7 @@ mmo_get_section_contents (bfd *abfd ATTRIBUTE_UNUSED,
memcpy (location, loc, chunk_size);
- location += chunk_size;
+ location = (bfd_byte *) location + chunk_size;
bytes_to_do -= chunk_size;
offset += chunk_size;
}
@@ -2657,7 +2657,7 @@ mmo_set_section_contents (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr sec,
memcpy (loc, location, chunk_size);
- location += chunk_size;
+ location = (bfd_byte *) location + chunk_size;
bytes_to_do -= chunk_size;
offset += chunk_size;
}
--
2.1.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] add casts to avoid arithmetic on void *
2016-04-21 4:44 [PATCH] add casts to avoid arithmetic on void * tbsaunde+binutils
@ 2016-04-21 10:38 ` Nick Clifton
0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2016-04-21 10:38 UTC (permalink / raw)
To: tbsaunde+binutils, binutils
Hi Trev,
> Unfortunately most of the
> argument types come from virtual function interfaces so changing the
> types to bfd_byte * isn't trivial though it might make the code clearer.
This would certainly be worth looking into at a later date.
> 2016-04-21 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
>
> * elf32-rx.c (rx_set_section_contents): Avoid arithmetic on void *.
> * mmo.c (mmo_get_section_contents): Likewise.
> (mmo_set_section_contents): Likewise.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-04-21 10:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-21 4:44 [PATCH] add casts to avoid arithmetic on void * tbsaunde+binutils
2016-04-21 10:38 ` Nick Clifton
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).