This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
strings.c uninit warning
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 7 Mar 2013 00:12:56 +1030
- Subject: strings.c uninit warning
This came about as a result of looking into a complaint that a power7
-O3 build of binutils fails with "may be used uninitialized" warnings
about buf[0..3]. The warning here is a false positive, and whether
you see this or not depends on gcc version and target (degree of
inlining), and probably the phase of the moon.
Besides getting rid of the warnings, this removes a wrong check for
EOF which could trigger with "strings --encoding={B,L}.
Applied mainline.
* 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.
Index: binutils/strings.c
===================================================================
RCS file: /cvs/src/src/binutils/strings.c,v
retrieving revision 1.49
diff -u -p -r1.49 strings.c
--- binutils/strings.c 9 Feb 2012 04:51:44 -0000 1.49
+++ binutils/strings.c 6 Mar 2013 09:51:09 -0000
@@ -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 *addres
}
(*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;
}
--
Alan Modra
Australia Development Lab, IBM