From ab53dad0ba791907fd23b8fd5a903b6c3d8d6294 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Wed, 1 Jul 2026 12:47:01 -0400 Subject: [PATCH] c++14 --- src/V3Control.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/V3Control.cpp b/src/V3Control.cpp index 7c076379d..71ea94585 100644 --- a/src/V3Control.cpp +++ b/src/V3Control.cpp @@ -21,7 +21,9 @@ #include "V3InstrCount.h" #include "V3String.h" -#include +#include +#include +#include #include #include #include @@ -1150,12 +1152,18 @@ void V3Control::applyVarAttr(const AstNodeModule* modulep, const AstNodeFTask* f // Parse one decimal array index from 'indexText' and append it to seg.m_indices. static bool parseIndexDigits(const std::string& indexText, V3ControlHierSegment& seg) { - int index = 0; - const char* const first = indexText.data(); - const char* const last = first + indexText.size(); - const auto [ptr, ec] = std::from_chars(first, last, index); - if (ec != std::errc{} || ptr != last) return false; - seg.m_indices.push_back(index); + const size_t firstDigit = (!indexText.empty() && indexText[0] == '-') ? 1 : 0; + if (indexText.size() <= firstDigit) return false; // Empty, or just "-" + for (size_t i = firstDigit; i < indexText.size(); ++i) { + if (indexText[i] < '0' || indexText[i] > '9') return false; + } + errno = 0; + char* endp = nullptr; + const long value = std::strtol(indexText.c_str(), &endp, 10); + if (errno != 0 || *endp != '\0') return false; // Overflow of long, or trailing junk + if (value < std::numeric_limits::min() || value > std::numeric_limits::max()) + return false; // Overflow of int + seg.m_indices.push_back(static_cast(value)); return true; }