这是代码分析中的错误吗?警告被_When_子句抑制 [英] Is this a bug in Code Analysis? Warning suppressed by _When_ clause
问题描述
我在这里问这个问题,因为Visual Studio代码分析和代码度量标准论坛似乎倾向于托管代码。
I am asking this here because the Visual Studio Code Analysis and Code Metrics forum seems to lean to managed code.
这是代码分析中的错误吗? 我希望在第三次foo2调用时发出Read Overrun警告,但_When_子句似乎影响了结果。 我在第三次foo1调用中得到警告......
Is this a bug in Code Analysis? I'd expect a Read Overrun warning on third foo2 call but the _When_ clause seems to have affected the results. I do get the warning in the third foo1 call...
void foo1(_In_ int buf_len,_In_reads_( buf_len)const char * symbol){}
void foo2(_In_ int buf_len,_When_( buf_len!= 0,_In_reads_(buf_len))_ When_(buf_len == 0,_Pre_null_)const char * symbol){}
//这保证了foo1的第二个参数在1和buf_len之间,这也保证了buf_len是> 0.
//同样保证,在foo2中,当buf_len为0且符号为非null时,该符号为空,并在buf_len>时初始化。 0。
char buffer [12] = {0};
foo1(sizeof buffer,buffer);
$
foo1(sizeof buffer-1,buffer);
foo1(sizeof buffer + 1,buffer); //收到警告C6385读取超限
foo2(sizeof缓冲区,缓冲区);
foo2(sizeof buffer-1,buffer);
foo2 (sizeof buffer + 1,buffer); //没有收到警告C6385读取超限!
$
foo2(0,nullptr);
$
foo2(0,缓冲区); //收到警告C6388无效参数值
foo2(sizeof buffer,nullptr); //收到警告C6387参数值无效
推荐答案
Woops!忘了提我正在使用VS2012 RC
Woops! forgot to mention I'm using VS2012 RC
这篇关于这是代码分析中的错误吗?警告被_When_子句抑制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!