From: Andreas Sandberg Date: Wed, 18 Sep 2013 15:08:35 +0000 (+0200) Subject: sim: Fix undefined behavior in the pseudo-inst interface X-Git-Tag: stable_2014_02_15~124 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4dbf25adc379d589c2aad9e62527d47a2ba62553;p=gem5.git sim: Fix undefined behavior in the pseudo-inst interface The order between updating and using arg_num in PseudoInst::pseudoInst() is currently undefined. This changeset explicitly updates arg_num after it has been used to extract an argument. --HG-- extra : rebase_source : 67c46dc3333d16ce56687ee8aea41ce6c6d133bb --- diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc index 0dcf5c32b..f4666a0cd 100644 --- a/src/sim/pseudo_inst.cc +++ b/src/sim/pseudo_inst.cc @@ -98,8 +98,10 @@ pseudoInst(ThreadContext *tc, uint8_t func, uint8_t subfunc) // used the Argument class, but due to the possible side effects // from getArgument, it'd most likely break. int arg_num(0); - for (int i = 0; i < sizeof(args) / sizeof(*args); ++i) - args[arg_num++] = getArgument(tc, arg_num, sizeof(uint64_t), false); + for (int i = 0; i < sizeof(args) / sizeof(*args); ++i) { + args[arg_num] = getArgument(tc, arg_num, sizeof(uint64_t), false); + ++arg_num; + } switch (func) { case 0x00: // arm_func