简体   繁体   English

SAL注释和指针参数

[英]SAL annotations and pointer parameters

I have been reading about SAL and I'm not clear on if annotations on pointer types apply to the reference or the value it points to. 我一直在阅读SAL ,我不清楚指针类型的注释是否适用于引用或它指向的值。 For example, if I have: 例如,如果我有:

void f(_In_ type* t);

_In_ means "The parameter must be valid in pre-state and will not be modified." _In_表示“参数必须在预先状态下有效且不会被修改”。 Does its application here mean that the address of t will not change, or the value of t? 这里的应用是否意味着t的地址不会改变,或者t的值是多少?

In your example, _In_ means that 在您的示例中, _In_表示

  • VS Code Analysis will validate that callers pass a non-null pointer to an initialized buffer. VS Code Analysis将验证调用者是否将非空指针传递给初始化缓冲区。
  • VS Code Analysis will not validate that t is checked for null before dereferencing it in the function; VS代码分析不会在函数中解除引用之前验证是否检查了t ; t is assumed to be non-null in the function itself. 假设t在函数本身中是非空的。 By changing _In_ to _In_opt_ , VS Code Analysis will validate that t is checked for null before dereferencing it. 通过将_In_更改为_In_opt_ ,VS代码分析验证在解除引用之前检查t是否为null。
  • VS Code Analysis will validate that the function only reads "one element" of type from the memory pointed at by t , like assigning the value of the dereferenced pointer to a variable. VS Code Analysis将验证该函数仅从t指向的内存中读取type “一个元素”,例如将解除引用的指针的值赋给变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM