From eb4e29810e854cebd56331b9481ef8cdd723e6ff Mon Sep 17 00:00:00 2001 From: Michael Baier Date: Thu, 9 Jul 2026 11:56:21 +0200 Subject: [PATCH] Fixed Overflow error in checking width --- frontends/rtlil/rtlil_frontend.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontends/rtlil/rtlil_frontend.cc b/frontends/rtlil/rtlil_frontend.cc index 5ddee9c31..4becf0ba0 100644 --- a/frontends/rtlil/rtlil_frontend.cc +++ b/frontends/rtlil/rtlil_frontend.cc @@ -529,9 +529,10 @@ struct RTLILFrontendWorker { break; } if (try_parse_keyword("width")){ - width = parse_integer(); - if (width >= RTLIL::WIDTH_LIMIT) - error("Wire width %lld out of range before `%s`.", width, error_token()); + long long width_val = parse_integer(); + if (width_val < 0 || width_val >= RTLIL::WIDTH_LIMIT) + error("Wire width %lld out of range before `%s`.", width_val, error_token()); + width = width_val; } else if (try_parse_keyword("upto")) upto = true; @@ -589,9 +590,10 @@ struct RTLILFrontendWorker { break; } if (try_parse_keyword("width")){ - width = parse_integer(); - if (width >= RTLIL::WIDTH_LIMIT) - error("Memory width %lld out of range before `%s`.", width, error_token()); + long long width_val = parse_integer(); + if (width_val < 0 || width_val >= RTLIL::WIDTH_LIMIT) + error("Memory width %lld out of range before `%s`.", width_val, error_token()); + width = width_val; } else if (try_parse_keyword("size")) size = parse_integer();