This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
GOLD: RFA: Fixing a coverty error for aarch64.cc
- From: Nick Clifton <nickc at redhat dot com>
- To: iant at google dot com, ccoutant at gmail dot com, rearnsha at arm dot com, marcus dot shawcroft at arm dot com
- Cc: binutils at sourceware dot org
- Date: Wed, 18 Jan 2017 16:03:02 +0000
- Subject: GOLD: RFA: Fixing a coverty error for aarch64.cc
- Authentication-results: sourceware.org; auth=none
Hi Guys,
Running coverty on the GOLD sources has flagged a potential error in
the aarch64.cc source file:
binutils-2.27/gold/aarch64.cc:800: bad_sizeof: The expression
"sizeof (ST_E_835769_INSNS) / sizeof (ST_E_835769_INSNS[0])"
is suspicious. Note that "ST_E_835769_INSNS" is a pointer and
therefore the division will not return the number of array
elements which may have been the intent.
Given that the source code concerned looks like this:
----------------------------------------------------------------
const static Insntype ST_E_843419_INSNS[] =
{
0x00000000, /* Placeholder for erratum insn. */
0x14000000, /* b <label> */
};
// ST_E_835769 has the same stub template as ST_E_843419.
const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
#define install_insn_template(T) \
const static Stub_template<big_endian> template_##T = { \
T##_INSNS, sizeof(T##_INSNS) / sizeof(T##_INSNS[0]) }; \
this->stub_templates_[T] = &template_##T
install_insn_template(ST_NONE);
install_insn_template(ST_ADRP_BRANCH);
install_insn_template(ST_LONG_BRANCH_ABS);
install_insn_template(ST_LONG_BRANCH_PCREL);
install_insn_template(ST_E_843419);
install_insn_template(ST_E_835769);
----------------------------------------------------------------
The error looks quite reasonable to me.
So - any objections to the patch below ? It just changes
ST_E_835769_INSNS to be an array, like the other stubs. This may not
be the most efficient solution, but I think that it is the simplest.
Cheers
Nick
gold/ChangeLog
2017-01-18 Nick Clifton <nickc@redhat.com>
* aarch64.cc (Stub_template_repertoire): Change ST_E_835769_INSNS
from a pointer to an array.
diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index b207dcd..b282ccf 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -784,8 +784,14 @@ Stub_template_repertoire<big_endian>::Stub_template_repertoire()
0x14000000, /* b <label> */
};
- // ST_E_835769 has the same stub template as ST_E_843419.
- const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
+ // ST_E_835769 has the same stub template as ST_E_843419
+ // but we reproduce the array here so that the sizeof
+ // expressions in install_insn_template will work.
+ const static Insntype ST_E_835769_INSNS[] =
+ {
+ 0x00000000, /* Placeholder for erratum insn. */
+ 0x14000000, /* b <label> */
+ };
#define install_insn_template(T) \
const static Stub_template<big_endian> template_##T = { \