質問

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. 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." Does its application here mean that the address of t will not change, or the value of t?

役に立ちましたか?

解決

In your example, _In_ means that

  • VS Code Analysis will validate that callers pass a non-null pointer to an initialized buffer.
  • VS Code Analysis will not validate that t is checked for null before dereferencing it in the function; t is assumed to be non-null in the function itself. By changing _In_ to _In_opt_, VS Code Analysis will validate that t is checked for null before dereferencing it.
  • 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.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top