Fix MSVC++ compiler error, bug927.

This commit is contained in:
Wilson Snyder 2015-06-04 19:37:03 -04:00
parent 4c29a13a6e
commit 491539ff32
5 changed files with 39 additions and 2 deletions

View File

@ -23,6 +23,8 @@ indicates the contributor was also the author of the fix; Thanks!
**** Fix width extension on mis-width ports, bug918. [Patrick Maupin] **** Fix width extension on mis-width ports, bug918. [Patrick Maupin]
**** Fix MSVC++ compiler error, bug927. [Hans Tichelaar]
* Verilator 3.872 2015-04-05 * Verilator 3.872 2015-04-05

View File

@ -421,7 +421,7 @@ public:
do { \ do { \
va_list args; \ va_list args; \
va_start(args, message); \ va_start(args, message); \
vsnprintf(m_buff, sizeof(m_buff), message.c_str(), args); \ VL_VSNPRINTF(m_buff, sizeof(m_buff), message.c_str(), args); \
va_end(args); \ va_end(args); \
} while (0) } while (0)

View File

@ -207,6 +207,22 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
# endif # endif
#endif #endif
#ifdef _WIN32
# define VL_VSNPRINTF vl_vsnprintf
inline int vl_vsnprintf(char* str, size_t size, const char* format, va_list ap) {
int count = -1;
if (size != 0) {
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
}
if (count == -1) {
count = _vscprintf(format, ap);
}
return count;
}
#else
# define VL_VSNPRINTF vsnprintf
#endif
//========================================================================= //=========================================================================
// File system functions // File system functions

View File

@ -117,7 +117,7 @@ void yyerrorf(const char* format, ...) {
va_list ap; va_list ap;
va_start(ap,format); va_start(ap,format);
vsnprintf(msg,maxlen,format,ap); VL_VSNPRINTF(msg,maxlen,format,ap);
msg[maxlen-1] = '\0'; msg[maxlen-1] = '\0';
va_end(ap); va_end(ap);

View File

@ -18,6 +18,7 @@ if (!-r "$root/.git") {
uint(); uint();
printfll(); printfll();
cstr(); cstr();
vsnprintf();
} }
ok(1); ok(1);
@ -86,4 +87,22 @@ sub cstr {
} }
} }
sub vsnprintf {
my $files = "src/*.c* src/*.h include/*.c* include/*.h test_c/*.c* test_regress/t/*.c* test_regress/t/*.h";
my $cmd = "cd $root && grep -n -P 'vsnprintf' $files | sort";
print "C $cmd\n";
my $grep = `$cmd`;
my %names;
foreach my $line (split /\n/, $grep) {
if ($line =~ /\b(vsnprintf)\b/) {
next if $line =~ /# *define\s*VL_VSNPRINTF/;
print "$line\n";
$names{$1} = 1;
}
}
if (keys %names) {
$Self->error("Files with vsnprintf, use VL_VSNPRINTF: ",join(' ',sort keys %names));
}
}
1; 1;