From f3a4752799edaf8d31bd1d587bb70a839dba8caa Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 5 Nov 2008 10:52:23 -0500 Subject: [PATCH] Fix MSVC compile error; bug42. --- Changes | 2 ++ include/verilated.cpp | 6 +++++- include/verilatedos.h | 4 ++-- src/V3EmitC.cpp | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 87fe2ceac..219c546a1 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix GCC 4.3 compile error; bug35. [Lane Brooks] +**** Fix MSVC compile error; bug42. [John Stroebel] + * Verilator 3.680 2008/10/08 ** Support negative bit indexes. [Stephane Laurent] diff --git a/include/verilated.cpp b/include/verilated.cpp index 0586ea0bb..56b1051af 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -539,7 +539,11 @@ IData VL_FGETS_IXQ(int obits, void* destp, QData fpq) { // any read data. This means we can't know in what location the first // character will finally live, so we need to copy. Yuk. IData bytes = VL_BYTES_I(obits); - char buffer[bytes]; + char buffer[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; + // V3Emit has static check that bytes < VL_TO_STRING_MAX_WORDS, but be safe + if (VL_UNLIKELY(bytes > VL_TO_STRING_MAX_WORDS*VL_WORDSIZE)) { + vl_fatal(__FILE__,__LINE__,"","Internal: fgets buffer overrun"); + } // We don't use fgets, as we must read \0s. IData got = 0; diff --git a/include/verilatedos.h b/include/verilatedos.h index 5037c0a4c..5234a3f34 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -86,10 +86,10 @@ typedef long vlsint32_t; ///< 32-bit signed type typedef unsigned long vluint32_t; ///< 32-bit unsigned type typedef long long vlsint64_t; ///< 64-bit signed type typedef unsigned long long vluint64_t; ///< 64-bit unsigned type -#elif defined(_WIN32) && !defined(__MINGW32__) +#elif defined(_WIN32) && defined(_MSC_VER) typedef unsigned char uint8_t; ///< 8-bit unsigned type (backward compatibility) typedef unsigned short int uint16_t; ///< 16-bit unsigned type (backward compatibility) -typedef unsigned long uint32_t; ///< 32-bit unsigned type (backward compatibility) +typedef unsigned int uint32_t; ///< 32-bit unsigned type (backward compatibility) typedef unsigned char vluint8_t; ///< 8-bit unsigned type typedef unsigned short int vluint16_t; ///< 16-bit unsigned type typedef int vlsint32_t; ///< 32-bit signed type diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index b1f7a2e55..b3fb40cbe 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -242,6 +242,10 @@ public: virtual void visit(AstSScanF* nodep, AstNUser*) { displayNode(nodep, nodep->text(), nodep->exprsp(), true); } + virtual void visit(AstFGetS* nodep, AstNUser*) { + checkMaxWords(nodep); + emitOpName(nodep, nodep->emitC(), nodep->lhsp(), nodep->rhsp(), NULL); + } void checkMaxWords(AstNode* nodep) { if (nodep->widthWords() > VL_TO_STRING_MAX_WORDS) {