aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-06-26 16:46:49 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-06-26 16:46:49 +0200
commit33fe4041f8fb9ef05cf946dae87a71005e7c72f7 (patch)
tree6fe5e19e0e30359929947397a3fc431b70ec733a /qtmips_machine
parent473b28e10956e022b8c809a09283f3581af917a2 (diff)
downloadqtmips-33fe4041f8fb9ef05cf946dae87a71005e7c72f7.tar.gz
qtmips-33fe4041f8fb9ef05cf946dae87a71005e7c72f7.tar.bz2
qtmips-33fe4041f8fb9ef05cf946dae87a71005e7c72f7.zip
Convert QString to C string character by character, std::strtol{l} fails under some circumstances.
It seems that under Emscripten build and sometimes even under Windows build the conversion QString.toLatin1().data() does not guarantee well formed null terminated C string. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/instruction.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp
index 31c04a7..d210ad9 100644
--- a/qtmips_machine/instruction.cpp
+++ b/qtmips_machine/instruction.cpp
@@ -1018,10 +1018,15 @@ void instruction_from_string_build_base(const InstructionMap *im = nullptr,
static int parse_reg_from_string(QString str, uint *chars_taken = nullptr)
{
int res;
+ int i;
uint ctk;
if (str.count() < 2 || str.at(0) != '$')
return -1;
- const char *p = str.toLatin1().data() + 1;
+ char cstr[str.count() + 1];
+ for (i = 0; i < str.count(); i++)
+ cstr[i] = str.at(i).toLatin1();
+ cstr[i] = 0;
+ const char *p = cstr + 1;
char *r;
res = std::strtol(p, &r, 0);
ctk = r - p + 1;
@@ -1146,23 +1151,37 @@ Instruction Instruction::from_string(QString str, bool *pok, uint32_t inst_addr)
FALLTROUGH
case 'o':
case 'n':
- // Qt functions are limited, toLongLong would be usable
- // but does not return information how many characters
- // are processed. Used solution has horrible overhead
- // but is usable for now
- p = fl.toLatin1().data();
- if (adesc->min < 0)
- val += std::strtoll(p, &r, 0);
- else
- val += std::strtoull(p, &r, 0);
- chars_taken = r - p;
+ {
+ int i;
+ // Qt functions are limited, toLongLong would be usable
+ // but does not return information how many characters
+ // are processed. Used solution has horrible overhead
+ // but is usable for now
+ char cstr[fl.count() + 1];
+ for (i = 0; i < fl.count(); i++)
+ cstr[i] = fl.at(i).toLatin1();
+ cstr[i] = 0;
+ p = cstr;
+ if (adesc->min < 0)
+ val += std::strtoll(p, &r, 0);
+ else
+ val += std::strtoull(p, &r, 0);
+ chars_taken = r - p;
+ }
break;
case 'a':
- p = fl.toLatin1().data();
- val -= (inst_addr + 4) & 0xf0000000;
- val += std::strtoull(p, &r, 0);
- chars_taken = r - p;
- break;
+ {
+ int i;
+ char cstr[fl.count() + 1];
+ for (i = 0; i < fl.count(); i++)
+ cstr[i] = fl.at(i).toLatin1();
+ cstr[i] = 0;
+ p = cstr;
+ val -= (inst_addr + 4) & 0xf0000000;
+ val += std::strtoull(p, &r, 0);
+ chars_taken = r - p;
+ break;
+ }
}
if (chars_taken <= 0) {
field = -1;