diff options
-rw-r--r-- | subx/011run.cc | 15 | ||||
-rw-r--r-- | subx/030---operands.cc | 17 |
2 files changed, 31 insertions, 1 deletions
diff --git a/subx/011run.cc b/subx/011run.cc index b8ca52db..ca568a98 100644 --- a/subx/011run.cc +++ b/subx/011run.cc @@ -300,6 +300,10 @@ const segment* find(const program& p, const string& segment_name) { } uint8_t hex_byte(const string& s) { + if (std::any_of(s.begin(), s.end(), isupper)) { + raise << "uppercase hex not allowed: " << s << '\n' << end(); + return 0; + } istringstream in(s); int result = 0; in >> std::hex >> result; @@ -392,6 +396,17 @@ void test_error_on_missing_segment_header() { ); } +void test_error_on_uppercase_hex() { + Hide_errors = true; + parse_and_load( + "== code\n" + "01 Ab\n" + ); + CHECK_TRACE_CONTENTS( + "error: uppercase hex not allowed: Ab\n" + ); +} + //: helper for tests void parse_and_load(const string& text_bytes) { program p; diff --git a/subx/030---operands.cc b/subx/030---operands.cc index ec621017..8dc38542 100644 --- a/subx/030---operands.cc +++ b/subx/030---operands.cc @@ -411,6 +411,17 @@ void test_pack_flags_bad_hex() { ); } +void test_pack_flags_uppercase_hex() { + Hide_errors = true; + run( + "== code 0x1\n" + "b9 0xAb/imm32\n" + ); + CHECK_TRACE_CONTENTS( + "error: uppercase hex not allowed: 0xAb\n" + ); +} + //:: helpers bool all_hex_bytes(const line& inst) { @@ -425,7 +436,7 @@ bool is_hex_byte(const word& curr) { return false; if (SIZE(curr.data) != 2) return false; - if (curr.data.find_first_not_of("0123456789abcdefABCDEF") != string::npos) + if (curr.data.find_first_not_of("0123456789abcdef") != string::npos) return false; return true; } @@ -492,6 +503,10 @@ string to_string(const line& inst) { int32_t parse_int(const string& s) { if (s.empty()) return 0; + if (std::any_of(s.begin(), s.end(), isupper)) { + raise << "uppercase hex not allowed: " << s << '\n' << end(); + return 0; + } istringstream in(s); in >> std::hex; if (s.at(0) == '-') { |