From a01e2c9068896ce7ed83449bed30b2da8ea1cbef Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 23 Aug 2023 10:46:46 +0200 Subject: [PATCH] nexus: Be robust to parameters shorter than expected Signed-off-by: gatecat --- nexus/pack.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nexus/pack.cc b/nexus/pack.cc index 4ebe68d1..d41766dc 100644 --- a/nexus/pack.cc +++ b/nexus/pack.cc @@ -82,19 +82,22 @@ Property Arch::parse_lattice_param(const Property &val, IdString prop, int width } temp = Property(ival); } - - for (auto b : temp.str.substr(width)) { - if (b == Property::S1) - log_error("Found value for property %s.%s with width greater than %d\n", ci, nameOf(prop), width); + if (int(temp.size()) > width) { + for (auto b : temp.str.substr(width)) { + if (b == Property::S1) + log_error("Found value for property %s.%s with width greater than %d\n", ci, nameOf(prop), width); + } } temp.update_intval(); return temp.extract(0, width); } else { - for (auto b : val.str.substr(width)) { - if (b == Property::S1) - log_error("Found bitvector value for property %s.%s with width greater than %d - perhaps a string was " - "converted to bits?\n", - ci, nameOf(prop), width); + if (int(val.str.size()) > width) { + for (auto b : val.str.substr(width)) { + if (b == Property::S1) + log_error("Found bitvector value for property %s.%s with width greater than %d - perhaps a string was " + "converted to bits?\n", + ci, nameOf(prop), width); + } } return val.extract(0, width); }