Require 0x before hexadecimal family IDs Fixes #161
diff --git a/main.cpp b/main.cpp index 3c54640..9123281 100644 --- a/main.cpp +++ b/main.cpp
@@ -321,22 +321,26 @@ } else if (value == rp2350_riscv_family_name) { t = RP2350_RISCV_FAMILY_ID; } else { - if (value.find("0x") == 0) value = value.substr(2); - size_t pos = 0; - long lvalue = std::numeric_limits<long>::max(); - try { - lvalue = std::stoul(value, &pos, 16); - if (pos != value.length()) { - return "Garbage after hex value: " + value.substr(pos); + if (value.find("0x") == 0) { + value = value.substr(2); + size_t pos = 0; + long lvalue = std::numeric_limits<long>::max(); + try { + lvalue = std::stoul(value, &pos, 16); + if (pos != value.length()) { + return "Garbage after hex value: " + value.substr(pos); + } + } catch (std::invalid_argument &) { + return ovalue + " is not a valid hex value"; + } catch (std::out_of_range &) { } - } catch (std::invalid_argument &) { - return ovalue + " is not a valid hex value"; - } catch (std::out_of_range &) { + if (lvalue != (unsigned int) lvalue) { + return value + " is not a valid 32 bit value"; + } + t = (unsigned int) lvalue; + } else { + return value + " is not a valid family ID"; } - if (lvalue != (unsigned int) lvalue) { - return value + " is not a valid 32 bit value"; - } - t = (unsigned int) lvalue; } return string(""); });