aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2013-03-06 13:40:51 +0000
committerAlan Modra <amodra@gmail.com>2013-03-06 13:40:51 +0000
commitc54e2ec1422ff0ea450229edea966ce994db408c (patch)
tree2f39c862ad361fe69a1eb9a19d01ad22ca7305a6
parent6c77229c00e6c7939fccda484093c35108ee9b21 (diff)
downloadgdb-c54e2ec1422ff0ea450229edea966ce994db408c.zip
gdb-c54e2ec1422ff0ea450229edea966ce994db408c.tar.gz
gdb-c54e2ec1422ff0ea450229edea966ce994db408c.tar.bz2
* strings.c (get_char): Dispense with buf[]. Instead shift
chars into big-endian value and byte-swap later if little-endian. Don't EOF check value read from object.
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/strings.c25
2 files changed, 12 insertions, 19 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 1278b1e..bc04889 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2013-03-07 Alan Modra <amodra@gmail.com>
+
+ * strings.c (get_char): Dispense with buf[]. Instead shift
+ chars into big-endian value and byte-swap later if
+ little-endian. Don't EOF check value read from object.
+
2013-03-05 Corinna Vinschen <vinschen@redhat.com>
* configure.in: Build DLL tools on x86_64-*-cygwin* as well.
diff --git a/binutils/strings.c b/binutils/strings.c
index 3eed63a..d591630 100644
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -455,8 +455,7 @@ static long
get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
{
int c, i;
- long r = EOF;
- unsigned char buf[4];
+ long r = 0;
for (i = 0; i < encoding_bytes; i++)
{
@@ -484,34 +483,22 @@ get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
}
(*address)++;
- buf[i] = c;
+ r = (r << 8) | (c & 0xff);
}
switch (encoding)
{
- case 'S':
- case 's':
- r = buf[0];
- break;
- case 'b':
- r = (buf[0] << 8) | buf[1];
+ default:
break;
case 'l':
- r = buf[0] | (buf[1] << 8);
- break;
- case 'B':
- r = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
- ((long) buf[2] << 8) | buf[3];
+ r = ((r & 0xff) << 8) | ((r & 0xff00) >> 8);
break;
case 'L':
- r = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |
- ((long) buf[3] << 24);
+ r = (((r & 0xff) << 24) | ((r & 0xff00) << 8)
+ | ((r & 0xff0000) >> 8) | ((r & 0xff000000) >> 24));
break;
}
- if (r == EOF)
- return 0;
-
return r;
}