From 688d771587af3f15c96d65e5c2cc8f82c8bfd0fc Mon Sep 17 00:00:00 2001 From: Stefan Wallentowitz Date: Tue, 31 Dec 2019 11:19:10 +0100 Subject: [PATCH] V3Number: Use stoi for conversion Convert using stoi and catch exceptions. This allows for large widths and avoids the issues with atoi. Fixes #2082 --- src/V3Number.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 0696b78be..23f0bd8f3 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -32,7 +32,6 @@ #include #define MAX_SPRINTF_DOUBLE_SIZE 100 // Maximum characters with a sprintf %e/%f/%g (probably < 30) -#define MAX_WIDTH 5*1024 // Maximum width before error // Number operations build output in-place so can't call e.g. foo.opX(foo) #define NUM_ASSERT_OP_ARGS1(arg1) \ @@ -124,14 +123,10 @@ void V3Number::V3NumberCreate(AstNode* nodep, const char* sourcep, FileLine* fl) if (*cp) { base=*cp; cp++; } value_startp = cp; - if (atoi(widthn.c_str())) { - if (atoi(widthn.c_str()) < 0 || atoi(widthn.c_str()) > MAX_WIDTH) { - // atoi might convert large number to negative, so can't tell which - v3error("Unsupported: Width of number exceeds implementation limit: "<