Fix possible nullreference in getImmediate
MODIFY
src/assembler/parserutilities.h
src/assembler/parserutilities.h
namespace Ripes {
namespace AssemblerTmp {
-inline int getImmediate(QString string, bool& canConvert) {
- string = string.toUpper();
+inline int getImmediate(const QString& string, bool& canConvert) {
+ QString upperString = string.toUpper();
canConvert = false;
- int immediate = string.toInt(&canConvert, 10);
+ int immediate = upperString.toInt(&canConvert, 10);
int sign = 1;
if (!canConvert) {
// Could not convert directly to integer - try hex or bin. Here, extra care is taken to account for a
// potential sign, and include this is the range validation
- if (string[0] == '-' || string[0] == '+') {
- sign = string[0] == '-' ? -1 : 1;
- string.remove(0, 1);
- }
- if (string.startsWith(QLatin1String("0X"))) {
- immediate = string.remove("0X").toUInt(&canConvert, 16);
- } else if (string.startsWith(QLatin1String("0B"))) {
- immediate = string.remove("0B").toUInt(&canConvert, 2);
+ if (upperString.size() > 0 && (upperString.at(0) == '-' || upperString.at(0) == '+')) {
+ sign = upperString.at(0) == '-' ? -1 : 1;
+ upperString.remove(0, 1);
+ }
+ if (upperString.startsWith(QLatin1String("0X"))) {
+ immediate = upperString.remove("0X").toUInt(&canConvert, 16);
+ } else if (upperString.startsWith(QLatin1String("0B"))) {
+ immediate = upperString.remove("0B").toUInt(&canConvert, 2);
} else {
canConvert = false;
}

Fix possible nullreference in getImmediate